电脑教程
位置:首页>> 电脑教程>> office教程>> Spire.Doc 教程:用C 识别Word中的合并字段名称

Spire.Doc 教程:用C 识别Word中的合并字段名称

  发布时间:2023-07-04 01:37:36 

标签:字段,合并字段名称,public,string

我们经常遇到一个场景,就是需要将数据合并到由其他人创建的合并字段,我们不能确定合并字段的名称。 所以为了完成邮件合并的目的,首先我们需要读取所有合并字段的名称。

Spire.Doc.Reporting命名空间中的MailMerge类公开了以下方法,该方法返回一个word文档中的合并字段名称或组(区域)名称的集合。

  • public string  GetMergeFieldNames:返回所有合并字段名称的集合。

  • public string  GetMergeFieldNames(string groupName):返回特定组中合并字段名称的集合。

  • public string  GetMergeGroupNames:返回组名的集合。

了更好的演示,我们使用以下示例文档:

Spire.Doc 教程:用C 识别Word中的合并字段名称

以下示例详细说明了如何读取上述单词文档中的组名称和合并字段。

//Creates Document instanceDocument document = new Document;//Loads the word documentdocument.LoadFromFile("MergeFields.docx");//Gets the collection of group namesstring GroupNames = document.MailMerge.GetMergeGroupNames;//Gets the collection of merge field names in a specific groupstring MergeFieldNamesWithinRegion = document.MailMerge.GetMergeFieldNames("Products");// Gets the collection of all the merge field namesstring MergeFieldNames = document.MailMerge.GetMergeFieldNames;Console.WriteLine("----------------Group Names-----------------------------------------");for (int i = 0; i

截图:

Spire.Doc 教程:用C 识别Word中的合并字段名称

慧都控件网

有用(0)没用(0)

0
投稿

猜你喜欢

手机版 电脑教程 asp之家 www.aspxhome.com