简体   繁体   English

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

[英]C# OpenXML - Table Properties - Set Indent from Left

I have a word document with a table on the first page. 我在第一页上有一个带有表格的Word文档。 It is the first table on the document and only one of the first page. 它是文档中的第一张表,也是第一页中的一个。 I need to set the "Indent from left" to 0" on this table. I'm already appending some text to the document: 我需要在此表上将“从左缩进”设置为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();
}

I've read a bit about the TableIndentation class, but haven't found any examples of it being used. 我已经阅读了一些有关TableIndentation类的信息,但是还没有找到任何正在使用的示例。 Does anybody have experience with this? 有人对此有经验吗?

Thanks 谢谢

Have you tried using the Open XML SDK Productivity Tool (note that there are multiple downloads on this page) to inspect a document that has what you need? 您是否尝试过使用Open XML SDK生产率工具 (请注意此页面上有多次下载)来检查具有所需内容的文档? If not, do so. 如果没有,请这样做。 It will answer your question. 它将回答您的问题。

You can specify the table indentation in the table properties class like this. 您可以像这样在表属性类中指定表缩进。

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

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

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