删除单元格边框后无法读取的 Word 文档 (OpenXml.Wordprocessing)
Unreadable Word document after removing cell borders (OpenXml.Wordprocessing)
创建 TableCellProperties
并删除 TableCellBorders
后,word 文档变得不可读,我得到:
Word found unreadable content in test.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes.
我使用的代码:
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 自动恢复程序之后,该文件是好的。谁会导致这样的问题?
问题解决了!
每个 table 单元格应 contain/end 与 Paragraph
对象,所以解决方案是:
tc.Append(cellProp);
tc.Append(new Paragraph());
看起来我遇到了与 this question 相同的问题,但没有错误。
创建 TableCellProperties
并删除 TableCellBorders
后,word 文档变得不可读,我得到:
Word found unreadable content in test.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes.
我使用的代码:
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 自动恢复程序之后,该文件是好的。谁会导致这样的问题?
问题解决了!
每个 table 单元格应 contain/end 与 Paragraph
对象,所以解决方案是:
tc.Append(cellProp);
tc.Append(new Paragraph());
看起来我遇到了与 this question 相同的问题,但没有错误。