Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Feb 01, 2025 6:36 am

Is it possible to create a table having a final row, with SUM of all the cells in that column.

Screenshot 2025-02-01 120538.jpg

suma_ar8
 
Posts: 9
Joined: Fri Jun 21, 2024 4:28 am

Tue Feb 04, 2025 9:37 am

Hello,

Thanks for your inquiry.
In Microsoft Word, you can add the SUM(LEFT) function to achieve summation, but based on initial testing, Spire.Doc cannot achieve the correct effect. I have logged this issue to our tracking system with the ticket SPIREDOC-11084. Our development team will further investigate and fix it, and I will notify you promptly after the fix is made. Thank you for your understanding.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Fri Feb 07, 2025 6:19 am

Hello,

Thanks for your patience.
We have further investigated the issue SPIREDOC-11084. You can achieve your requirement using the following code:
Code: Select all
Document document = new Document();
Table table = document.AddSection().AddTable(true);
table.ResetCells(1, 3);
table.Rows[0].Cells[0].AddParagraph().AppendText("1");
table.Rows[0].Cells[1].AddParagraph().AppendText("2");
Field field = new Field(document);
field.Code = $"=SUM(LEFT) ";
Spire.Doc.Documents.Paragraph paragraph = table.Rows[0].Cells[2].AddParagraph();
paragraph.ChildObjects.Add(field);
FieldMark end = new FieldMark(document, Spire.Doc.Documents.FieldMarkType.FieldEnd);
paragraph.ChildObjects.Add(end);
field.End = end;
document.IsUpdateFields = true;
document.SaveToFile("res.docx");

If you have any questions about this, please feel free to write to us.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Doc

cron