创建一个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自动恢复过程之后,文件很好。 Whan会引起这样的问题吗?
问题解决了!
每个表格单元格应该包含/ end与Paragraph
对象,因此解决方案是:
tc.Append(cellProp);
tc.Append(new Paragraph());
看起来我有像this question一样的问题,但没有错误。