仅供参考,我正在使用 Perl 和 Win32::OLE,但错误是 Word VBA 错误。
使用 Perl 的 Win32::OLE 模块,我试图在 Word 中创建一个表格并格式化它的某些元素。我创建了表格 (15 x 3) 并成功创建了一个范围对象,指向从 (2, 1) 到 (14, 3) 的单元格,即除了顶部和底部行之外的所有单元格。
然后我设置 OutsideLineStyle 和 InsideLineStyle 并启用边框,但生成的表格在表格内没有垂直边框。整个表格周围有边框,行之间有边框,但列之间没有边框。
我试图通过设置 wdBorderVertical 来纠正这个问题,但我收到“请求的集合成员不存在”的错误。我不确定为什么。
这是我的代码:
$cells = $document->Range( $table->Cell(2, 1)->Range->Start, $table->Cell(14, 3)->Range->End );
$cells->Borders->{OutsideLineStyle} = wdLineStyleSingle;
$cells->Borders->{OutsideLineWidth} = wdLineWidth150pt;
$cells->Borders->{InsideLineStyle} = wdLineStyleSingle;
$cells->Borders->{InsideLineWidth} = wdLineWidth150pt;
$cells->Borders->Item(wdBorderRight)->{LineStyle} = wdLineStyleSingle;
$cells->Borders->Item(wdBorderRight)->{LineWidth} = wdLineWidth150pt;
# The next two lines generate the error.
$cells->Borders->Item(wdBorderVertical)->{LineStyle} = wdLineStyleSingle;
$cells->Borders->Item(wdBorderVertical)->{LineWidth} = wdLineWidth150pt;
$cells->Borders->{Enable} = 1;
单元格范围不存在 wdBorderVertical 吗?我试图在不使用选择或循环的情况下执行此操作,因为似乎(也许我错了) Ranges 是专门使用的,因此您可以避免不必要的循环等,并且您可以使用多个 Ranges 而不是单个选择。