0

创建TableCellProperties并删除 后TableCellBorders,word 文档变得不可读,我得到:

Word 在 test.docx 中发现不可读的内容。是否要恢复此文档的内容?如果您信任此文档的来源,请单击是。

我使用的代码:

TableCellProperties cellProp = new TableCellProperties(
    new TableCellBorders(
        new TopBorder()
        {
            Val =
                new EnumValue<BorderValues>(BorderValues.Nil),
        },
        new BottomBorder()
        {
            Val =
                new EnumValue<BorderValues>(BorderValues.Nil),
        },
        new LeftBorder()
        {
            Val =
                new EnumValue<BorderValues>(BorderValues.Nil),

        },
        new RightBorder()
        {
            Val = new EnumValue<BorderValues>(BorderValues.Nil),
        }
    )
);
TableCell tc = new TableCell();


tc.Append(cellProp);

TableRow trTest = new TableRow();
trTest.Append(new TableCell(tc.OuterXml));
trTest.Append(new TableCell(new Paragraph(new Run(new Text("B")))));
trTest.Append(new TableCell(new Paragraph(new Run(new Text("C")))));
trTest.Append(new TableCell(new Paragraph(new Run(new Text("D")))));
trTest.Append(new TableCell(new Paragraph(new Run(new Text("E")))));
trTest.Append(new TableCell(new Paragraph(new Run(new Text("F")))));
t.Append(trTest);

BorderValue设置为,Nil因为None似乎没有删除边框。在 MS Word 自动恢复过程之后,文件很好。什么会导致这样的问题?

4

1 回答 1

0

问题解决了!

每个表格单元格应包含/以Paragraph对象结尾,因此解决方案是:

tc.Append(cellProp);
tc.Append(new Paragraph());

看起来我在这个问题中遇到了同样的问题,但没有错误。

于 2018-11-13T11:20:57.490 回答