Menu

Same numberOfDigitsAfterPoint in several styles

bcianyo
2018-07-21
2018-07-22
  • bcianyo

    bcianyo - 2018-07-21

    I want two styles that differ in fgColor and have numberOfDigitsAfterPoint=2 so I did:

    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    #include <math.h>
    #include <map>
    
    #include <SimpleXlsx/Chart.h>
    #include <SimpleXlsx/Chartsheet.h>
    #include <SimpleXlsx/Workbook.h>
    #include <SimpleXlsx/XLSXColorLib.h>
    using namespace std;
    using namespace SimpleXlsx;
    
    int main()
    {
        CWorkbook book;
    
        CWorksheet & sheet = book.AddSheet( "Data" );
    
        enum StyleType
        {
            BORDER_FILL_COLOUR1_2DIGITS
            ,BORDER_FILL_COLOUR2_2DIGITS
    
        };
    
        std::map<StyleType, std::size_t> indices;
    
        {
        SimpleXlsx::Style st;
        st.border.left.style = SimpleXlsx::BORDER_THIN;
        st.border.right.style = st.border.left.style;
        st.border.bottom.style = st.border.left.style;
        st.border.top.style = st.border.left.style;
        st.fill.patternType = SimpleXlsx::PATTERN_SOLID;
        st.fill.fgColor = "FFFAAFAF";
        st.numFormat.numberOfDigitsAfterPoint = 2;
        st.numFormat.numberStyle = SimpleXlsx::NUMSTYLE_NUMERIC;
        indices[BORDER_FILL_COLOUR1_2DIGITS] = book.AddStyle(st);
        }
    
        {
        SimpleXlsx::Style st;
        st.border.left.style = SimpleXlsx::BORDER_THIN;
        st.border.right.style = st.border.left.style;
        st.border.bottom.style = st.border.left.style;
        st.border.top.style = st.border.left.style;
        st.fill.patternType = SimpleXlsx::PATTERN_SOLID;
        st.fill.fgColor = "FFFFFF00";
        st.numFormat.numberOfDigitsAfterPoint = 2;
        st.numFormat.numberStyle = SimpleXlsx::NUMSTYLE_NUMERIC;
        indices[BORDER_FILL_COLOUR2_2DIGITS] = book.AddStyle(st);
        }
    
        for( int i = 0; i < 20; i++ )
        {
    
            sheet.BeginRow();
    
            sheet.AddCell(log(i+1.0), indices[BORDER_FILL_COLOUR1_2DIGITS]);
            sheet.AddCell(i*i/1.3, indices[BORDER_FILL_COLOUR2_2DIGITS]);
            sheet.EndRow();
        }
    
       book.Save("test.xlsx");
    
        return 0;
    }
    

    MS Excel 2010 displays test.xlsx like this:
    0.00 0
    0.69 1
    1.10 3 ...
    I want like this:
    0.00 0.00
    0.69 0.77
    1.10 3.08 ...
    If I chek cell format of 2nd column in Excel it appears to be set numeric and 0 (zero!) digits afeter point. I want in both column 2 digits after point.
    I tried to set st.numFormat.formatString = "0.00" instead of st.numFormat.numberOfDigitsAfterPoint = 2 in both styles and it also work as above. If I set different numberOfDigitsAfterPoint in two styles (suppose 2 and 3) it dysplays correctly. But I want same numberOfDigitsAfterPoint.
    Copiled SimpleXlsx-r0.29 with g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0 on Windows.
    How can I achieve this?

     
  • bcianyo

    bcianyo - 2018-07-21

    LibreOffice Calc 6.0.2.1 also displays 2nd column of test.xlsx with 0 digits after point.
    EDIT:
    I can programmatically round values up to 2 digits after point. But I dont thik it's a good solution.

     

    Last edit: bcianyo 2018-07-21
  • Alexandr Belyak

    Alexandr Belyak - 2018-07-21

    Hi,
    Thanks for the detailed description of the problem. This is a library error with the number format.
    Please check the new version of the library from the attachment.

     
  • bcianyo

    bcianyo - 2018-07-21

    Yes. The new version seems to work correctly with my numbers. I created some styles with different digits after point and all of them displays exactly what I want.

     
  • Alexandr Belyak

    Alexandr Belyak - 2018-07-22

    Ok. Thank you for testing. Now the library has become even better :-)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.