Spire.Doc 教程:用C#识别Word中的合并字段名称
生活随笔
收集整理的這篇文章主要介紹了
Spire.Doc 教程:用C#识别Word中的合并字段名称
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
我們經常遇到一個場景,就是需要將數據合并到由其他人創建的合并字段,我們不能確定合并字段的名稱。 所以為了完成郵件合并的目的,首先我們需要讀取所有合并字段的名稱。
Spire.Doc.Reporting命名空間中的MailMerge類公開了以下方法,該方法返回一個word文檔中的合并字段名稱或組(區域)名稱的集合。
- public string [] GetMergeFieldNames():返回所有合并字段名稱的集合。
- public string [] GetMergeFieldNames(string groupName):返回特定組中合并字段名稱的集合。
- public string [] GetMergeGroupNames():返回組名的集合。
了更好的演示,我們使用以下示例文檔:
以下示例詳細說明了如何讀取上述單詞文檔中的組名稱和合并字段。
//Creates Document instance Document document = new Document(); //Loads the word document document.LoadFromFile("MergeFields.docx"); //Gets the collection of group names string[] GroupNames = document.MailMerge.GetMergeGroupNames(); //Gets the collection of merge field names in a specific group string[] MergeFieldNamesWithinRegion = document.MailMerge.GetMergeFieldNames("Products"); // Gets the collection of all the merge field names string[] MergeFieldNames = document.MailMerge.GetMergeFieldNames(); Console.WriteLine("----------------Group Names-----------------------------------------"); for (int i = 0; i < GroupNames.Length; i++) { Console.WriteLine(GroupNames[i]); } Console.WriteLine("----------------Merge field names within a specific group-----------"); for (int j = 0; j < MergeFieldNamesWithinRegion.Length; j++) { Console.WriteLine(MergeFieldNamesWithinRegion[j]); } Console.WriteLine("----------------All of the merge field names------------------------"); for (int k = 0; k < MergeFieldNames.Length; k++) { Console.WriteLine(MergeFieldNames[k]); }截圖:
慧都控件網
轉載于:https://my.oschina.net/u/3006003/blog/1512564
總結
以上是生活随笔為你收集整理的Spire.Doc 教程:用C#识别Word中的合并字段名称的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在Windows平台上安装Node.js
- 下一篇: Centos7配置为NAT服务器