Skip to content

Use SimpleXlsxWriter in Qt5. SimpleXlsxWriter is C++ library for creating XLSX files for MS Excel 2007 and above.

License

Notifications You must be signed in to change notification settings

QtExcel/QSimpleXlsxWriter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QSimpleXlsxWriter

Introduction

  • Use SimpleXlsxWriter in Qt.
  • SimpleXlsxWriter
    • C++ library for creating XLSX files for MS Excel 2007 and above.
    • Brought to you by: oxod, programmeralex
    • The main feature of this library is that it uses C++ standard file streams. On the one hand it results in almost unnoticeable memory and CPU resources consumption while processing (that may be very useful at saving a large data arrays), but on the other hand it makes unfeasible to edit data that were written. Hence, if using this library the structure of the future report should be known enough.

Hello World (HelloQSimpleXlsxWriter)

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <Xlsx/Workbook.h>

using namespace SimpleXlsx;

int main( int argc, char * argv[] )
{
    ( void )argc; ( void )argv;

    setlocale( LC_ALL, "" );

    time_t CurrentTime = time( NULL );

    CWorkbook book( "Incognito" );

    std::vector<ColumnWidth> ColWidth;
    ColWidth.push_back( ColumnWidth( 0, 3, 20 ) );
    CWorksheet & Sheet = book.AddSheet( "Unicode", ColWidth );

    Style style;
    style.horizAlign = ALIGN_H_CENTER;
    style.font.attributes = FONT_BOLD;
    size_t CenterStyleIndex = book.AddStyle( style );

    Sheet.BeginRow();
    Sheet.AddCell( "Common test of Unicode support", CenterStyleIndex );
    Sheet.MergeCells( CellCoord( 1, 0 ), CellCoord( 1, 3 ) );
    Sheet.EndRow();

    Font TmpFont = book.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.AddContent( TmpFont, "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( L"Русский язык" );
    Sheet.EndRow();

    Sheet.BeginRow();
    Sheet.AddCell( "Chinese language" );
    Sheet.AddCell( L"中文" );
    Sheet.EndRow();

    Sheet.BeginRow();
    Sheet.AddCell( "French language" );
    Sheet.AddCell( L"le français" );
    Sheet.EndRow();

    Sheet.BeginRow();
    Sheet.AddCell( "Arabic language" );
    Sheet.AddCell( L"العَرَبِيَّة‎‎" );
    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.AddStyle( style );

    Sheet.BeginRow();
    Sheet.AddCell( "Money symbol" );
    Sheet.AddCell( 123.45, MoneyStyleIndex );
    Sheet.EndRow();

    style.numFormat.numberStyle = NUMSTYLE_DATETIME;
    size_t DateTimeStyleIndex = book.AddStyle( style );

    Sheet.BeginRow();
    Sheet.AddCell( "Write date/time" );
    Sheet.AddCell( CurrentTime, DateTimeStyleIndex );
    Sheet.EndRow();

    style.numFormat.formatString = "hh:mm:ss";
    size_t CustomDateTimeStyleIndex = book.AddStyle( style );
    Sheet.BeginRow();
    Sheet.AddCell( "Custom date/time" );
    Sheet.AddCell( CurrentTime, CustomDateTimeStyleIndex );
    Sheet.EndRow();

    Sheet.BeginRow();
    Sheet.EndRow();

    Style stPanel;
    stPanel.border.top.style = BORDER_THIN;
    stPanel.border.bottom.color = "FF000000";
    stPanel.fill.patternType = PATTERN_SOLID;
    stPanel.fill.fgColor = "FFCCCCFF";
    size_t PanelStyleIndex = book.AddStyle( stPanel );
    Sheet.BeginRow();
    Sheet.AddCell( "Cells with border", PanelStyleIndex );
    Sheet.AddCell( "", PanelStyleIndex );
    Sheet.AddCell( "", PanelStyleIndex );
    Sheet.AddCell( "", PanelStyleIndex );
    Sheet.EndRow();

    if( book.Save( "Simple.xlsx" ) ) std::cout << "The book has been saved successfully" << std::endl;
    else std::cout << "The book saving has been failed" << std::endl;

    return 0;
}

License and links

  • QSimpleXlsxWriter is under MIT license.
  • SimpleXlsxWriter is under zlib license.
  • zlib is under zlib license.

About

Use SimpleXlsxWriter in Qt5. SimpleXlsxWriter is C++ library for creating XLSX files for MS Excel 2007 and above.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages