1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00
QXlsx/Example.md

117 lines
4.2 KiB
Markdown
Raw Normal View History

2018-11-17 16:27:43 +09:00
# QXlsx Examples
2019-09-11 22:15:30 +09:00
## [HelloWorld](https://github.com/QtExcel/QXlsx/tree/master/HelloWorld)
2018-12-27 12:05:23 +09:00
2019-08-29 17:32:10 +09:00
- Hello world example
```cpp
// 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;
// [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);
2023-01-06 17:00:27 +09:00
int row = 1; int col = 1;
2018-11-28 17:30:26 +09:00
// [1] Writing excel file(*.xlsx)
QXlsx::Document xlsxW;
2023-01-06 17:00:27 +09:00
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'
2018-11-28 17:30:26 +09:00
// [2] Reading excel file(*.xlsx)
2018-12-30 17:37:03 +09:00
Document xlsxR("Test.xlsx");
if (xlsxR.load()) // load excel file
2018-11-28 17:30:26 +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. it is 'Hello Qt!'.
}
2018-11-28 17:30:26 +09:00
}
return 0;
}
```
2019-09-11 22:15:30 +09:00
## [TestExcel](https://github.com/QtExcel/QXlsx/tree/master/TestExcel)
2018-12-27 12:05:23 +09:00
2019-01-02 20:56:00 +09:00
- :zap: Basic examples (based on QtXlsx examples)
2023-01-06 17:00:27 +09:00
- [calendar](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/calendar.cpp)
- [chart](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/chart.cpp)
- [chart sheet](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/chartsheet.cpp)
- [data validation](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/datavalidation.cpp)
- [demo](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/demo.cpp)
- [document property](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/documentproperty.cpp)
- [extract data](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/extractdata.cpp)
- [formula](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/formulas.cpp)
- [hyperlink](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/hyperlinks.cpp)
- [image](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/image.cpp)
- [merge cells](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/mergecells.cpp)
- [number format](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/numberformat.cpp)
- [page margins](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/pageMargins.cpp)
- [read style](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/readStyle.cpp)
- [richtext](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/richtext.cpp)
- [row column](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/rowcolumn.cpp)
- [style](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/style.cpp)
- [worksheet operations](https://github.com/QtExcel/QXlsx/blob/master/TestExcel/worksheetoperations.cpp)
2018-11-17 16:27:43 +09:00
2019-01-03 16:24:37 +09:00
![](markdown.data/testexcel.png)
2019-11-23 23:37:13 +09:00
## [HelloAndroid](https://github.com/QtExcel/QXlsx/tree/master/HelloAndroid)
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
2023-01-06 17:00:27 +09:00
- 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)
2018-11-17 16:27:43 +09:00
![](markdown.data/android.jpg)
2019-11-23 23:37:13 +09:00
## [WebServer](https://github.com/QtExcel/QXlsx/tree/master/WebServer)
2018-11-17 16:27:43 +09:00
- Load xlsx file and display on Web.
2023-01-06 17:00:27 +09:00
- Connect to `http://127.0.0.1:3001`
- C++ 14(17) is required. Old compilers is not supported.
2018-11-17 16:27:43 +09:00
![](markdown.data/webserver.png)
2019-08-02 00:13:11 +09:00
2019-11-23 23:37:13 +09:00
## [ShowConsole](https://github.com/QtExcel/QXlsx/tree/master/ShowConsole)
2019-08-02 00:13:11 +09:00
- Load xlsx file and display in console.
2019-08-02 00:15:33 +09:00
- [Usage] ShowConsole *.xlsx
2023-01-06 17:00:27 +09:00
- C++ 11 is required. Old compilers is not supported.
2019-08-02 00:13:11 +09:00
![](markdown.data/show-console.jpg)
2019-09-19 22:53:15 +09:00
2020-02-07 21:01:34 +09:00
## [ReadColor](https://github.com/QtExcel/QXlsx/tree/master/ReadColor)
- Read cell color
![](markdown.data/read-color.jpg)
## XlsxFactory
2019-09-19 22:53:15 +09:00
- Load xlsx file and display on Qt widgets.
- Moved to personal repository for advanced app.
2023-01-06 17:00:27 +09:00
- https://j2doll.tistory.com/654
- The source code of this program cannot be released because it contains a commercial license.
2019-09-19 22:53:15 +09:00
![](markdown.data/copycat.png)
![](markdown.data/copycat2.jpg)