1

仅供参考,我正在使用 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 而不是单个选择。

4

2 回答 2

1

对于单元格范围,确实可能wdBorderVertical不存在这种情况。我发现的代码搜索结果都没有wdBorderVertical应用于单元格范围,通常只应用于单元格或表格。您可能必须使用循环来按照您希望的方式完成此操作。

于 2009-09-30T19:46:14.853 回答
0

我不知道 perl,但我认为您需要 的Cells成员Range,例如,对于您的第 1 行是这样的:

$cells = $document->Range( $table->Cell(2, 1)->Range->Start, $table->Cell(14, 3)->Range->End )->Cells;
于 2012-04-07T09:35:22.263 回答