在open xml中查找特定的表(在书签之后)

mer*_*ger 3 c# openxml

我有一个包含多个表的文档.我需要填写其中一些表格.我遇到的问题是如何找到它们?我可以通过它们进行交流

var doc = document.MainDocumentPart.Document;
var tables= doc.Body.Elements< Table >();
Run Code Online (Sandbox Code Playgroud)

但是我如何找到特定的表?表格可以改变,所以我不能依赖订单.我想把书签放在特定的桌子前面,然后找到书签后的第一张桌子,但是我没找到怎么做...

那么,如何在文档中找到特定的表?

如果有更好的方法,请告诉我.

jn1*_*1kk 6

给表格标题.

首先在Word中创建表,然后右键单击其中一个表,表格属性,替换文字,填写标题框,保存,关闭.

现在在OpenXML中,找到具有特定标题的表.

IEnumerable<TableProperties> tableProperties = bd.Descendants<TableProperties>().Where(tp => tp.TableCaption != null);
foreach(TableProperties tProp in tableProperties)
{
    if(tProp.TableCaption.Val.Equals("myCaption")) // see comment, this is actually StringValue
    {
        // do something for table with myCaption
        Table table = (Table) tProp.Parent;
    }
}
Run Code Online (Sandbox Code Playgroud)