Jump to content
sparrow925

Quick Add Borders to _Word_DocTableWrite

Recommended Posts

sparrow925

Hi all,

Very simple problem here -- I'd like to add borders to this table.

#include <Array.au3>
#include <Word.au3>


Local $oWord = _Word_Create()
Local $oDoc = _Word_DocAdd($oWord, $WdNewBlankDocument)
Local $oRange = _Word_DocRangeSet ($oDoc, -1)
Local $aTable = ["", "a, b, c", "d, e, f", "h, i, j"]

_Word_DocTableWrite ($oRange, $aTable, Default, "," )

 

I found a thread by @water from a few years back saying that there might be a UDF for Word table customization in the works. (I've since lost the link to the thread, whoops) I didn't see a follow-up. Did anything to this purpose get published? 

There is also this thread on UDFs, but I had limited success adapting the resources within, and seem to lack the required expertise to parse the code that the author put together. 

 

 

I've been looking for this for days, and I'm beginning to realize I must be missing something obvious. Could a kind soul nudge me in the right direction?

Share this post


Link to post
Share on other sites
water

Start the macro recorder in Word, format the table to your liking, stop the macro recorder and translate the VBA code to AutoIt.

Can't test at the moment but it should be something like this:

#include <Array.au3>
#include <Word.au3>


Local $oWord = _Word_Create()
Local $oDoc = _Word_DocAdd($oWord, $WdNewBlankDocument)
Local $oRange = _Word_DocRangeSet ($oDoc, -1)
Local $aTable = ["", "a, b, c", "d, e, f", "h, i, j"]

Local $oTable = _Word_DocTableWrite ($oRange, $aTable, Default, "," )
$oTable.InsideLineStyle = $wdLineStyleSingle 
$oTable.OutsideLineStyle = $wdLineStyleDouble

The Borders collection can be found here: https://msdn.microsoft.com/en-us/library/ff821528(v=office.14).aspx
The needed constants can be found here: https://msdn.microsoft.com/en-us/library/ff836368(v=office.14).aspx


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
sparrow925
#include <Array.au3>
#include <Word.au3>


Local $oWord = _Word_Create()
Local $oDoc = _Word_DocAdd($oWord, $WdNewBlankDocument)
Local $oRange = _Word_DocRangeSet ($oDoc, -1)
Local $aTable = ["", "a, b, c", "d, e, f", "h, i, j"]

Local $oTable = _Word_DocTableWrite ($oRange, $aTable, Default, "," )
$oTable.Borders.InsideLineStyle = True
$oTable.Borders.OutsideLineStyle = True

 

Thank you very much @water!

Share this post


Link to post
Share on other sites
water

Setting the Inside/Outside line style to True isn't 100% correct.
True evaluates to 1 and gives a "A single solid line.". This is what we call a "magic number". I suggest to use constants so you still know what your script does when you have to modify it in a few months ;)

#include <Word.au3>

; WdLineStyle Enumeration - https://msdn.microsoft.com/en-us/library/ff836368(v=office.14).aspx
Local $wdLineStyleSingle = 1 ; A single solid line

Local $oWord = _Word_Create()
Local $oDoc = _Word_DocAdd($oWord, $WdNewBlankDocument)
Local $oRange = _Word_DocRangeSet ($oDoc, -1)
Local $aTable = ["", "a, b, c", "d, e, f", "h, i, j"]

Local $oTable = _Word_DocTableWrite ($oRange, $aTable, Default, "," )
$oTable.Borders.InsideLineStyle = $wdLineStyleSingle
$oTable.Borders.OutsideLineStyle = $wdLineStyleSingle

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
sparrow925

Classy! Will do!

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

×