Inserting a Autofield in new Document

Hi,

How can i insert a new Autofield(author) in newly created document using aspose words for java API.Please guide me with sample code.

Hello,
Thank you for your request.
Could you please describe in more detail exactly what you want. Please attach the document expected that you want to get the output.

I have created a new document using the following code. I want to insert a autofield(ex.author) in this document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.save("Autofield.doc", SaveFormat.DOC);

Hi
Thanks for your request. You can set value of Author property using setAuthor.
https://reference.aspose.com/words/java/com.aspose.words/builtindocumentproperties/#getAuthor
But using Aspose.Words cannot update AUTHOR field in the document. However, Aspose.Words can update DOCPROPERTY fields. So you can use it instead AUTHOR field. Here is field code:
{ DOCPROPERTY Author \* MERGEFORMAT }
You can update such field using UpdateField method.
https://docs.aspose.com/words/java/update-field/
Hope this helps.
Best regards,

Hi,

Thanks for your reply.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

/* what should i do to insert a new autofield in this document using aspose words for java API*/

doc.save("Autofield.doc", SaveFormat.DOC);

Please try using the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.getBuiltInDocumentProperties().setAuthor("Andrey");
builder.insertField("DOCPROPERTY Author \\* MERGEFORMAT");
doc.updateFields();
doc.save("C:\\Temp\\Autofield.doc", SaveFormat.DOC);

Best regards,

The issues you have found earlier (filed as WORDSNET-4680) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(3)