原創(chuàng)|使用教程|編輯:王香|2017-08-18 10:02:54.000|閱讀 509 次
概述:Spire.Doc 是一個MS Word 組件,使用戶可以直接執(zhí)行各種Word文檔處理任務(wù),本文介紹了如何用C#識別Word中的合并字段名稱。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
我們經(jīng)常遇到一個場景,就是需要將數(shù)據(jù)合并到由其他人創(chuàng)建的合并字段,我們不能確定合并字段的名稱。 所以為了完成郵件合并的目的,首先我們需要讀取所有合并字段的名稱。
Spire.Doc.Reporting命名空間中的MailMerge類公開了以下方法,該方法返回一個word文檔中的合并字段名稱或組(區(qū)域)名稱的集合。
了更好的演示,我們使用以下示例文檔:
以下示例詳細(xì)說明了如何讀取上述單詞文檔中的組名稱和合并字段。
//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]); }
截圖:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn