简体   繁体   中英

Using PowerShell to modify MS Word cell borders

I routinely create reports using MS Word. Part of this report contains a table, which I have been copying manually from Excel into the word document. I am trying to use PowerShell in order to do this automatically, but I am having trouble finding the correct formatting commands. Specifically, I am currently trying to format the table so that every border between rows is dotted instead of solid, but the borders between columns are invisible. So something like this:

Heading1 Heading2 Heading3
.................................................
H1Item1 H2Item1 H3Item1
.................................................
H1Item2 H2Item2 H3Item2
.................................................

I did find that this gets me going in the right direction, but doesn't quite provide the granularity of border control that I'm looking for:

$Table.Range.Style = "Table Grid"
$Table.Borders.InsideLineStyle = 2
$Table.Borders.OutsideLineStyle = 0

If there is any good documentation on formatting Word paramters through PowerShell, I would really appreciate the pointer. I've managed to find articles relating to how to do specific things, but no good documentation.

Aha! I found it. I was trying for a way to do it in one line, but I found that if I just edit each row as I'm adding the data to it, then I can get the whole table that way. This is the line I added to my Foreach loop:

$Table.Rows($x).Borders.InsideLineStyle = 0

I would still love a link to some good documentation if anyone knows of any!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM