Menu

Version with Unicode support

2017-01-28
2017-03-20
  • Alexandr Belyak

    Alexandr Belyak - 2017-01-28

    Hello all.

    Thanks again to Pavel for the good library.

    I had some free time and I tried to make support for Unicode, and also fix some bugs.
    Below is a list of major changes (I named r0.21 version):

    • XmlWriter is rewritten to work with Unicode, implemented writing of strings in UTF-8.
    • Rewrote all the code to work with the new XmlWriter. All string constants for XML stored in the type const char * , which allows speed up the work and reduce the size of the executable file for the Unicode version.
    • Minimal use _stprintf functions, which is replaced by _tstringstream for the safety (no fixed buffer length).
    • Fixed bugs in the charts module, because of what Excel can not open the file or display it correctly. Compatibility is also upgraded to Office 2010 because of the charts.
    • For fields valAxisFrom and valAxisTo (from CChartsheet::Series) made standard numbering for rows (from 1)
    • For CWorkbook you can specify the name of the author. If not specified, the current user name is queried from the Operation system.
    • Many functions AddCell of the CWorksheet class can take the "raw" data without the need to create wrapper classes (for example, without CellDataStr or CellDataInt).

    Unfortunately I can not attach a file to the topic, so I leave a link to Dropbox:
    https://dl.dropboxusercontent.com/u/5514290/SimpleXlsx%20r0.21.zip

    I tested the updated library on the following platforms:

    Linux Mint 18.1 Cinnamon 64-bit
    gcc version 5.4.0 64-bit

    Linux Ubuntu 10.04.1 LTS 32-bit
    gcc version 4.4.3 32-bit

    Windows 7 SP1 64-bit
    MinGW 4.8.2 32-bit

    Windows 7 SP1 64-bit
    Microsoft Visual Studio 2012 C++ 32-bit

    I hope that the changes will be useful. I will be glad to any feedback about of the updated library.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-01-28

    Ok, the second message allows to attach a file.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-01-28

    A small example of the updated library:

    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #include "SimpleXLSX/Xlsx/Workbook.h"
    
    using namespace SimpleXlsx;
    
    int main( int argc, char * argv[] )
    {
        ( void )argc; ( void )argv;
    
        setlocale( LC_ALL, "" );
    
        time_t CurrentTime = time( NULL );
        srand( static_cast<unsigned int>( CurrentTime ) );
    
        CWorkbook Book( _T( "Incognito" ) );
    
        {
    #ifndef _UNICODE
    #error For this test must be defined _UNICODE macro!
    #endif
            std::vector<ColumnWidth> ColWidth;
            ColWidth.push_back( ColumnWidth( 0, 3, 20 ) );
            CWorksheet & Sheet = Book.AddSheet( _T( "Unicode" ), ColWidth );
    
            Style style;
            style.horizAlign = ALIGN_H_CENTER;
            style.font.attributes = FONT_BOLD;
            size_t CenterStyleIndex = Book.m_styleList.Add( style );
    
            Sheet.BeginRow();
            Sheet.AddCell( "Common test of Unicode support", CenterStyleIndex );
            Sheet.MergeCells( CellCoord( 1, 0 ), CellCoord( 1, 3 ) );
            Sheet.EndRow();
    
            Font TmpFont = Book.m_styleList.GetFonts().front();
            TmpFont.attributes = FONT_ITALIC;
            Comment Com;
            Com.x = 250;
            Com.y = 100;
            Com.width = 100;
            Com.height = 30;
            Com.cellRef = CellCoord( 8, 1 );
            Com.isHidden = false;
            Com.contents.push_back( std::pair<Font, _tstring>( TmpFont, _T( "Comment with custom style" ) ) );
            Sheet.AddComment( Com );
    
    
            Sheet.BeginRow();
            Sheet.AddCell( "English language" );
            Sheet.AddCell( "English language" );
            Sheet.EndRow();
    
            Sheet.BeginRow();
            Sheet.AddCell( "Russian language" );
            Sheet.AddCell( _T( "Русский язык" ) );
            Sheet.EndRow();
    
            Sheet.BeginRow();
            Sheet.AddCell( "Chinese language" );
            Sheet.AddCell( _T( "中文" ) );
            Sheet.EndRow();
    
            Sheet.BeginRow();
            Sheet.AddCell( "French language" );
            Sheet.AddCell( _T( "le français" ) );
            Sheet.EndRow();
    
            Sheet.BeginRow();
            Sheet.AddCell( "Arabic language" );
            Sheet.AddCell( _T( "العَرَبِيَّة‎‎" ) );
            Sheet.EndRow();
    
            Sheet.BeginRow();
            Sheet.EndRow();
    
            style.fill.patternType = PATTERN_NONE;
            style.font.theme = true;
            style.horizAlign = ALIGN_H_RIGHT;
            style.vertAlign = ALIGN_V_CENTER;
    
            style.numFormat.numberStyle = NUMSTYLE_MONEY;
    
            size_t MoneyStyleIndex = Book.m_styleList.Add( style );
    
            Sheet.BeginRow();
            Sheet.AddCell( "Money symbol" );
            Sheet.AddCell( 123.45, MoneyStyleIndex );
            Sheet.EndRow();
    
            style.numFormat.numberStyle = NUMSTYLE_DATETIME;
            size_t DateTimeStyleIndex = Book.m_styleList.Add( style );
    
            Sheet.BeginRow();
            Sheet.AddCell( "Write date/time" );
            Sheet.AddCell( CurrentTime, DateTimeStyleIndex );
            Sheet.EndRow();
    
            style.numFormat.formatString = "hh:mm:ss";
            size_t CustomDateTimeStyleIndex = Book.m_styleList.Add( style );
            Sheet.BeginRow();
            Sheet.AddCell( "Custom date/time" );
            Sheet.AddCell( CurrentTime, CustomDateTimeStyleIndex );
            Sheet.EndRow();
    
        }
        {
            //data sheet to store data to be referenced
            CWorksheet & Sheet = Book.AddSheet( _T( "Data" ) );
    
            std::vector<CellDataDbl> data1, data2;
            CellDataDbl cellDbl;
            cellDbl.style_id = 0;
    
            // fill data sheet with randomly generated numbers
            for( int i = 0; i < 15; i++ )
            {
                cellDbl.value = ( rand() % 100 ) / 50.0;
                data1.push_back( cellDbl );
                cellDbl.value = 2.0 - cellDbl.value;
                data2.push_back( cellDbl );
            }
    
            Sheet.AddRow( data1 ); // data can be added by row or by cell
            Sheet.AddRow( data2 );
    
            // create series object, that contains most chart settings
            CChartsheet::Series ser;
    
            // adding chart to the workbook the reference to a newly created object is returned
            CChartsheet & line_chart = Book.AddChart( _T( "Line Chart" ), CHART_LINEAR );
    
            // leave category sequence (X axis) not specified (optional) - MS Excel will generate the default sequence automatically
            ser.catSheet =  NULL;
    
            // specify range for values` sequence (Y axis)
            ser.valAxisFrom = CellCoord( 1, 0 );
            ser.valAxisTo = CellCoord( 1, 10 );
            ser.valSheet =  &Sheet; // don`t forget to set the pointer to the data sheet
    
            ser.title = _T( "Line series test" );
            ser.isSmoothed = true;  // determines whether series will be a smoothed or straight-lined curve
            ser.isMarked = false;   // if true add diamond marks in each node of the sequence set
    
            // add series into the chart (you can add as many series as you wish into the same chart)
            line_chart.AddSeries( ser );
    
            //Second line to the chart
            CChartsheet::Series ser2 = ser;
            ser2.valAxisFrom = CellCoord( 2, 0 );
            ser2.valAxisTo = CellCoord( 2, 10 );
            ser2.title = _T( "Second Line" );
            line_chart.AddSeries( ser2 );
        }
    
        if( Book.Save( _T( "MyBook.xlsx" ) ) )   std::cout << "The book has been saved successfully" << std::endl;
        else        std::cout << "The book saving has been failed" << std::endl;
    
        return 0;
    }
    
     
  • Alexandr Belyak

    Alexandr Belyak - 2017-02-22

    Version 0.22. Change log:
    - Support for the TDM-GCC 64-bit compiler (thanks to Eduardo Baena).
    - Minor bug fixes.

    Note for Windows users. To work with Unicode you must specify two macros/defines in the compiler options: "_UNICODE" and "UNICODE".

     
  • Aso

    Aso - 2017-03-09

    Thanks Alexandr for the updates.
    It would be good if we could create charts in the worksheets not necessarily in separate chartsheets. Do you think it is possible?

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-03-13

    Hi Aso.
    Thank you for your message. I will try to deal with this issue.
    Perhaps in 3 weeks I will have free time for this.
    If you are willing to help with testing, then send me an email. My address is in the source code.

     
  • E.Naumovich

    E.Naumovich - 2017-03-20

    HI,
    Alexandr, thanks for good enhancements.
    I hope this week I will improve scatter charts to more "scientific" appearance, including color and symbol selection and width of the lines.
    Regards.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-03-24

    Hi E.Naumovich.
    This is a great idea. You can send me your results for testing. My address is in the source code.

     
  • E.Naumovich

    E.Naumovich - 2017-03-27

    Hi,
    please find attached file, it include improved version of lib code and kind of example.
    It is not finished yet- I hung on colors. I know how to introduce them, but I don find a solution, handy for user. Also I did not touch a linear plot code- now there are some stubs to avoid conflicts.
    I`m using mingw_w64 gcc 6.x 32b

     
  • E.Naumovich

    E.Naumovich - 2017-03-27

    Version with RGB colors. Colors are not checked inside.

     
  • E.Naumovich

    E.Naumovich - 2017-03-31

    Version with RGB colors+ autogenerated colors libraries.
    Error in Chartsheet.cpp concerning orietation of the X-axis title is corrected.
    I`m waiting for response,
    Regards.

     
  • E.Naumovich

    E.Naumovich - 2017-04-03

    Hello,
    I found an arror in implementation of the X-axis code.
    Probably two kinds of the X axes should be considered, one "cat" (for bar diagramms?) and one "val" (for scatter and for lines).
    I`ll put parched code probaly tomorrow.

     
  • E.Naumovich

    E.Naumovich - 2017-04-04

    Hi,
    Another one iteration. Corrected issue with X-axis tag.
    Example is in tst_charts1 sub-dir.
    Regards,

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-04-05

    Hi.
    Thanks for your useful enhancements. I tested an updated library with your example, it works well (MinGW 4.8.2 32-bit).
    I liked your idea with the library of auto-generated colors :-)

    I have one question. The original library does not require C++11. Your version requires C++11. Maybe we should maintain compatibility with old compilers? I think this can be useful.

     
  • E.Naumovich

    E.Naumovich - 2017-04-06

    "maintain compatibility with old compilers? "
    I`m using last versions of gcc which are avaliable with mingw, so I dont care too much about pre-C++11 compatibility, MS VC compatibility, etc..
    With c++98 I found few points and made corrections. see attach.

     

    Last edit: E.Naumovich 2017-04-06
  • Alexandr Belyak

    Alexandr Belyak - 2017-04-06

    Just the original library does not use C++11 and I tried to keep compatibility for existing projects. I asked you about this.
    I tested simplexlsx-r022e_201704060905.7z, everything works. Thanks for the change.
    P.S. I also use GCC and C++11 in all my projects under Linux and Windows.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-05-14

    Version 0.23. Change log:
    - Improved scatter charts to more "scientific" appearance, including color and symbol selection and width of the lines (thanks for this to E.Naumovich).
    - Creating charts in the worksheets by CWorkbook::AddChart. For chart sheets must be used CWorkbook::AddChartSheet (thanks for idea to Aso).
    - Now the sheets are arranged in order of creation. Using CWorkbook::SetActiveSheet can be set the active sheet (by default the first sheet).
    - CWorkbook::m_styleList was moved to private. Now must be used CWorkbook::AddStyle() and CWorkbook::GetFonts().
    - Many internal changes.
    - Added examples to the archive.

     

    Last edit: Alexandr Belyak 2017-05-14

Log in to post a comment.