如何使用 OpenXml Wordprocessing 在表格中为每个新页面创建标题
我正在尝试创建一个带有标题的表格。我希望该表的每个新页面都重复此标题。如何在 C# 和 OpenXml 字处理中执行此操作?
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?
I am trying to create a table with a header. I want this header to be repeated for each new page that the table takes. How can I do this in C# and 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Chris 所说,您需要的是 TableHeader 类的实例。它需要附加到标题行的 TableRowProperties:
As Chris said, an instance of the TableHeader class is what you need. It needs to be appended to the header row's TableRowProperties:
对于任何正在寻找相同问题的人:
下面的代码必须应用于标题行,如 TablePropertiesRow
Deww!
For anyone who is looking for the same issue:
The code below must be applied to the header Row, as TablePropertiesRow
Deww!!
我认为这就是你正在寻找的为了。如果您将该元素应用于特定行,它将按照您所描述的方式运行。
I think this is what you're looking for. If you apply that element to a particular row, it will behave the way you're describing.
为页面中的每个表格创建标题。
您需要创建多个正文并附加到文档。
如果要为每个表格创建新标题,则需要将每个表格附加到新正文,然后应用分页符。
最后,将所有主体附加到文档中。
然后你终于在创建的文档中得到了你的结果。
如有疑问请回复我。
问候,
巴拉吉
To create header for every table in a page.
You need to create multiple body's and append to document.
If you want to create new header to every table, you need to append every table to new body then apply page break.
Finally, append all bodies to document.
Then you finally have your result in created document.
If any doubts reply to me.
Regards,
Balaji