We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Using UpdateFields() to update a Sum will not sum field values

I'm using Aspose 15.10. I'm trying to get a Word "sum" formula to update. I've included an example document in which there are two scenarios:
- Simple: the column contains normal numbers
- Fields: the column contains fields whose display values are numbers

In both cases, highlighting the "sum" formula and hitting F9 correctly updates the sum within Word.

Using Aspose:
- Iterating over Fields and using FieldStart.Range.UpdateFields() doesn't seem to work for either case.
- Using Document.UpdateFields() will update the "Simple" case, but does not update the "Fields" case.

I've attached a sample document and .NET solution that demonstrates the issues. Can you please let me know what I'm doing wrong? What I really need to get working is to have the "Fields" column summing work. Thank you!

Bryan

Hi Bryan,


Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 15.10.0, we managed to reproduce this issue on our end. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-12701. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Hi Bryan,


Thanks for being patient. Regarding WORDSNET-12701, our product team has completed the work on your issue and has come to a conclusion that this issue and the undesired behaviour you’re observing is actually not a bug in Aspose.Words. So, we have closed this issue as ‘Not a Bug’.

The problem occurs because the sample code does not update formula fields at all. Because, fieldStart.Range contains only field start node, but the Range.UpdateFields method updates only complete fields in the range. You should use following code snippet to update formula fields in document:

foreach (Field field in document.Range.Fields)

{

if (field.Type == FieldType.FieldFormula)

{

field.Update();

}

}


Hope, this helps.

Best regards,

Thank you very much - this was extremely helpful.


I’m hoping you can tell me how to iterate over fields in a document without using Document.Range.Fields - that iterator appears to have been added in a version after the one that we’re currently using (11.9). I would just upgrade to the most recent version, but the testing and deployment procedure will take forever; it would be much faster to get it working in our current version.

Thank you for any pointers that you can provide!

Hi Bryan,


Thanks for your inquiry. Please check the following code:

foreach (FieldStart start in doc.GetChildNodes(NodeType.FieldStart, true))

{

if (start.FieldType == FieldType.FieldFormula)

{

Field field = start.GetField();

field.Update();

}

}


Hope, this helps.

Bets regards,

Thank you very much for trying to help. However, in the version of Aspose I’m trying to use (11.9), “start.GetField()” will not compile - the FieldStart object doesn’t have a method GetField() available. Is there another way to do so in version 11.9 (please say there is!)?


Thank you!

Bryan

Hi Bryan,


Thanks for your inquiry. You may try using the following code but it may also be error prone. I suggest you please upgrade to the latest version of Aspose.Words.

foreach (FieldStart start in doc.GetChildNodes(NodeType.FieldStart, true))

{

if (start.FieldType == FieldType.FieldFormula)

{

start.ParentParagraph.Range.UpdateFields();

}

}


Best regards,

That worked! I’m doing a very happy dance. Thank you so much for your assistance!


Bryan