我有一个控制台应用程序,该应用程序从API获取json结果,并且需要使用启用了宏的模板(它具有一些自定义快捷键,而不是页眉或页脚)。我需要将josn结果写入宏模板并将其另存为docx文件。当我尝试下面的代码时,我得到了docx文件,但是缺少自定义快捷键。谁能检查我的代码并帮助我正确执行?
C#:
private static void PocUsingDotTemplate()
{
SetAsposeLicense();
var [email protected]"C:\tools\PoC\dot-template";
var [email protected]"C:\tools\PoC\dot-template\template.dotm";
var [email protected]"C:\tools\PoC\dot-template\197669-1502119-de.html";
var opts1=new LoadOptions();
opts1. LoadFormat=LoadFormat.Dotm;
var opts2=new LoadOptions();
opts1. LoadFormat=LoadFormat.Html;
var template=new Document(pathToTemplate,opts1);
var document=new Document(pathToDocument,opts2);
DocumentBuilder dbuilder=new DocumentBuilder(template);
dbuilder. InsertDocument(document,ImportFormatMode.UseDestinationStyles);
//next lines are to generate a document with macros activated in output,
//Hence the format should be docm.
dbuilder. Document.Save($"{basepath}{DateTime.Now.GetHashCode()}.docm",SaveFormat.Docm);
//next lines removes the macro from document builder and geneates properly
//a docx document
dbuilder. Document.RemoveMacros();
dbuilder. Document.Save($"{basepath}{DateTime.Now.GetHashCode()}.docx",SaveFormat.Docx);
}
由主持人最后编辑: