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 Jan 25, 2020 5:24 pm

Hello
I apologize about my bad english

With Spire.Doc professionnal 8.1.10
Windows 10 pro french language, decimal separator as comma.
Visual Studio 2019.

A table with one column of numbers and a last cell that contains a field of type FieldExpression .Code= "=SUM(ABOVE)"
When numbers are strict natural numbers, the field is correctly updated when programme change the content of one cell

If one cell contains a decimal number with comma as decimal separator, the sum excludes this value

If I try to put decimal with a dot decimal separator, I got the text "Le format de la chaîne d'entrée est incorrect."

Another remark, less dramatic : when Word meets a bad formatted value, for exemple an empty cellule, it stops adding content of further (above) cellules, but do not complains, not Spire.doc

danielhalte1
 
Posts: 23
Joined: Sat Dec 14, 2019 12:50 am

Mon Jan 27, 2020 6:22 am

Hello,

Thanks for your inquiry and sorry for the late reply as weekend.
To help us investigate your issue more accurately and quickly, please provide your input file, your full testing code as well as your expected output for our reference. You could attach them here or send them to us via email ([email protected]). Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Mon Jan 27, 2020 3:28 pm

I have attached the (very simple) docx I used for this test

And here is the code :
I replace the content of first cell with a natural number.
the second cell contains a decimal number that will not be included in the SUM(ABOVE) of the last cell.

Code: Select all
    // Le document TestFile doit exister et avoir le format attendu (voir code)
    // Test du type de champ que représente une formule =SUM(ABOVE) dans un tableau
    // et s'il est mis à jour par un IsUpdateFields=true;
    private const string TestFile = @"TestSUM.docx";
    public void Test()
    {
      using (Document doc = new Document(TestFile))
      {
        Section section = doc.Sections[0];
        Table table = section.Tables[0] as Table;
        TableRow row = table.LastRow;
        Paragraph paragraph = row.Cells[0].FirstParagraph as Paragraph;
        Field field = GetFirstField(paragraph);
        //Code= =SUM(ABOVE)  Text=3 Pattern={0} Type=FieldExpression
        Debug.Print($"Code={field.Code} Text={field.FieldText} Pattern={field.Pattern} Type={field.Type}");
        TableRow row0 = table.FirstRow;
        Paragraph paragraph0 = row0.Cells[0].FirstParagraph as Paragraph;
        paragraph0.Text = $"{DateTime.Now:fff}";
        doc.IsUpdateFields = true;
        // Ne met pas à jour le champ
        Debug.Print($"Code={field.Code} Text={field.FieldText} Pattern={field.Pattern} Type={field.Type}");
        doc.SaveToFile(TestFile, FileFormat.Docx);
        Process.Start(TestFile);
      }
    }
    private Field GetFirstField(Paragraph paragraph)
    {
      foreach (var item in paragraph.ChildObjects)
      {
        if (item is Field)
        {
          return item as Field;
        }
      }
      return null;
    }


danielhalte1
 
Posts: 23
Joined: Sat Dec 14, 2019 12:50 am

Tue Jan 28, 2020 7:38 am

Hello,

Thanks for your sharing.
Regarding "the second cell contains a decimal number that will not be included in the SUM(ABOVE) of the last cell" you mentioned, I did reproduce your issue.
And as for the issue of dot decimal separator, it can be solved by setting the thread culture, the corresponding code is as follows. However, I found the value of the last cell was also inconsistent with the value calculated by Microsoft Word, as shown in the attached screenshot.
Code: Select all
        public static void Test()
        {
            CultureInfo cc = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            using (Document doc = new Document(TestFile))
            {           
                //......
            }
            Thread.CurrentThread.CurrentCulture = cc;
        }

These two issues have been logged into our bug tracking system with the ticket SPIREDOC-3871. Besides, our Dev team is on Chinese New Year holiday (24/1/2020-/2/2/2020), they will work on your issue after they get back to the office. Sorry for the delay and inconvenience caused.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc

cron