OpenXML - 左表边框不工作?

问题描述 投票:0回答:1

以下是我使用 OpenXML (C#) 在 docx 中创建测试表的边框格式。

    //Create a TableProperties object and specify its border information.
    var borderType = BorderValues.Single;
    DocumentFormat.OpenXml.UInt32Value size = 5;
    TableProperties tblProp = new TableProperties(
        new TableJustification() { Val = TableRowAlignmentValues.Center },
        new TableBorders(
            new TopBorder(){ Val = new EnumValue<BorderValues>(borderType), Size = size },
            new BottomBorder(){ Val = new EnumValue<BorderValues>(borderType), Size = size },
            new LeftBorder(){ Val = new EnumValue<BorderValues>(borderType), Size = size },
            new RightBorder(){ Val = new EnumValue<BorderValues>(borderType), Size = size },
            new InsideHorizontalBorder(){ Val = new EnumValue<BorderValues>(borderType), Size = size },
            new InsideVerticalBorder(){ Val = new EnumValue<BorderValues>(borderType), Size = size }
        )
    );

    // Append the TableProperties object to the empty table.
    table.AppendChild<TableProperties>(tblProp);

上面的格式化产生了这样的结果(当在365word查看器中查看时)。enter image description here 问题是,为什么?

这里是生成的xml(从zip中提取)。enter image description here

EDIT: 它在word桌面程序中正确显示... 所以这似乎是一个#微软的错误。

c# openxml docx
1个回答
1
投票

不同的客户端往往对该规范的支持程度不同。我记得当我试图为Google docs制作内容时,我就在与此作斗争。

有一些事情你可以尝试。

首先,不要使用 LeftBorderRightBorder试试 StartBorderEndBorder. 这些对于支持RTL文化与LTR文化中的语义考虑很重要,因此可能会得到更好的支持。

其次,逆向工程对我来说几乎总是有效的。先在Word或其他工具中按照你想要的方式来设计文档的样式,然后提取并检查XML。

我想你会发现,Word定义了一种风格,它应用于表格,而不是试图在行内完成所有的工作--复制这种方法比较复杂,但往往能起到作用。

© www.soinside.com 2019 - 2024. All rights reserved.