2018-11-17 16:27:43 +09:00
|
|
|
# QXlsx Examples
|
|
|
|
|
2018-11-28 17:28:51 +09:00
|
|
|
## HelloWorld
|
2018-12-27 12:05:23 +09:00
|
|
|
|
2018-11-28 17:28:51 +09:00
|
|
|
- Hello world example
|
|
|
|
|
|
|
|
```cpp
|
2018-12-22 20:50:18 +09:00
|
|
|
// main.cpp
|
|
|
|
|
2018-12-27 12:05:23 +09:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
2018-11-28 17:28:51 +09:00
|
|
|
// [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[])
|
|
|
|
{
|
2018-11-28 17:30:26 +09:00
|
|
|
QCoreApplication app(argc, argv);
|
2018-11-28 17:28:51 +09:00
|
|
|
|
2018-11-28 17:30:26 +09:00
|
|
|
// [1] Writing excel file(*.xlsx)
|
2018-11-28 17:28:51 +09:00
|
|
|
QXlsx::Document xlsxW;
|
|
|
|
xlsxW.write("A1", "Hello Qt!"); // write "Hello Qt!" to cell(A,1). it's shared string.
|
|
|
|
xlsxW.saveAs("Test.xlsx"); // save the document as 'Test.xlsx'
|
|
|
|
|
2018-11-28 17:30:26 +09:00
|
|
|
// [2] Reading excel file(*.xlsx)
|
2018-11-28 17:28:51 +09:00
|
|
|
Document xlsxR("Test.xlsx"); // load excel file
|
|
|
|
if (xlsxR.isLoadPackage())
|
2018-11-28 17:30:26 +09:00
|
|
|
{
|
|
|
|
int row = 1; int col = 1;
|
2018-11-28 17:28:51 +09:00
|
|
|
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
|
|
|
|
}
|
2018-11-28 17:30:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-11-28 17:28:51 +09:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-11-17 16:27:43 +09:00
|
|
|
## TestExcel
|
2018-12-27 12:05:23 +09:00
|
|
|
|
2018-12-22 20:50:18 +09:00
|
|
|
- :zap: Basic examples based on QtXlsx examples
|
2018-11-17 16:27:43 +09:00
|
|
|
|
|
|
|
## HelloAndroid : Android Example
|
2018-12-27 12:05:23 +09:00
|
|
|
|
2018-11-17 16:27:43 +09:00
|
|
|
- See 'HelloAndroid' example using QML and native C++.
|
2018-12-27 12:05:23 +09:00
|
|
|
|
2018-11-17 16:27:43 +09:00
|
|
|
- Qt 5.11.1 / QtCreator 4.6.2 / gcc 4.9 / Android x86 (using Emulator [Android Oreo]) / Android Studio 3.1.3 (Android NDK 17.1)
|
|
|
|
|
|
|
|
![](markdown.data/android.jpg)
|
|
|
|
|
|
|
|
## Copycat : Windows Widget Example
|
|
|
|
- Load xlsx file and display on Qt widgets.
|
2018-12-27 12:05:23 +09:00
|
|
|
- Print xlsx to papaer.
|
|
|
|
- TODO: save xlsx.
|
2018-11-17 16:27:43 +09:00
|
|
|
|
|
|
|
![](markdown.data/copycat.png)
|
|
|
|
|
|
|
|
## WebServer : WebServer Example
|
|
|
|
- Load xlsx file and display on Web.
|
2018-12-20 13:20:31 +09:00
|
|
|
- Connect to `http://127.0.0.1:3001`
|
2018-12-27 12:05:23 +09:00
|
|
|
- C++ 14 is required. Old compilers is not supported.
|
2018-11-17 16:27:43 +09:00
|
|
|
|
|
|
|
![](markdown.data/webserver.png)
|