gpt4 book ai didi

c# - 使用 DocX 库在 DOCX 文件中查找表格

转载 作者:行者123 更新时间:2023-11-30 12:30:27 26 4
gpt4 key购买 nike

我已经下载并开始使用 DocX library .我有一个名为 template.docx 的文档正在加载到内存中。我在该文档中有一个表,其中包含 id = 241。我想通过它的 id 获取该表并向其中添加行。我怎样才能做到这一点?这是我的代码:

using (DocX document = DocX.Load("template.docx"))
{
int tableId = 241, i = 0;
Table t = //here I need to find the table

foreach(DataGridViewRow row in produseFacturate.Rows)
{
i++;

//here I want to add rows to the table
}
}

最佳答案

我自己找到了解决方案。

因为 document.Tables 是一个列表,我可以这样调用它:

Table t = document.Tables[3]; // I found out that the table index is actually 3;

关于c# - 使用 DocX 库在 DOCX 文件中查找表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15977202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com