文檔半島外圍網上直營>>E-iceblue中文文檔>>識別 Word 中的合并字段名稱
                識別 Word 中的合并字段名稱
我們經常遇到這樣的場景,我們需要將數據合并到其他人創建的合并字段中,并且我們不確定合并字段的名稱。所以為了完成郵件合并的目的,首先我們需要讀取所有合并字段的名稱。
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]);
}
}
}
}
	
截屏:
	 
 
歡迎下載|體驗更多E-iceblue產品

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線