在项目开发过程当中咱们常常会使用word书签替换功能导出一些模板类的文档,可能不少人都不知道word还有一个域替换的功能。能够实现和书签一样的效果,对比word书签,word域还能够用于一些对于格式要求严格的文档导出(将域创建在模板图片上),本文使用c#基于Aspose.Word实现word域套打功能c#
以word2013为例,插入-文本-文档部件-域,选择MergeFieldapp
下图示例就是插入域完毕的文档ui
string licenseFile = System.IO.Path.Combine(ModelPath, @"Model\Aspose.Words.lic"); if (File.Exists(licenseFile)) { Aspose.Words.License license = new Aspose.Words.License(); license.SetLicense(licenseFile); }
替换后效果以下spa
代码示例code