Jump to content

Quick Add Borders to _Word_DocTableWrite


Recommended Posts

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?

Link to comment
Share on other sites

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 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

#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!

Link to comment
Share on other sites

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 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...