Skip to content

Commit 78001b3

Browse files
committed
append whattype example
1 parent 8706994 commit 78001b3

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

WhatType/WhatType.pro

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# WhatType.pro
2+
3+
TARGET = WhatType
4+
TEMPLATE = app
5+
6+
QT += core
7+
8+
CONFIG += console
9+
CONFIG -= app_bundle
10+
11+
DEFINES += QT_DEPRECATED_WARNINGS
12+
13+
##########################################################################
14+
# NOTE: You can fix value of QXlsx path of source code.
15+
# QXLSX_PARENTPATH=./
16+
# QXLSX_HEADERPATH=./header/
17+
# QXLSX_SOURCEPATH=./source/
18+
include(../QXlsx/QXlsx.pri)
19+
20+
SOURCES += main.cpp

WhatType/main.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// main.cpp
2+
3+
#include <QtGlobal>
4+
#include <QCoreApplication>
5+
#include <QtCore>
6+
#include <QVariant>
7+
#include <QDir>
8+
#include <QDateTime>
9+
#include <QDate>
10+
#include <QTime>
11+
#include <QDebug>
12+
13+
#include <iostream>
14+
using namespace std;
15+
16+
#include "xlsxdocument.h"
17+
#include "xlsxchartsheet.h"
18+
#include "xlsxcellrange.h"
19+
#include "xlsxchart.h"
20+
#include "xlsxrichstring.h"
21+
#include "xlsxworkbook.h"
22+
using namespace QXlsx;
23+
24+
int whatType(QVariant var);
25+
26+
int main(int argc, char *argv[])
27+
{
28+
QCoreApplication app(argc, argv);
29+
30+
QXlsx::Document xlsxW;
31+
32+
xlsxW.write( 1, 1, QString("Hello Qt!") );
33+
xlsxW.write( 2, 1, double(10.5) );
34+
xlsxW.write( 3, 1, (int)10 );
35+
xlsxW.write( 4, 1, QDateTime::currentDateTimeUtc() );
36+
xlsxW.write( 5, 1, QDate( 2019, 10, 5 ) );
37+
xlsxW.write( 6, 1, QTime( 4, 13, 36 ) );
38+
39+
if ( xlsxW.saveAs("Test.xlsx") ) // save the document as 'Test.xlsx'
40+
{
41+
qDebug() << "[debug] success to write xlsx file";
42+
}
43+
else
44+
{
45+
qDebug() << "[debug][error] failed to write xlsx file";
46+
}
47+
48+
qDebug() << "[debug] current directory is " << QDir::currentPath();
49+
50+
Document xlsxR("Test.xlsx");
51+
if ( ! xlsxR.load() )
52+
{
53+
qDebug() << "[debug][error] failed to load xlsx file.";
54+
}
55+
56+
whatType( xlsxR.cellAt( 1, 1 )->readValue() );
57+
whatType( xlsxR.cellAt( 2, 1 )->readValue() );
58+
whatType( xlsxR.cellAt( 3, 1 )->readValue() );
59+
whatType( xlsxR.cellAt( 4, 1 )->readValue() );
60+
whatType( xlsxR.cellAt( 5, 1 )->readValue() );
61+
whatType( xlsxR.cellAt( 6, 1 )->readValue() );
62+
63+
return 0;
64+
}
65+
66+
int whatType(QVariant var)
67+
{
68+
if ( var.type() == QVariant::Invalid ) { qDebug() << "Invalid"; }
69+
if ( var.type() == QVariant::String ) { qDebug() << "String"; }
70+
if ( var.type() == QVariant::Double ) { qDebug() << "Double"; }
71+
if ( var.type() == QVariant::Int ) { qDebug() << "Int"; }
72+
if ( var.type() == QVariant::DateTime ) { qDebug() << "DateTime"; }
73+
if ( var.type() == QVariant::Date ) { qDebug() << "Date"; }
74+
if ( var.type() == QVariant::Time ) { qDebug() << "Time"; }
75+
76+
return 0;
77+
}

0 commit comments

Comments
 (0)