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

Free Support Forum - aspose.com

Bookmark on totals

Bookmark.zip (60.0 KB)
attached is my project.
issue : stmt01.dot and stmt02.dot are NEARLY identical.
they have a table, a sum on the table, and a bookmark on the sum, which is displayed in the page footer.
however, the value displayed in the page footer is different between the two template files.
It took me awhile, but I finally tracked it down to the line above the table totals in stmt01 (which is correct), and isn’t present in stmt02 (which is not correct).

please advise on how to fix, hopefully without adding the line

@conniem,

You can fix the output of “result2.docx” by using the following code:

Document doc = new Document(MyDir + @"bookmark\result2.docx");
foreach(Field field in doc.Range.Fields)
{
    if (field.Start.GetAncestor(NodeType.HeaderFooter) != null)
    {
        field.IsLocked = false;
    }
}
doc.UpdateFields();
doc.Save(MyDir + @"bookmark\18.5.docx");

I updated the ‘saveas’ code to be the below, but it did not work. the footer values are incorrect

  static void SaveAs(Document aDoc, string FileName)
  {
     aDoc.FieldOptions.FileName = FileName;

     foreach(Aspose.Words.Fields.Field field in aDoc.Range.Fields)
     {
        if (field.Start.GetAncestor(Aspose.Words.NodeType.HeaderFooter) != null)
        {
           field.IsLocked = false;
        }
     }         

    aDoc.UpdateFields();         
    aDoc.UpdatePageLayout();                                       
    foreach (Aspose.Words.Tables.Table tabl in aDoc.GetChildNodes(Aspose.Words.NodeType.Table, true))
     {
        foreach(Aspose.Words.Fields.Field afield in tabl.Range.Fields)
        {
           if (afield.Type == Aspose.Words.Fields.FieldType.FieldFormula)
           {
              afield.Result = string.Empty;
              afield.Update();
              afield.IsLocked = true;
           } 
        }
     }



     aDoc.RemoveMacros();
     aDoc.Save(FileName);
  }

@conniem,

The following method produces the correct output:

static void SaveAs(Document aDoc, string FileName)
{
    aDoc.FieldOptions.FileName = FileName;

    foreach (Aspose.Words.Tables.Table tabl in aDoc.GetChildNodes(Aspose.Words.NodeType.Table, true))
    {
        foreach (Aspose.Words.Fields.Field afield in tabl.Range.Fields)
        {
            if (afield.Type == Aspose.Words.Fields.FieldType.FieldFormula)
            {
                afield.Result = string.Empty;
                afield.Update();
                afield.IsLocked = true;
            }
        }
    }

    foreach (Aspose.Words.Fields.Field field in aDoc.Range.Fields)
    {
        if (field.Start.GetAncestor(Aspose.Words.NodeType.HeaderFooter) != null)
        {
            field.IsLocked = false;
        }
    }

    aDoc.UpdateFields();
    aDoc.UpdatePageLayout();

    aDoc.RemoveMacros();
    aDoc.Save(FileName);
}