Updating a cell in a table

Hi,
I am currently working on a program that takes the document produced from a merge performed by ASPOSE and removing empty rows based on a set of rules. This works fine until I come accross a table using the formula SUM(ABOVE). When the document is returned from the merge the formula still shows but you can see the result by toggleing between show field codes on/off. After I have processed the table removing the empty rows the formula no longer shows the value but instead just zero. If I manually highlight the field and use the update field option in MS Word it re-calculates the SUM and I get the correct value. So my question is how can I replicate this manual step in my program using ASPOSE functions so that when I save the document it show the correct value after deleting the empty rows. I have tried using the cell.range.replace but it doesn’t update the contents on the cell .
Any ideas please.

Hi Timothy,

Thanks for your inquiry. Please call Document.UpdateFields method before saving the final output document. Hope this helps you.

If you still face problem, please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.

Please find attached copy inpyt document, output document and sample code.

Hi Timothy,

Thanks for sharing the detail. I have used the following code example to test the shared issue and have not found the shared issue.

Document doc = new Document(MyDir + "InputDocument.docx");
doc.UpdateFields();
doc.Save(MyDir + "Out.docx");

In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.11.0) from here and let us know how it goes on your side. If the problem still remains, please share following detail for investigation purposes.

  • Please create a standalone/runnable simple application (for example a Console
    Application Project
    ) that demonstrates the code (Aspose.Words code) you used to generate your output document

Hi,
I have plese find attached a sample program, input word document and the output file produced. I have tried it wirh version V14.11 and it still doesn’t work. I The input file was produced by a program using ASPOSE.WORD and my sample program the updates the document to remove the blank rows. the SUM(ABOVE) is correct in the input file but goes to zero on the output file.
Many thanks for your help
Tim

Hi Tim,

Thanks
for sharing the detail. Please use Row.Remove method to remove the row instead of Row.RemoveAllChildren. This will fix the issue which you are facing. Please let us know if you have any more queries.

// Remove blank lines - ignoring header
if (iTableCount > iStartTable)
{
    //...
    //...
    //...
    if (removeRow)
    {
        if (blankCellCount == Number_of_columns_to_check)
        {
            row.Remove();
        }
    }
    //...
    //...
    //...
}
asposeDocument.UpdateFields();
asposeDocument.Save("Output.doc");

Hi,
Thank you very much, all is now working.
Regards
Tim

Hi Tim,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.