简体   繁体   English

如何使用open xml sdk获取word文档的所有合并字段

[英]How to get all merge fields of word document using open xml sdk

I am beginner to open xml sdk. 我是初学者,打开xml sdk。 I am trying to find out all merge fields of document. 我试图找出文档的所有合并字段。

But I am not getting the headers and footers merge fields. 但我没有得到页眉和页脚合并字段。

Can any one suggest a working solution? 任何人都可以提出有效的解决方案吗

I am trying some thing like this - 我正在尝试这样的事情 -

foreach (FieldCode field in docGenerated.MainDocumentPart.RootElement.Descendants<FieldCode>())
                    {

                        String fieldText = field.Text;
                        if (fieldText.StartsWith(" MERGEFIELD"))
                        {
                            Int32 endMerge = fieldText.IndexOf("\\");

                            Int32 fieldNameLength = fieldText.Length - endMerge;

                            String fieldName = fieldText.Substring(11, endMerge - 11);

                            fieldName = fieldName.Trim();
                         }
}

You have to loop through header and footer separately, see the following code: 您必须分别遍历页眉和页脚,请参阅以下代码:

foreach (var header in doc.MainDocumentPart.HeaderParts)
            foreach (var cc in header.RootElement.Descendants<FieldCode>())
                //DO CODE
foreach (var footer in doc.MainDocumentPart.FooterParts)
           foreach (var cc in footer.RootElement.Descendants<FieldCode>())
                //DO CODE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Open XML SDK从Word文档获取特定页面 - Get particular page from Word document using Open XML SDK 如何使用类似 json 格式的 C# open-xml SDK 从 Word 文档中获取文本? - How to get text out of Word Document using C# open-xml SDK in json like format? 如何使用C#中的Open XML SDK锁定Word文档上的所有字段(CTRL-A,CTRL-F11) - How do I lock all fields (CTRL-A, CTRL-F11) on a word doc using Open XML SDK in C# 无法使用打开的xml在单词中找到合并字段 - Unable to find Merge Fields in word using open xml 如何使用打开的 xml sdk 2.0 在 Word 文档、C++\CLI 中读取书签值 - How to read bookmarks value in word document, C++\CLI using open xml sdk 2.0 如何使用C#和Open XML SDK按部分拆分Word文档? - How to split a Word document by section using C# and the Open XML SDK? 如何使用 Open XML SDK 用图像替换 Word 文档 (docx) 中的书签? - How to replace bookmark in Word document (docx) with an image using Open XML SDK? 如何使用开放XML SDK在word文档的页脚中查找和替换文本? - How to find and replace the text in the footer of the word document using open XML SDK? 如何从 Word 文档中复制富文本内容控件的内容并使用 Open XML SDK 删除控件本身 - How to copy content of Rich Text Content Control from Word document and remove the control itself using Open XML SDK 我如何获得 <w:pict> 使用开放xml从Word文档中标记 - how i can get a <w:pict> tag from word document using open xml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM