简体   繁体   English

删除单元格边框后无法读取的Word文档(OpenXml.Wordprocessing)

[英]Unreadable Word document after removing cell borders (OpenXml.Wordprocessing)

After creating a TableCellProperties and removing the TableCellBorders , the word document becomes unreadable and I get: 创建TableCellProperties并删除TableCellBorders ,单词document变得不可读,我得到:

Word found unreadable content in test.docx. Word在test.docx中发现了不可读的内容。 Do you want to recover the contents of this document? 您要恢复本文档的内容吗? If you trust the source of this document, click Yes. 如果您信任此文档的来源,请单击“是”。

The code that I use: 我使用的代码:

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);

The BorderValue is set to Nil , since None does not seem to remove the borders. BorderValue设置为Nil ,因为None似乎没有删除边框。 After the MS Word auto recover procedure, the file is fine. MS Word自动恢复过程之后,该文件就可以了。 Whan can cause such an issue? 谁会引起这样的问题?

Problem solved! 问题解决了!

Each table cell should contain/end with Paragraph object, so the solution is: 每个表单元格应包含/以Paragraph对象结尾,因此解决方案是:

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

Looks like I have the same problem like in this question , but without the error. 看起来我有与此问题相同的问题,但没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM