Document is being saved as a template


#1

I’m creating a new document based on a template like this:

Document doc = new Document(“template.dot”);



I add some stuff and then I save it: doc.Save(“C:/NewDocument.doc”);



The NewDocument.doc is a template - when I open the document and go to
“Templates and Add ins” I can’t assign a template because the saved
document is a template.



I also tried creating a new document and attaching the template but the
style names I need aren’t getting imported that way.



Any suggestions? I’m using the java version.



Thanks







#2

Document doc = new Document(fileName)

just opens the file you specify. It does not create a new document based on a template. Therefore when you save it, you still get the template. This was the default behaviour for Aspose.Words for .NET before version 4.0 and it is still the behaviour for Aspose.Words for Java.

In general, I recommend you get along without templates. Most of the time you don't have to use templates. Just use normal documents if you can.

Because customers reported this issue several times (opened a template and thought it would create a new document instead), we changed the behaviour of the Document constructor since Aspose.Words 4.0 for .NET (and next Java version too).

Now when you new Document("myTemplate.dot"), it will open a document and reset the "template" flag. So when you do Document.Save, it will save as a normal document.

You can also explicitly control whether you want the document to be saved as template or document using the Document.IsTemplate property and specify Document.AttachedTemplate. However, this is not yet available in the Java version. This update will come out, probably end of this month.

If you have to use templates and have to use the Java version, you need to wait till the next release.


#3

I do need to use the styles defined in the template. I look forward to the next release.

Thanks!