翻譯|使用教程|編輯:胡濤|2022-04-22 13:22:20.407|閱讀 188 次
概述: 本文向您介紹如何使用 C# 識別 Word 中的合并字段名稱,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
我們經常遇到這樣的場景,我們需要將數據合并到其他人創建的合并字段中,并且我們不確定合并字段的名稱。所以為了完成郵件合并的目的,首先我們需要讀取所有合并字段的名稱。
Spire.Doc.Reporting 命名空間中的 MailMerge 類公開了以下方法,這些方法返回 Word 文檔中的合并字段名稱或組(區域)名稱的集合。
為了更好地演示,我們使用以下示例文檔:
下面的例子詳細說明了如何讀取上述word文檔中的組名和合并字段。
using Spire.Doc; using System; namespace MailMerge { class Program { static void Main(string[] args) { //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]); } } } }
截屏:
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn