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

88 lines
1.9 KiB
C++
Raw Normal View History

2018-07-06 16:10:36 +09:00
// main.cpp
2018-07-12 18:15:23 +09:00
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QUrl>
2018-07-13 09:17:28 +09:00
#include <QList>
#include <QVariant>
2018-07-12 18:15:23 +09:00
#include <QDebug>
2018-07-06 16:10:36 +09:00
#include <QGuiApplication>
#include <QQmlApplicationEngine>
2018-07-12 18:15:23 +09:00
#include <QQmlContext>
2018-07-06 16:10:36 +09:00
2018-07-13 09:17:28 +09:00
#include <cstdio>
#include <iostream>
2018-07-06 17:50:49 +09:00
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
2018-07-13 13:56:11 +09:00
#include "XlsxTableModel.h"
2018-07-12 18:15:23 +09:00
2018-07-06 16:10:36 +09:00
int main(int argc, char *argv[])
{
2018-07-12 18:15:23 +09:00
QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
2018-07-06 16:10:36 +09:00
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
2018-07-12 18:15:23 +09:00
QQmlContext* ctxt = engine.rootContext();
2018-07-06 17:50:49 +09:00
2018-07-13 13:56:11 +09:00
QXlsx::Document xlsx( ":/test.xlsx" ); // load xlsx
2018-07-13 09:17:28 +09:00
if (!xlsx.isLoadPackage())
{
qDebug() << "[ERROR] Failed to load xlsx";
return (-1);
}
2018-07-13 13:56:11 +09:00
2018-07-13 09:17:28 +09:00
// A1 B1
// B2 C2
// A3 B3 C3
QList<QString> colTitle;
colTitle.append(QString("A"));
colTitle.append(QString("B"));
colTitle.append(QString("C"));
2018-07-13 13:56:11 +09:00
QList<VLIST> xlsxData;
2018-07-13 09:17:28 +09:00
VLIST vl1;
vl1.append( xlsx.read("A1") );
vl1.append( xlsx.read("B1") );
vl1.append( xlsx.read("C1") );
xlsxData.append( vl1 );
VLIST vl2;
vl2.append( xlsx.read("A2") );
vl2.append( xlsx.read("B2") );
vl2.append( xlsx.read("C2") );
xlsxData.append( vl2 );
VLIST vl3;
vl3.append( xlsx.read("A3") );
vl3.append( xlsx.read("B3") );
vl3.append( xlsx.read("C3") );
xlsxData.append( vl3 );
2018-07-13 13:56:11 +09:00
XlsxTableModel xlsxTableModel(colTitle, xlsxData);
ctxt->setContextProperty( "xlsxModel", &xlsxTableModel ); // set model for tableview
2018-07-12 18:15:23 +09:00
2018-07-13 13:56:11 +09:00
engine.load( QUrl(QStringLiteral("qrc:/main.qml")) ); // load QML
2018-07-12 18:15:23 +09:00
if ( engine.rootObjects().isEmpty() )
{
qDebug() << "Failed to load qml";
return (-1);
}
int ret = app.exec();
return ret;
2018-07-06 16:10:36 +09:00
}