- Hello world example
// main.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVariant>
#include <QDebug>
#include <iostream>
using namespace std;
// [0] include QXlsx headers
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
int row = 1; int col = 1;
// [1] Writing excel file(*.xlsx)
QXlsx::Document xlsxW;
QVariant writeValue = QString("Hello Qt!");
xlsxW.write(row, col, writeValue); // write "Hello Qt!" to cell(A,1).
xlsxW.saveAs("Test.xlsx"); // save the document as 'Test.xlsx'
// [2] Reading excel file(*.xlsx)
Document xlsxR("Test.xlsx");
if (xlsxR.load()) // load excel file
{
Cell* cell = xlsxR.cellAt(row, col); // get cell pointer.
if ( cell != NULL )
{
QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...)
qDebug() << var; // display value. it is 'Hello Qt!'.
}
}
return 0;
}- ⚡ Basic examples (based on QtXlsx examples)
-
See 'HelloAndroid' example using QML and native C++.
-
Qt 5.11.1 / gcc 4.9 / QtCreator 4.6.2
-
Android x86 (using Emulator <Android Oreo / API 26>)
-
Android Studio 3.1.3 (Android NDK 17.1)
- Load xlsx file and display on Web.
- Connect to
http://127.0.0.1:3001
- Connect to
- C++ 14(17) is required. Old compilers is not supported.
- Load xlsx file and display in console.
- [Usage] ShowConsole *.xlsx
- C++ 11 is required. Old compilers is not supported.
- Read cell color
- Save the
xlsxfile as acsvfile.
QString xlsxFileName = ":/test.xlsx";
QXlsx::Document xlsxDoc(xlsxFileName);
if (!xlsxDoc.isLoadPackage()) {
return 0; // failed to load
}
QString csvFileName = "hello.csv";
if ( xlsxDoc.saveAsCsv(csvFileName) ){
qDebug() << "save as csv file";
}- Load xlsx file and display on Qt widgets.
- Load xlsx file and display on Qt widgets.
- Moved to personal repository for advanced app.
- https://j2doll.tistory.com/654
- The source code of this program cannot be released because it contains a commercial license.
-
LargeDataexample demonstrates how to efficiently generate, write, and read large Excel.xlsxfiles usingQXlsx. -
It showcases:
- Writing a large dataset (hundreds of thousands of rows)
- Optional cell formatting
- Splitting data across multiple sheets
- Time-stamped progress reporting (0.1% increments)
- Verification of selected sample cells after writing
- Command-line configurability (rows, columns, sheet size, etc.)
-
This example is useful for testing performance, benchmarking, and validating QXlsx behavior with big data workloads.
-
Command-Line Usage
- The program accepts several optional parameters:
| Option | Description | Default |
|---|---|---|
--rows <n> -r <n> |
Number of rows to generate | 100000 |
--cols <n> -c <n> |
Number of columns to generate | 10 |
--use-style -s |
Apply simple cell formatting | Disabled |
--sheet-rows <n> -S <n> |
Max rows per sheet (0 = single sheet) | 0 |
- Examples
LargeData --rows 200000 --cols 20
Generate 200,000 rows × 20 columns
LargeData -r 100000 -c 10 --use-style
Apply cell formatting
LargeData -r 200000 -c 10 -S 50000
Split into multiple sheets (50,000 rows per sheet)
LargeData -r 300000 -c 15 -S 60000 --use-style
All options combined







