VishVin

Formatting Word Document

6 posts in this topic

Hello,

I am looking for a way to create a Word document which is formatted from the data I have in a spread sheet. For example, data which is in column 1 should be of the style _Heading 1 with Bold , Column 2 data from the spread sheet should show up as Heading 2 but in italics. I am able to extract data from spreadsheet  and write to a word document however I am unable to manage different styles for each paragraph.

Any kind of help /advice is appreciated.
 

-VishVin

Share this post


Link to post
Share on other sites



Create a template document with all the formatting and then call _Word_DocAdd to create a new document from this template.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hello Water,

Thanks for the quick response. However I am trying to create a template through a script. To illustrate better, I have attached the spreadsheet, which basically in my input and covert it to a doc format. The attached word document is a what I want my script to create. I have close to 1000 rows in spreadsheet.

Thanks,

VV

 

Example.xlsx

Example.docx

Share this post


Link to post
Share on other sites

The Word UDF only provides basic stuff. So there is no formatting function available.
You could activate the macro recorder in Word and format the 3 levels of entries.
Grab the macro and translate it to AutoIt. Unfortunately the recorded macro works with Selections and not with Ranges. But this should be easy too.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You could end with something like this:

#include <Word.au3>

Global Const $wdStyleHeading1 = -2
Global Const $wdStyleHeading2 = -3
Global Const $wdStyleHeading3 = -4

$oWord = _Word_Create()
$oDoc = _Word_DocAdd($oWord)
$oRange = _Word_DocRangeSet($oDoc, -1) ; Set the Range start/end to the start of the document
; Heading 1
$oRange.InsertBefore("Department 1")
$oRange.Style = $wdStyleHeading1
$oRange.InsertParagraphAfter()
$oRange = _Word_DocRangeSet($oDoc, -2) ; Set the Range to the end of the document
; Heading 2
$oRange.InsertAfter("Sub-Department 1.1")
$oRange.Style = $wdStyleHeading2
$oRange.InsertParagraphAfter()
$oRange = _Word_DocRangeSet($oDoc, -2)
; Heading 3 - Line 1
$oRange.InsertAfter("Boss")
$oRange.Style = $wdStyleHeading3
$oRange.InsertParagraphAfter()
$oRange = _Word_DocRangeSet($oDoc, -2)
; Heading 3 - Line 2
$oRange.InsertAfter("POC")
$oRange.Style = $wdStyleHeading3
$oRange.InsertParagraphAfter()
$oRange = _Word_DocRangeSet($oDoc, -2)

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water,

Appreciate your help on this. I was able to get all the formatting necessary.

Thanks,

Vinyas

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now