在OpenXML中检测表的范围 [英] Detect the Range for table in OpenXML

查看:78
本文介绍了在OpenXML中检测表的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用openxml打开和编辑eh word文档.

因为我还曾研究Microsoft DOM组件 Microsoft.Office.Interop.Word
在其中我们可以选择特定的表并使用我们的新内容来更新该表.
同样:

Hi

I am using openxml to open and edit eh word document.

As i had also worked on Microsoft DOM component Microsoft.Office.Interop.Word
in which we can select the particular table and update the table with our new content.
likewise:

 Range rng5 = adoc.Tables[24].Cell(1, 1).Range;
rng5.InlineShapes.AddPicture(@"C:\FIGURE1.JPG", ref missing, ref missing, ref missing);



现在,我要通过openXMl进行相同的操作,我想这样做,并选择文档中的各个表.
所以首先,我无法像在DOM编码中一样搜索表(24)
那么我该如何用更新代码标记范围.



Now I am doing same via openXMl where I want to do the same and select the various tables in my document.
So first of all I am unable to search the table as I am doing in my DOM coding (24)
then how do I mark the range with update code.

<pre lang="xml">// Find the first table in the document.
       Table table =
           doc.MainDocumentPart.Document.Body.Elements<Table>().First();




请帮帮我.

提前谢谢..

问候
Mahendra Varandani




Please assist me.

Thanks in advance..

regards
Mahendra Varandani

推荐答案

MainDocumentPart mainPart = doc.MainDocumentPart;

            List<sdtblock> sdtList = mainPart.Document.Descendants<sdtblock>().ToList();
            SdtBlock sdtA = null;

            foreach (SdtBlock sdt in sdtList)
            {
                var test = sdt.SdtProperties.GetFirstChild<tag>().Val.Value;
                if (sdt.SdtProperties.GetFirstChild<tag>().Val.Value == replacestring)
                {
                    sdtA = sdt;
                    break;
                }
            }
            sdtA.AppendChild(table);</tag></tag></sdtblock></sdtblock>


这篇关于在OpenXML中检测表的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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