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

207 lines
5.2 KiB
C++
Raw Normal View History

2017-10-05 20:38:15 +09:00
// readStyle.cpp
2017-10-08 23:15:09 +09:00
#include <QtGlobal>
2017-10-05 21:00:40 +09:00
#include <QtCore>
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
2020-06-05 22:20:08 +09:00
QXLSX_USE_NAMESPACE
2017-10-05 21:00:40 +09:00
int readGoogleSpreadsheet();
int readMSExcel201x();
2017-10-10 16:46:08 +09:00
int readMSExcel201xNumber(QXlsx::Document* pXlsx);
int readLibreOffice();
int readWPSOffice();
2017-10-05 21:00:40 +09:00
2017-10-05 20:38:15 +09:00
int readStyle()
{
2017-10-10 16:46:08 +09:00
int ret;
2020-10-11 15:52:21 +09:00
// ret = readGoogleSpreadsheet();
2017-10-10 16:46:08 +09:00
2020-10-11 15:52:21 +09:00
// ret = readMSExcel201x();
2017-10-08 21:33:00 +09:00
2017-10-05 21:00:40 +09:00
return 0;
}
int readGoogleSpreadsheet()
2017-10-05 21:00:40 +09:00
{
2017-10-06 23:06:34 +09:00
Document xlsx("google-spreadsheet.xlsx"); // google docs
2017-10-08 21:33:00 +09:00
if (!xlsx.isLoadPackage())
{
qDebug() << "[readGoogleSpreadsheet] failed to load package";
return (-1);
}
2017-10-10 16:46:08 +09:00
// current sheet is default sheet. (Sheet1)
2017-10-06 23:06:34 +09:00
for (int row = 1; row < 20; ++row)
2017-10-05 21:00:40 +09:00
{
2017-10-08 23:15:09 +09:00
Cell* cell = xlsx.cellAt(row, 1);
2017-10-10 16:46:08 +09:00
if ( cell == NULL )
2017-10-08 23:15:09 +09:00
continue;
QVariant var = cell->readValue();
qint32 styleNo = cell->styleNumber();
2017-10-10 16:46:08 +09:00
Format fmt = cell->format();
QString strFormat;
if (fmt.hasNumFmtData())
{
QString strNumFormat = fmt.numberFormat();
if ( ! strNumFormat.isEmpty() )
strFormat = strFormat + QString(" number format : ") + strNumFormat;
}
if (fmt.hasFontData() )
{
Format::FontScript fs = fmt.fontScript();
}
if (fmt.hasFillData())
{
int fillIndex = fmt.fillIndex();
QByteArray ba = fmt.fillKey();
}
if (fmt.hasBorderData())
{
}
if (fmt.hasAlignmentData())
{
}
if (fmt.hasProtectionData())
{
}
2017-10-08 23:15:09 +09:00
if ( styleNo >= 0 )
2017-10-05 21:00:40 +09:00
{
2017-10-10 16:46:08 +09:00
qDebug() << row << " " << var << " , style:" << styleNo << strFormat;
2017-10-05 21:00:40 +09:00
}
2017-10-08 23:15:09 +09:00
else
{
2017-10-10 16:46:08 +09:00
qDebug() << row << " " << var << strFormat;
2017-10-08 23:15:09 +09:00
}
2017-10-10 16:46:08 +09:00
}
/* Deug Output
1 QVariant(double, 1) , style: 1 ""
2 QVariant(QString, "2") , style: 2 ""
3 QVariant(double, 3) , style: 3 ""
4 QVariant(double, 4) , style: 4 ""
5 QVariant(double, 5) , style: 5 ""
6 QVariant(double, 6) , style: 6 " number format : _([$\-412]* #,##0.00_);_([$\-412]* \\(#,##0.00\\);_([$\-412]* \"-\"??_);_(@_)"
7 QVariant(double, 7) , style: 7 " number format : #,##0.00;(#,##0.00)"
8 QVariant(double, 8) , style: 8 " number format : [$\-412]#,##0.00"
9 QVariant(double, 9) , style: 9 " number format : [$\-412]#,##0"
10 QVariant(QString, "1900. 1. 9") , style: 10 " number format : yyyy. M. d"
11 QVariant(QTime, QTime("00:00:00.000")) , style: 11 " number format : am/pm h:mm:ss"
12 QVariant(QString, "1900. 1. 11 AM 12:00:00") , style: 12 " number format : yyyy. M. d am/pm h:mm:ss"
13 QVariant(QString, "312:0:0") , style: 13 ""
*/
2017-10-08 21:33:00 +09:00
/* Testing fo read google spreadsheet file (made by google docs)
2017-10-10 16:46:08 +09:00
https://github.com/j2doll/QXlsx/blob/master/image/LibreOffice-Google-XLSX.png
1 QVariant(double, 1) OK:it's auto style (1)
2 QVariant(QString, "2") OK:it's shared string. (2) see ./xl/sharedStrings.xml
2017-10-10 16:46:08 +09:00
3 QVariant(double, 3) PENDING:it's number (3.00) (TODO: use style[3] of cell)
2017-10-06 23:06:34 +09:00
4 QVariant(double, 4) PENDING:it's percentage (400.00%) (TODO: use style[4] of cell)
5 QVariant(double, 5) PENDING:it's exponentiation (5.00E+00) (TODO: use style[5] of cell)
6 QVariant(double, 6) PENDING:it's accounting#1 ($ 6.00) (TODO: use style[6] of cell)
7 QVariant(double, 7) PENDING:it's accounting#2 (7.00) (TODO: use style[7] of cell)
8 QVariant(double, 8) PENDING:it's currency ($8.00) (TODO: use style[8] of cell)
9 QVariant(double, 9) PENDING:it's currency(rounds) ($9) (TODO: use style[9] of cell)
10 QVariant(QString, "1900. 1. 9") OK:it's shared string. see /xl/sharedStrings.xml
11 QVariant(QDateTime, QDateTime(1900-01-11 00:00:00.000 KOREA KST Qt::TimeSpec(LocalTime))) PENDING:it means '1900Y.1M.11D.00H-00m-00s'. but, style[11] uses 'AM/PM HH:mm:ss' format. (TODO: use style[11] of cell)
12 QVariant(QString, "1900. 1. 11 AM 12:00:00") OK:it's shared string. see /xl/sharedStrings.xml
13 QVariant(QDateTime, QDateTime(1900-01-13 00:00:00.000 KOREA KST Qt::TimeSpec(LocalTime))) NOK:it's period (312H:00m:00s). [it's date. but, 13 days means 312 hours!!]
2017-10-05 21:00:40 +09:00
*/
2017-10-06 23:06:34 +09:00
2017-10-05 21:00:40 +09:00
return 0;
}
int readLibreOffice()
{
// WAIT...
return 0;
}
int readMSExcel201x()
{
2017-10-10 16:46:08 +09:00
Document xlsx("ms-number.xlsx"); // ms office online
if (!xlsx.isLoadPackage())
{
qDebug() << "[ms-number] failed to load package";
return (-1);
}
return readMSExcel201xNumber(&xlsx);
}
int readMSExcel201xNumber(QXlsx::Document* pXlsx)
{
if (NULL == pXlsx)
return (-1);
for (int row = 1; row < 10; ++row)
{
Cell* cell = pXlsx->cellAt(row, 1);
if (cell == NULL)
continue;
QVariant var = cell->readValue();
qint32 styleNo = cell->styleNumber();
Format fmt = cell->format();
QString strFomrat;
if (fmt.hasNumFmtData())
{
QString strNumFormat = fmt.numberFormat();
strFomrat = strFomrat + QString(" number format :") + strNumFormat;
}
if (styleNo >= 0)
{
qDebug() << row << " " << var << " , style:" << styleNo << strFomrat;
}
else
{
qDebug() << row << " " << var << strFomrat;
}
}
/* Debug output
1 QVariant(double, 1) ""
2 QVariant(double, 2) , style: 1 " number format :0.00_ "
3 QVariant(double, 3000) , style: 2 " number format :#,##0_ "
4 QVariant(double, -4) , style: 3 " number format :0_ ;[Red]\\-0\\ "
cell value that is printed on excel
[1]
[2.00]
[3,000]
[red minus four]
*/
2017-10-08 21:33:00 +09:00
return 0;
}
2017-10-10 16:46:08 +09:00
int readWPSOffice()
{
return 0;
}