![](/img/trans.png)
[英]C# OpenXml Excel Creation - can I set it to “Format as table”?
[英]C# OpenXML - Table Properties - Set Indent from Left
我在第一页上有一个带有表格的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 };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.