日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

Word控件Spire.Doc 【邮件合并】教程(六): 使用 C# 识别 Word 中的合并字段名称

發布時間:2023/12/29 C# 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Word控件Spire.Doc 【邮件合并】教程(六): 使用 C# 识别 Word 中的合并字段名称 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們經常遇到這樣的場景,我們需要將數據合并到其他人創建的合并字段中,并且我們不確定合并字段的名稱。所以為了完成郵件合并的目的,首先我們需要讀取所有合并字段的名稱。

Spire.Doc for.NET 最新下載

Spire.Doc.Reporting 命名空間中的 MailMerge 類公開了以下方法,這些方法返回 Word 文檔中的合并字段名稱或組(區域)名稱的集合。

  • public string[] GetMergeFieldNames():返回所有合并字段名稱的集合。
  • public string[] GetMergeFieldNames(string groupName):返回特定組內合并字段名稱的集合。
  • public string[] GetMergeGroupNames():返回組名的集合。

為了更好地演示,我們使用以下示例文檔:


下面的例子詳細說明了如何讀取上述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]); }}} }

截屏:?

總結

以上是生活随笔為你收集整理的Word控件Spire.Doc 【邮件合并】教程(六): 使用 C# 识别 Word 中的合并字段名称的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。