diff --git a/DateTime/DateTime.pro b/DateTime/DateTime.pro new file mode 100644 index 0000000..68db0d9 --- /dev/null +++ b/DateTime/DateTime.pro @@ -0,0 +1,38 @@ +# DateTime.pro + +TARGET = IssueTest +TEMPLATE = app + +QT += core +QT += gui + +CONFIG += console +CONFIG -= app_bundle + +# NOTE: You can fix value of QXlsx path of source code. +# QXLSX_PARENTPATH=./ +# QXLSX_HEADERPATH=./header/ +# QXLSX_SOURCEPATH=./source/ +include(../QXlsx/QXlsx.pri) + +########################################################################## +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +########################################################################## +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain +# version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 +# disables all the APIs deprecated before Qt 6.0.0 + +########################################################################## +# source code + +SOURCES += \ +main.cpp \ +test.cpp diff --git a/DateTime/main.cpp b/DateTime/main.cpp new file mode 100644 index 0000000..a302d50 --- /dev/null +++ b/DateTime/main.cpp @@ -0,0 +1,33 @@ +// main.cpp + +#include +#include +#include +#include +#include +#include + +#include +using namespace std; + +#include "xlsxdocument.h" +#include "xlsxchartsheet.h" +#include "xlsxcellrange.h" +#include "xlsxchart.h" +#include "xlsxrichstring.h" +#include "xlsxworkbook.h" +using namespace QXlsx; + +extern int test(QVector params); + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QVector testParams; + int ret = test(testParams); + // qDebug() << "test return value : " << ret; + + return 0; +} + diff --git a/DateTime/test.cpp b/DateTime/test.cpp new file mode 100644 index 0000000..950b249 --- /dev/null +++ b/DateTime/test.cpp @@ -0,0 +1,179 @@ +// test.cpp + +#include +#include +#include +#include +#include +#include +#include + +#include +using namespace std; + +#include "xlsxdocument.h" +#include "xlsxchartsheet.h" +#include "xlsxcellrange.h" +#include "xlsxchart.h" +#include "xlsxrichstring.h" +#include "xlsxworkbook.h" + +int test( QVector params ); +int test1( QVector params ); +int test2( QVector params ); + +int test( QVector params ) +{ + // return test1( params ); + return test2( params ); +} + +int test1( QVector params ) +{ + qDebug() << "[debug] current path : " << QDir::currentPath(); + + using namespace QXlsx; + + Document doc; + + doc.write( "A1", QVariant(QDateTime::currentDateTimeUtc()) ); + doc.write( "A2", QVariant(double(10.5)) ); + doc.write( "A3", QVariant(QDate(2019, 10, 9)) ); + doc.write( "A4", QVariant(QTime(10, 9, 5)) ); + doc.write( "A5", QVariant((int) 40000) ); + + qDebug() << "doc.read()"; + qDebug() << doc.read( 1, 1 ).type() << doc.read( 1, 1 ); + qDebug() << doc.read( 2, 1 ).type() << doc.read( 2, 1 ); + qDebug() << doc.read( 3, 1 ).type() << doc.read( 3, 1 ); + qDebug() << doc.read( 4, 1 ).type() << doc.read( 4, 1 ); + qDebug() << doc.read( 5, 1 ).type() << doc.read( 5, 1 ); + qDebug() << "\n"; + + qDebug() << "doc.cellAt()->value()"; + qDebug() << doc.cellAt( 1, 1 )->value().type() << doc.cellAt( 1, 1 )->value(); + qDebug() << doc.cellAt( 2, 1 )->value().type() << doc.cellAt( 2, 1 )->value(); + qDebug() << doc.cellAt( 3, 1 )->value().type() << doc.cellAt( 3, 1 )->value(); + qDebug() << doc.cellAt( 4, 1 )->value().type() << doc.cellAt( 4, 1 )->value(); + qDebug() << doc.cellAt( 5, 1 )->value().type() << doc.cellAt( 5, 1 )->value(); + + doc.saveAs("datetime.xlsx"); + + return 0; +} + +int test2( QVector params ) +{ + qDebug() << "[debug] current path : " << QDir::currentPath(); + + using namespace QXlsx; + + qDebug() << "\n\ndoc1\n"; + + Document doc; + + doc.write( "A1", QVariant(QDateTime::currentDateTimeUtc()) ); + doc.write( "A2", QVariant(double(10.5)) ); + doc.write( "A3", QVariant(QDate(2019, 10, 9)) ); + doc.write( "A4", QVariant(QTime(10, 9, 5)) ); + doc.write( "A5", QVariant((int) 40000) ); + + qDebug() << "doc.read()"; + qDebug() << doc.read( 1, 1 ).type() << doc.read( 1, 1 ); + qDebug() << doc.read( 2, 1 ).type() << doc.read( 2, 1 ); + qDebug() << doc.read( 3, 1 ).type() << doc.read( 3, 1 ); + qDebug() << doc.read( 4, 1 ).type() << doc.read( 4, 1 ); + qDebug() << doc.read( 5, 1 ).type() << doc.read( 5, 1 ); + qDebug() << "\n"; + + qDebug() << "doc.cellAt()->value()"; + qDebug() << doc.cellAt( 1, 1 )->value().type() << doc.cellAt( 1, 1 )->value(); + qDebug() << doc.cellAt( 2, 1 )->value().type() << doc.cellAt( 2, 1 )->value(); + qDebug() << doc.cellAt( 3, 1 )->value().type() << doc.cellAt( 3, 1 )->value(); + qDebug() << doc.cellAt( 4, 1 )->value().type() << doc.cellAt( 4, 1 )->value(); + qDebug() << doc.cellAt( 5, 1 )->value().type() << doc.cellAt( 5, 1 )->value(); + qDebug() << "\n"; + + doc.saveAs("datetime.xlsx"); + + qDebug() << "\n\ndoc2\n"; + + Document doc2("datetime.xlsx"); + if ( !doc2.load() ) + { + qWarning() << "failed to load datetime.xlsx" ; + return (-1); + } + qDebug() << "\n\n"; + + doc2.write( "A6", QVariant(QDateTime::currentDateTimeUtc()) ); + doc2.write( "A7", QVariant(double(10.5)) ); + doc2.write( "A8", QVariant(QDate(2019, 10, 9)) ); + doc2.write( "A9", QVariant(QTime(10, 9, 5)) ); + doc2.write( "A10", QVariant((int) 40000) ); + + qDebug() << "doc2.read()"; + qDebug() << doc2.read( 1, 1 ).type() << doc2.read( 1, 1 ); + qDebug() << doc2.read( 2, 1 ).type() << doc2.read( 2, 1 ); + qDebug() << doc2.read( 3, 1 ).type() << doc2.read( 3, 1 ); + qDebug() << doc2.read( 4, 1 ).type() << doc2.read( 4, 1 ); + qDebug() << doc2.read( 5, 1 ).type() << doc2.read( 5, 1 ); + qDebug() << doc2.read( 6, 1 ).type() << doc2.read( 6, 1 ); + qDebug() << doc2.read( 7, 1 ).type() << doc2.read( 7, 1 ); + qDebug() << doc2.read( 8, 1 ).type() << doc2.read( 8, 1 ); + qDebug() << doc2.read( 9, 1 ).type() << doc2.read( 9, 1 ); + qDebug() << doc2.read(10, 1 ).type() << doc2.read(10, 1 ); + qDebug() << "\n"; + + qDebug() << "doc2.cellAt()->value()"; + qDebug() << doc2.cellAt( 1, 1 )->value().type() << doc2.cellAt( 1, 1 )->value(); + qDebug() << doc2.cellAt( 2, 1 )->value().type() << doc2.cellAt( 2, 1 )->value(); + qDebug() << doc2.cellAt( 3, 1 )->value().type() << doc2.cellAt( 3, 1 )->value(); + qDebug() << doc2.cellAt( 4, 1 )->value().type() << doc2.cellAt( 4, 1 )->value(); + qDebug() << doc2.cellAt( 5, 1 )->value().type() << doc2.cellAt( 5, 1 )->value(); + qDebug() << doc2.cellAt( 6, 1 )->value().type() << doc2.cellAt( 6, 1 )->value(); + qDebug() << doc2.cellAt( 7, 1 )->value().type() << doc2.cellAt( 7, 1 )->value(); + qDebug() << doc2.cellAt( 8, 1 )->value().type() << doc2.cellAt( 8, 1 )->value(); + qDebug() << doc2.cellAt( 9, 1 )->value().type() << doc2.cellAt( 9, 1 )->value(); + qDebug() << doc2.cellAt(10, 1 )->value().type() << doc2.cellAt(10, 1 )->value(); + doc2.saveAs("datetime2.xlsx"); + + qDebug() << "\n\ndoc3\n"; + + Document doc3("datetime2.xlsx"); + if ( !doc3.load() ) + { + qWarning() << "failed to load datetime2.xlsx" ; + return (-1); + } + qDebug() << "\n\n"; + + qDebug() << "doc3.read()"; + qDebug() << doc3.read( 1, 1 ).type() << doc3.read( 1, 1 ); + qDebug() << doc3.read( 2, 1 ).type() << doc3.read( 2, 1 ); + qDebug() << doc3.read( 3, 1 ).type() << doc3.read( 3, 1 ); + qDebug() << doc3.read( 4, 1 ).type() << doc3.read( 4, 1 ); + qDebug() << doc3.read( 5, 1 ).type() << doc3.read( 5, 1 ); + qDebug() << doc3.read( 6, 1 ).type() << doc3.read( 6, 1 ); + qDebug() << doc3.read( 7, 1 ).type() << doc3.read( 7, 1 ); + qDebug() << doc3.read( 8, 1 ).type() << doc3.read( 8, 1 ); + qDebug() << doc3.read( 9, 1 ).type() << doc3.read( 9, 1 ); + qDebug() << doc3.read(10, 1 ).type() << doc3.read(10, 1 ); + qDebug() << "\n"; + + qDebug() << "doc3.cellAt()->value()"; + qDebug() << doc3.cellAt( 1, 1 )->value().type() << doc3.cellAt( 1, 1 )->value(); + qDebug() << doc3.cellAt( 2, 1 )->value().type() << doc3.cellAt( 2, 1 )->value(); + qDebug() << doc3.cellAt( 3, 1 )->value().type() << doc3.cellAt( 3, 1 )->value(); + qDebug() << doc3.cellAt( 4, 1 )->value().type() << doc3.cellAt( 4, 1 )->value(); + qDebug() << doc3.cellAt( 5, 1 )->value().type() << doc3.cellAt( 5, 1 )->value(); + qDebug() << doc3.cellAt( 6, 1 )->value().type() << doc3.cellAt( 6, 1 )->value(); + qDebug() << doc3.cellAt( 7, 1 )->value().type() << doc3.cellAt( 7, 1 )->value(); + qDebug() << doc3.cellAt( 8, 1 )->value().type() << doc3.cellAt( 8, 1 )->value(); + qDebug() << doc3.cellAt( 9, 1 )->value().type() << doc3.cellAt( 9, 1 )->value(); + qDebug() << doc3.cellAt(10, 1 )->value().type() << doc3.cellAt(10, 1 )->value(); + doc2.saveAs("datetime2.xlsx"); + + return 0; +} +