Free Support Forum - aspose.com

Document.updateFields()

Hi,

The following statement works with Aspose Words version 4.0.3.0 where as it fails with 10.4.0.0
document.getRange().updateFields().
Even document.updateFields() also fails with newer version. It is throwing NullPointerException.

Part of the StackTrace Error I am getting:
java.lang.NullPointerException
at com.aspose.words.oe.Ji(FieldUpdateActionApplyResult.java:68)
at com.aspose.words.oe.perform(FieldUpdateActionApplyResult.java:56)
at com.aspose.words.Field.b(Field.java:462)
at com.aspose.words.Field.a(Field.java:395)
at com.aspose.words.Field.a(Field.java:712)
at com.aspose.words.arj.u(SpanField.java:170)
at com.aspose.words.Field.Gq(Field.java:522)
at com.aspose.words.Field.b(Field.java:450)
at com.aspose.words.Field.a(Field.java:395)
at com.aspose.words.on.a(FieldUpdater.java:154)
at com.aspose.words.on.l(FieldUpdater.java:107)
at com.aspose.words.ok.execute(FieldUpdateExecutionItem.java:82)
at com.aspose.words.on.hr(FieldUpdater.java:97)
at com.aspose.words.on.updateFields(FieldUpdater.java:57)
at com.aspose.words.Range.updateFields(Range.java:172)
at com.aspose.words.Document.updateFields(Document.java:1039)

Could you please help me in resolving this issue to update the document?

Thanks

Hi

Thanks for your request. Could you please attach the document you are getting problem with? I will check it on my side and provide you more information.

Best regards,

Hi,


It’s a report gets generated from a template. As it is a big template, I cannot modify and provide it to you.

After using the following statement we are trying to update the fields.
builder.insertTableOfContents("\h \z \c “” + elementCaption + “”");

It is the problem with the version. So could you please do the needful.

Thanks.

Hi

Thank you for additional information. I cannot reproduce the problem on my side using the latest version of Aspose.Words (10.5.0) and the following code:

// Create DocumentBuilder, which we will use to generate document.

DocumentBuilder builder = new DocumentBuilder();

// At the beggining of the document we insert TOC filed, whick will be updated before saving document.

builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");

builder.writeln();

// Build a document with complex structure by applying different heading styles thus creating TOC entries.

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);

builder.writeln("Heading 1");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);

builder.writeln("Heading 1 Data");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);

builder.writeln("Heading 1.1");

builder.writeln("Heading 1.2");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);

builder.writeln("Heading 2");

builder.writeln("Heading 3");

// Opdate fields in the document to update TOC.

builder.getDocument().updateFields();

// Now we can save the final document.

builder.getDocument().save("C:\\Temp\\out.doc");

Please try using this code and the latest version of Aspose.Words and let me know how it goes on your side.

If it does not help, could you please attach you simplified document and code which will allow me to reproduce the problem on my side.

Best regards,

Hi,

I am not getting TOT (Table of Tables) in the generated document using Aspose version 10.4.0.0.
Below here I am providing the used code & template.

DocumentBuilder builder = new DocumentBuilder(document);
removeBookMarkData(document, bookMarkName);
insertPageBreakAtBookmark(builder, bookMarkName, true, false);
if (bookMarkName != null && bookMarkName.trim().length() > 0) {
boolean moveResult = builder.moveToBookmark(bookMarkName);
//if bookmark found only then insert TOT/TOF...
if (moveResult) {
//if a heading is needed add it here
if (heading != null && heading.trim().length() > 0) {
builder.getFont().setBold(true);
builder.getRowFormat().setAlignment(RowAlignment.CENTER);
builder.writeln(heading);
//reset the font
builder.setBold(false);
}
//now add the TOC
builder.insertTableOfContents("\\h \\z \\c \"" + elementCaption + "\"");
//try to update all the fields (in current version of Aspose this does not have any effect on the TOC)
document.getRange().updateFields();
}
}

Please help me in generating the TOT.
Thanks.

Hi Spoorthy,

Thank you for additional information.

In your case, to generate TOT, the best approach I can suggest you is first moving the DocumentBuilder cursor to the end of "TOT" bookmark, insert the actual TOT inside a Paragraph there and finally by calling the Update method display the FieldResult (Actual TOT). Please see the following code snippet for clarification:

DocumentBuilder builder = new DocumentBuilder(document);
builder.MoveToBookmark("TOT", false, false);

Paragraph totParagraph = builder.CurrentParagraph;

// Insert TOT.
Field tot = builder.InsertTableOfContents("\\h \\z \\c \"" + elementCaption + "\"");
builder.Writeln();
totParagraph.ParagraphFormat.ClearFormatting();

// Update TOT.
tot.Update();

//Save output.
document.Save(@"out.doc");


I hope, this will help

Best Regards,