Powershell Word表边框

时间:2018-07-23 21:31:44

标签: powershell ms-word

我正在寻找有关如何在Word文档中设置表格边框属性的帮助。

我有一个预先格式化的Word文档,我正在从Windows窗体中插入信息。

到目前为止,我在这里找到了与此相关的帖子,下面一行在每个单元格周围插入边框:

$Table.cell($x,1).range.Borders.OutsideLineStyle = 1

我要达到的目的是,说我要插入4位信息,我希望在整个4个单元格周围加一个边框以使其成为一个块(如果这样)

我发现了一个使用borders对象的c#示例,但是我不知道如何在powershell中使用它:

$table.cell($x,1).Range.Borders[WdBorderType.wdBorderLeft].LineStyle   = WdLineStyle.wdLineStyleSingle
$table.cell($x,1).Range.Borders[WdBorderType.wdBorderRight].LineStyle  = WdLineStyle.wdLineStyleSingle

我认为我需要使用以下内容

"[Microsoft.Office.Interop.Word.WdParagraphAlignment]::wdAlignParagraphCenter"

有人可以给我一些指导吗?

非常感谢

2 个答案:

答案 0 :(得分:0)

您必须首先将Word程序集加载到内存中。然后使用它:

Add-Type -AssemblyName "Microsoft.Office.Interop.Word"
$pCenter = [Microsoft.Office.Interop.Word.WdParagraphAlignment]::wdAlignParagraphCenter

答案 1 :(得分:0)

通过使用以下方式解决:

$wdBorderBottom = "-3"
$wdBorderLeft = "-2"
$wdBorderRight = "-4"
$Table.cell($x,4).range.Borders.item($wdBorderRight).LineStyle = 1
$Table.cell($x,4).range.Borders.item($wdBorderLeft).LineStyle = 1
$Table.cell($x,4).range.Borders.item($wdBorderBottom).LineStyle = 0

谢谢

相关问题