Jump to content

Formatting Word Document


Recommended Posts

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...