c# - 如何从文档中的特定位置读取表格?

标签 c# ms-word

当我使用以下行时,它会读取该特定文档的所有表格:

  foreach (Microsoft.Office.Interop.Word.Table tableContent in document.Tables)

但是我想读取特定内容的表格,例如从一个标识符到另一个标识符。

标识符的形式可以是[SRS oraganisation_123]到另一个标识符[SRS Oraganisation_456]

我只想读取上述标识符之间的表格。

假设第 34 页包含我的标识符,所以我想读取从那一点到我遇到第二个标识符的所有表格。我不想阅读剩余的表格。

请问我对问题的任何澄清。

最佳答案

假设开始和结束标识符存储在名为 myStartIdentifiermyEndIdentifier 的变量中 -

    Range myRange = doc.Range();
    int iTagStartIdx = 0;
    int iTagEndIdx = 0;

    if (myRange.Find.Execute(myStartIdentifier))
        iTagStartIdx = myRange.Start;

    myRange = doc.Range();    
    if (myRange.Find.Execute(myEndIdentifier))
        iTagEndIdx = myRange.Start;

    foreach (Table tbl in doc.Range(iTagStartIdx,iTagEndIdx).Tables)
    {
       // Your code goes here
    }

关于c# - 如何从文档中的特定位置读取表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15893130/

相关文章:

c# - 为什么在不修改枚举集合时得到 "Collection was modified; enumeration operation may not execute"?

c# - 未更新的行

c# - 在使用 WinAppDriver 单击之前等待元素

java - 在 Java 中将 Microsoft Word 文档读入纯文本(DOC、DOCX)

ms-word - Word AddIn 无法加载,但是当我将 Visual Studio 的 "Solution Configuration"从“调试”更改为“发布”时,它会加载

c# - 清空 <tbody> 不起作用

c# - 将 JSON 反序列化为在局部 View 中呈现的模型(restsharp 或任何其他方法)

excel - 通过 CreateObject ("Application"获取 Access 2007 中的全名)..?

ios - 通过 ms-word 打开 Office 文档 :ofe on iPad

c++ - MS Word InsertBreak 抛出异常