C# OpenXML - 表属性 - 设置从左开始的缩进



我有一个word文档,第一页上有一个表格。 它是文档上的第一个表,也是第一页中的一个。 我需要在此表上将"从左缩进"设置为 0"。 我已经在文档中附加了一些文本:

using (WordprocessingDocument oDocument = WordprocessingDocument.Open(_ms, true))
{
    //Set paragraph, run, and runproperties objects. 
    Paragraph para = oDocument.MainDocumentPart.Document.Descendants<Paragraph>().First();
    Run run = para.AppendChild(new Run());
    RunProperties runPro = new RunProperties();
    Run lineBreak = new Run(new Break());
    //Set the text color and text value
    Color color = new Color() { Val = "FFFFFF" };
    Text text1 = new Text();
    text1.Text = "text";
    //Add the text to the body
    runPro.Append(color);
    run.Append(runPro);
    run.Append(text1, lineBreak);
    //Close the handle
    oDocument.Close();
}

我已经阅读了一些关于 TableIndentation 类的信息,但没有找到任何使用它的示例。 有人有这方面的经验吗?

谢谢

您是否尝试过使用 Open XML SDK 生产力工具(请注意,此页面上有多个下载)来检查包含所需内容的文档?如果没有,请这样做。它将回答您的问题。

可以像这样在表属性类中指定表缩进。

TableProperties tPr = new TableProperties();
tPr.TableIndentation = new TableIndentation() { Type = indentationType, Width = indentationWidth };

使用它并提供宽度DXA(1"=1440 something)

props.TableIndentation = new TableIndentation() { Type = TableWidthUnitValues.Dxa, Width=-997 };

最新更新