RRR*_*RRR 5 c# ms-word openxml word-2010
我正在尝试创建一个带有标题的表.我想要为表所采用的每个新页面重复此标题.如何在C#和OpenXml Wordprocessing中执行此操作?
DocumentFormat.OpenXml.Packaging.WordprocessingDocument internalDoc =
DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(stream, true);
var tables = wordDoc.MainDocumentPart.Document.Descendants<SdtBlock>().Where
( r => r.SdtProperties.GetFirstChild<Tag>().Val.Value.StartsWith(DATA_TABLE_TAG));
Table table = tables.Descendants<Table>().Single();
//Here can I set some property to repeat the header of the table?
Run Code Online (Sandbox Code Playgroud)
正如Chris所说,TableHeader类的一个实例就是你所需要的.它需要附加到标题行的TableRowProperties:
var row = table.GetFirstChild<TableRow>();
if (row.TableRowProperties == null)
row.TableRowProperties = new TableRowProperties();
row.TableRowProperties.AppendChild(new TableHeader());
Run Code Online (Sandbox Code Playgroud)
小智 6
对于正在寻找相同问题的任何人:
下面的代码必须应用于标题行,如 TablePropertiesRow
TableRowProperties tblHeaderRowProps = new TableRowProperties(
new CantSplit() { Val = OnOffOnlyValues.On },
new TableHeader() { Val = OnOffOnlyValues.On }
);
tblHeaderRow.AppendChild<TableRowProperties>(tblHeaderRowProps);
Run Code Online (Sandbox Code Playgroud)
露水!!
| 归档时间: |
|
| 查看次数: |
5942 次 |
| 最近记录: |