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

append debugging information for HelloWorld example

This commit is contained in:
Jay Two 2018-12-28 21:10:21 +09:00
parent 313faab5f4
commit 02710b2544

View File

@ -15,6 +15,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QtCore> #include <QtCore>
#include <QVariant> #include <QVariant>
#include <QDir>
#include <QDebug> #include <QDebug>
#include <iostream> #include <iostream>
@ -36,20 +37,40 @@ int main(int argc, char *argv[])
// [1] Writing excel file(*.xlsx) // [1] Writing excel file(*.xlsx)
QXlsx::Document xlsxW; QXlsx::Document xlsxW;
xlsxW.write("A1", "Hello Qt!"); // write "Hello Qt!" to cell(A,1). it's shared string. 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' if (xlsxW.saveAs("Test.xlsx")) // save the document as 'Test.xlsx'
{
qDebug() << "[debug] success to write xlsx file";
}
else
{
qDebug() << "[debug][error] failed to write xlsx file";
}
qDebug() << "[debug] current directory is " << QDir::currentPath();
// [2] Reading excel file(*.xlsx) // [2] Reading excel file(*.xlsx)
Document xlsxR("Test.xlsx"); // load excel file Document xlsxR("Test.xlsx"); // load excel file
if (xlsxR.isLoadPackage()) if (xlsxR.isLoadPackage())
{ {
qDebug() << "[debug] success to load xlsx file.";
int row = 1; int col = 1; int row = 1; int col = 1;
Cell* cell = xlsxR.cellAt(row, col); // get cell pointer. Cell* cell = xlsxR.cellAt(row, col); // get cell pointer.
if ( cell != NULL ) if ( cell != NULL )
{ {
QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...) QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...)
qDebug() << var; // display value qDebug() << var; // display value
} }
else
{
qDebug() << "[debug][error] cell(1,1) is not set.";
}
} }
else
{
qDebug() << "[debug][error] failed to load xlsx file.";
}
return 0; return 0;
} }