I have a console application which gets json result from an API and need to use a macros enabled template(it has some custom shortcut keys not header or footer). I need to write the josn result into the macros template and save it as a docx file. When I tried below code, I got the docx file but the custom shortcut keys are missing. Can anyone check my code and help me do it right?
C#:
private static void PocUsingDotTemplate()
{
SetAsposeLicense();
var basePath=@"C:\tools\PoC\dot-template";
var pathToTemplate=@"C:\tools\PoC\dot-template\template.dotm";
var pathtoDocument=@"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);
}
Last edited by a moderator: