通过openxml将表格插入word以及如何设置适合word的宽度

use*_*362 1 openxml

我想通过openxml创建一个word文件并在其中插入一个表格。现在我不知道如何设置网格的宽度以适应 word 文件。请帮我。谢谢

Jpa*_*ons 6

表格宽度可以通过第二行代码设置。

其余的只是为了展示如何将属性附加到表中

TableProperties tblProps = new TableProperties();

tableWidth = new TableWidth() { Width = "5000", Type =TableWidthUnitValues.Pct };

TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };
tblProps.Append(tableStyle, tableWidth);

table.Append(tblProps);
Run Code Online (Sandbox Code Playgroud)

  • 根据网站指南(查看帮助中心),仅包含代码或链接的答案是“低质量”的,可能会被删除。如果您包含一些有关如何解决问题中所述问题的解释,您的答案可以成为网站上的宝贵资源。另外,您需要小心:提出问题的人没有指定正在使用 Open XML SDK,因此您所做的假设可能会使您的答案无效:-) (2认同)