在打开的xml中查找特定的表(在书签之后) [英] Find a specific Table (after a bookmark) in open xml

查看:118
本文介绍了在打开的xml中查找特定的表(在书签之后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a document with multiple tables in it. I need to fill some of those tables. The problem im having is how do i locate them? I can interate through them

var doc = document.MainDocumentPart.Document;
var tables= doc.Body.Elements< Table >();

但是我如何找到特定的表?该表可以更改,所以我不能依靠顺序. 我当时想在特定表格的前面放置一个书签,而只是在书签之后找到第一个表格,但是我没有找到如何做的...

But how do i find a specific table? The table can change so i cant rely on the order. I was thinking of placing a bookmark ahead of the specific table and just locate the first table after the bookmark, but i have failed to find out how to do that...

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

So, how do one find a specific table in a document?

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

If there is a better way of doing it please let me know.

推荐答案

给出表格标题.

首先在Word中创建表,然后右键单击表属性,替代文本中的一个,在标题"框中填写,保存,关闭.

First in Word, create the tables, and right click one of them, Table Properties, Alt Text, fill in the Title box, save, close.

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

Now in OpenXML, find the table with specific captions.

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;
    }
}

这篇关于在打开的xml中查找特定的表(在书签之后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆