mirror of
https://github.com/QtExcel/QXlsx.git
synced 2025-01-30 05:02:52 +08:00
append whattype example
This commit is contained in:
parent
8706994b11
commit
78001b33de
20
WhatType/WhatType.pro
Normal file
20
WhatType/WhatType.pro
Normal file
@ -0,0 +1,20 @@
|
||||
# WhatType.pro
|
||||
|
||||
TARGET = WhatType
|
||||
TEMPLATE = app
|
||||
|
||||
QT += core
|
||||
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
##########################################################################
|
||||
# NOTE: You can fix value of QXlsx path of source code.
|
||||
# QXLSX_PARENTPATH=./
|
||||
# QXLSX_HEADERPATH=./header/
|
||||
# QXLSX_SOURCEPATH=./source/
|
||||
include(../QXlsx/QXlsx.pri)
|
||||
|
||||
SOURCES += main.cpp
|
77
WhatType/main.cpp
Normal file
77
WhatType/main.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
// main.cpp
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QCoreApplication>
|
||||
#include <QtCore>
|
||||
#include <QVariant>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QDate>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "xlsxdocument.h"
|
||||
#include "xlsxchartsheet.h"
|
||||
#include "xlsxcellrange.h"
|
||||
#include "xlsxchart.h"
|
||||
#include "xlsxrichstring.h"
|
||||
#include "xlsxworkbook.h"
|
||||
using namespace QXlsx;
|
||||
|
||||
int whatType(QVariant var);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QXlsx::Document xlsxW;
|
||||
|
||||
xlsxW.write( 1, 1, QString("Hello Qt!") );
|
||||
xlsxW.write( 2, 1, double(10.5) );
|
||||
xlsxW.write( 3, 1, (int)10 );
|
||||
xlsxW.write( 4, 1, QDateTime::currentDateTimeUtc() );
|
||||
xlsxW.write( 5, 1, QDate( 2019, 10, 5 ) );
|
||||
xlsxW.write( 6, 1, QTime( 4, 13, 36 ) );
|
||||
|
||||
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();
|
||||
|
||||
Document xlsxR("Test.xlsx");
|
||||
if ( ! xlsxR.load() )
|
||||
{
|
||||
qDebug() << "[debug][error] failed to load xlsx file.";
|
||||
}
|
||||
|
||||
whatType( xlsxR.cellAt( 1, 1 )->readValue() );
|
||||
whatType( xlsxR.cellAt( 2, 1 )->readValue() );
|
||||
whatType( xlsxR.cellAt( 3, 1 )->readValue() );
|
||||
whatType( xlsxR.cellAt( 4, 1 )->readValue() );
|
||||
whatType( xlsxR.cellAt( 5, 1 )->readValue() );
|
||||
whatType( xlsxR.cellAt( 6, 1 )->readValue() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int whatType(QVariant var)
|
||||
{
|
||||
if ( var.type() == QVariant::Invalid ) { qDebug() << "Invalid"; }
|
||||
if ( var.type() == QVariant::String ) { qDebug() << "String"; }
|
||||
if ( var.type() == QVariant::Double ) { qDebug() << "Double"; }
|
||||
if ( var.type() == QVariant::Int ) { qDebug() << "Int"; }
|
||||
if ( var.type() == QVariant::DateTime ) { qDebug() << "DateTime"; }
|
||||
if ( var.type() == QVariant::Date ) { qDebug() << "Date"; }
|
||||
if ( var.type() == QVariant::Time ) { qDebug() << "Time"; }
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user