Hi,
I have a number of templates, each containing a few buildingblocks, which are only relevant to the containing template. This is to simplify the UI for the user, so they only have a few buildingblocks available per document, and to prevent them from using the wrong ones.
When I create the document using Word only, everything is fine, as Word retains the reference to the template.
However, when I create a document using Aspose, there is no longer a reference to the template and therefore not to the buildingblocks.
The code I use is quite simple:
Aspose.Words.Document doc = new Aspose.Words.Document("Template.dotx");
doc.Save("document.docx", Aspose.Words.SaveFormat.Docx);
I have tried setting the template explicitly with this code:
Aspose.Words.Document doc = new Aspose.Words.Document("Template.dotx");
doc.BuiltInDocumentProperties.Template = "Template.dotx";
doc.Save("document.docx", Aspose.Words.SaveFormat.Docx);
But that gave an error with the Aspose error “This operation requires the node to be inside the main document.”
I’m using Aspose Words 11.5.0.0.
Can you guide me to how I can get the template reference to stay when creating document?
Regards
Thomas
Thomas:
However, when I create a document using Aspose, there is no longer a reference to the template and therefore not to the buildingblocks.
Could you please attach your input template document (Template.dotx file) here for testing? I will investigate the issue on my side and provide you more information.
Hi Awais,
I tried the AttachedTemplate properti, but it gave me the same result.
I have attached the tempalte to this post, so you can take a look at it.
Regards
Thomas
While using the latest version of Aspose.Words i.e. 11.7.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The issue ID is WORDSNET-6859. Your request has also been linked to this issue and you will be notified as soon as it is resolved.
Hello Thomas,
Thanks for your interest to Aspose.Words. I’m working on the issue you have reported earlier.
I cannot reproduce the problem on my side using the latest version of Aspose.Words 11.7.0.0.
I use the following code for testing:
Hi Andrey,
I will try with 11.7, but I have a question to your code:
The template we are using is called “Dagsorden DA.dotx”, which is the one used for creating a new document, and is the template I wanted attached. But In your sample, you attach a template called “MyTemplate.dotx”. Have you tried the code with “Dagsorden DA.dotx” as the AttachTemplate?
Regards
Thomas
Thanks for your request. Range.UpdateFields method updates all fields in a document. So, if you call this method somewhere before saving document, fields will be updated. Also, fields in a document can be updated when you open this document in MS Word. Please let us know if you need more information.
The template we are using is called “Dagsorden DA.dotx”, which is the one used for creating a new document, and is the template I wanted attached. But In your sample, after attached a template called “MyTemplate.dotx”,and save this document,but Automatically update document styles is not set,Therefore, the template style in the document does not change,Have you tried the code with “Dagsorden DA.dotx” as the AttachTemplate?
Thanks for your inquiry. Unfortunately, Aspose.Words does not support this feature (WORDSNET-2177: automatically update document styles) yet. We will consider adding such feature in future. We will keep you informed and let you know once it is available.