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

标签 c# winforms docx

我已经下载并开始使用 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/

相关文章:

c# - 文本未在 ListViewItem 中换行

c# - 数据库连接不起作用 C#

c# - 在双显示器的屏幕中央显示表格 如何?

c# - 我应该使用什么模式将 .NET UI 耦合到将提供回调更新的 .NET 库类

c# - 如何以编程方式使用 C#/VB.Net 以 MB 为单位测量网站带宽(上传+下载)?

c# - 在 windows 通用应用程序中实现 Master Detail 模式

C# 设置 ComboBox DropDownList 默认值或遍历所有 CheckBox

javascript - 使用原生js创建pdf文件?

java - 在java中读取.docx文件

ms-word - 如何从 Word 2007 文档链接到 chm 文件主题?