diff --git a/experiment_data/analysis_state/sample.xlsx b/experiment_data/analysis_state/sample.xlsx new file mode 100644 index 0000000..866245e Binary files /dev/null and b/experiment_data/analysis_state/sample.xlsx differ diff --git a/src/AnalysTool.pro b/src/AnalysTool.pro index 4a982a9..e9fcc56 100644 --- a/src/AnalysTool.pro +++ b/src/AnalysTool.pro @@ -1,93 +1,97 @@ -QT += core gui serialport printsupport - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++11 - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has 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 it uses 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 - -SOURCES += \ - data/filemanager.cpp \ - data/pointcalculate.cpp \ - global.cpp \ - logger/logger.cpp \ - rightwidget.cpp \ - thirdparty/easylogging/easylogging++.cc \ - ui/analysissettingform.cpp \ - ui/centralwidget.cpp \ - main.cpp \ - mainwindow.cpp \ - serialport/dataparser.cpp \ - serialport/serialport.cpp \ - thirdparty/qcustomplot/qcustomplot.cpp \ - ui/degreeofcrystallinityform.cpp \ - ui/degreeofcureform.cpp \ - ui/eventhandler.cpp \ - ui/experimentsettingform.cpp \ - ui/instrumentcoefficientform.cpp \ - ui/leftwidget.cpp \ - ui/oitautoanalysisparamform.cpp \ - ui/realtimedataform.cpp \ - ui/specificheatcomparisonmethodform.cpp - -HEADERS += \ - data/filemanager.h \ - data/pointcalculate.h \ - defines.h \ - global.h \ - logger/logger.h \ - rightwidget.h \ - thirdparty/easylogging/easylogging++.h \ - ui/analysissettingform.h \ - ui/centralwidget.h \ - mainwindow.h \ - serialport/dataparser.h \ - serialport/protocol.h \ - serialport/serialport.h \ - thirdparty/qcustomplot/qcustomplot.h \ - ui/degreeofcrystallinityform.h \ - ui/degreeofcureform.h \ - ui/eventhandler.h \ - ui/experimentsettingform.h \ - ui/instrumentcoefficientform.h \ - ui/leftwidget.h \ - ui/oitautoanalysisparamform.h \ - ui/realtimedataform.h \ - ui/specificheatcomparisonmethodform.h - -FORMS += \ - mainwindow.ui \ - ui/degreeofcrystallinityform.ui \ - ui/degreeofcureform.ui \ - ui/experimentsettingform.ui \ - ui/instrumentcoefficientform.ui \ - ui/oitautoanalysisparamform.ui \ - ui/realtimedataform.ui \ - ui/specificheatcomparisonmethodform.ui - -INCLUDEPATH += serialport \ -ui \ -logger \ -thirdparty/easylogging \ -thirdparty/qcustomplot \ -data - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -RESOURCES += \ - images.qrc - -DISTFILES += \ - logger/log.conf +QT += core gui serialport printsupport + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has 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 it uses 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 + +include(thirdparty\QtXlsxWriter-0.3.0\src\xlsx\qtxlsx.pri) + +SOURCES += \ + data/filemanager.cpp \ + data/pointcalculate.cpp \ + global.cpp \ + logger/logger.cpp \ + ui/rightwidget.cpp \ + thirdparty/easylogging/easylogging++.cc \ + ui/analysissettingform.cpp \ + ui/centralwidget.cpp \ + main.cpp \ + mainwindow.cpp \ + serialport/dataparser.cpp \ + serialport/serialport.cpp \ + thirdparty/qcustomplot/qcustomplot.cpp \ + ui/degreeofcrystallinityform.cpp \ + ui/degreeofcureform.cpp \ + ui/eventhandler.cpp \ + ui/experimentsettingform.cpp \ + ui/instrumentcoefficientform.cpp \ + ui/leftwidget.cpp \ + ui/oitautoanalysisparamform.cpp \ + ui/realtimedataform.cpp \ + ui/specificheatcomparisonmethodform.cpp \ + data/xlsxhandler.cpp + +HEADERS += \ + global.h \ + data/filemanager.h \ + data/pointcalculate.h \ + defines.h \ + logger/logger.h \ + ui/rightwidget.h \ + thirdparty/easylogging/easylogging++.h \ + ui/analysissettingform.h \ + ui/centralwidget.h \ + mainwindow.h \ + serialport/dataparser.h \ + serialport/protocol.h \ + serialport/serialport.h \ + thirdparty/qcustomplot/qcustomplot.h \ + ui/degreeofcrystallinityform.h \ + ui/degreeofcureform.h \ + ui/eventhandler.h \ + ui/experimentsettingform.h \ + ui/instrumentcoefficientform.h \ + ui/leftwidget.h \ + ui/oitautoanalysisparamform.h \ + ui/realtimedataform.h \ + ui/specificheatcomparisonmethodform.h \ + data/xlsxhandler.h + +FORMS += \ + mainwindow.ui \ + ui/degreeofcrystallinityform.ui \ + ui/degreeofcureform.ui \ + ui/experimentsettingform.ui \ + ui/instrumentcoefficientform.ui \ + ui/oitautoanalysisparamform.ui \ + ui/realtimedataform.ui \ + ui/specificheatcomparisonmethodform.ui + +INCLUDEPATH += serialport \ +ui \ +logger \ +thirdparty/easylogging \ +thirdparty/qcustomplot \ +data + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + images.qrc + +DISTFILES += \ + logger/log.conf diff --git a/src/data/filemanager.cpp b/src/data/filemanager.cpp index 14556df..5d001d4 100644 --- a/src/data/filemanager.cpp +++ b/src/data/filemanager.cpp @@ -7,7 +7,7 @@ namespace FileManager { -FileManager::ExpeInfo _expeInfo; +Global::ExpeInfo _expeInfo; QFile _expeFile; void writeExperimentFile(const CommonData &cd) @@ -68,7 +68,7 @@ void close() } -void readExperimentFile(const QString fileName, QVector &dataVtr) +void readExperimentFile(const QString fileName, QVector &dataVtr) { if(fileName.isEmpty()){ return; @@ -90,7 +90,7 @@ void readExperimentFile(const QString fileName, QVector &dataVtr QString line = in.readLine(); QStringList values = line.split(" "); if (values.size() == 2) { - ExperimentData data; + Global::ExperimentData data; data.sampleTemp = values[0].toFloat(); data.dsc = values[1].toFloat(); // dataVtr.append(data); diff --git a/src/data/filemanager.h b/src/data/filemanager.h index 2e2c430..1d472f3 100644 --- a/src/data/filemanager.h +++ b/src/data/filemanager.h @@ -3,9 +3,11 @@ #include #include -#include +#include +#include #include "protocol.h" +#include "global.h" namespace FileManager{ const QString ExperimentDirPath = QDir::currentPath()+"/../experiment_data"; @@ -13,27 +15,14 @@ const QString SampleDataFloder = ExperimentDirPath + "/sample_data"; const QString BaseLineFolder = ExperimentDirPath + "/base_line"; const QString AnalysisStateFolder = ExperimentDirPath + "/analysis_state"; -struct ExperimentData { - float sampleTemp; - float dsc; -}; - -struct ExpeInfo -{ - QString sampleName; - float sampleWeight; - QString date; - QString userName; -}; - -extern ExpeInfo _expeInfo; +extern Global::ExpeInfo _expeInfo; extern QFile _expeFile; void createExperimentFile(); void writeExperimentFile(const CommonData&); void close(); -void readExperimentFile(const QString fileName,QVector&); +void readExperimentFile(const QString fileName,QVector&); void test(); }; diff --git a/src/data/pointcalculate.cpp b/src/data/pointcalculate.cpp index 01e881d..ff94c92 100644 --- a/src/data/pointcalculate.cpp +++ b/src/data/pointcalculate.cpp @@ -3,11 +3,11 @@ #include "pointcalculate.h" #include "logger.h" -QVectorPointCalculate:: _dataVtr; +QVectorPointCalculate:: _dataVtr; QPointF PointCalculate::_peakPoint; QPointF PointCalculate::_leftSelectedPoint,PointCalculate::_rightSelectedPoint; -void PointCalculate::setExperimentData(const QVector &dataVtr) +void PointCalculate::setExperimentData(const QVector &dataVtr) { _dataVtr = dataVtr; @@ -15,8 +15,8 @@ void PointCalculate::setExperimentData(const QVector PointCalculate::getPeakPointGroup() { QVector pointVtr; - for(FileManager::ExperimentData& ed:_dataVtr) { + for(Global::ExperimentData& ed:_dataVtr) { if(ed.sampleTemp >= _leftSelectedPoint.x() && ed.sampleTemp <= _rightSelectedPoint.x()){ pointVtr.push_back(QPointF(ed.sampleTemp,ed.dsc)); @@ -274,7 +274,7 @@ void PointCalculate::updateStartEndPoint() { //需要在a1和a2之间查询是否有高于a1和a2之间的点,若存在,则重新给a1、a2赋值 - for(FileManager::ExperimentData& ed:_dataVtr){ + for(Global::ExperimentData& ed:_dataVtr){ if(ed.sampleTemp > _leftSelectedPoint.x() && ed.sampleTemp < _peakPoint.x()){ if(ed.dsc > _leftSelectedPoint.y()){ _leftSelectedPoint.setX(ed.sampleTemp); @@ -333,7 +333,7 @@ QPointF PointCalculate::calculateIntersection(const QPointF p1,const QPointF p2, QPair PointCalculate::getCurveInflectionPointTangent(const float x1,const float x2) { std::vector dataVtr; - for(FileManager::ExperimentData& ed:_dataVtr){ + for(Global::ExperimentData& ed:_dataVtr){ if(x1 < ed.sampleTemp && ed.sampleTemp < x2){ dataVtr.push_back(ed.sampleTemp); } @@ -374,7 +374,7 @@ QPointF PointCalculate::getClosestPointByX(const float targetX) QPointF resultPointF; float minDiff = std::numeric_limits::max(); - for(FileManager::ExperimentData &ed:_dataVtr){ + for(Global::ExperimentData &ed:_dataVtr){ float diff = std::abs(ed.sampleTemp - targetX); if (diff < minDiff) { minDiff = diff; @@ -429,8 +429,8 @@ QPair PointCalculate::getStartAndEndPoint() return qMakePair(QPointF(), QPointF()); } - FileManager::ExperimentData startPoint = _dataVtr.at(0); - FileManager::ExperimentData endPoint = _dataVtr.at(_dataVtr.size() - 1); + Global::ExperimentData startPoint = _dataVtr.at(0); + Global::ExperimentData endPoint = _dataVtr.at(_dataVtr.size() - 1); return qMakePair( QPointF(startPoint.sampleTemp,startPoint.dsc), @@ -457,7 +457,7 @@ QPointF PointCalculate::getClosestPointByY(const float left,const float right,co float minValue = std::numeric_limits::infinity(); // 初始化为正无穷 QPointF closestPoint; - for (const FileManager::ExperimentData& ed : _dataVtr) { + for (const Global::ExperimentData& ed : _dataVtr) { if (left < ed.sampleTemp && ed.sampleTemp < right) { float diff = std::abs(ed.dsc - valueY); if (diff < minValue) { diff --git a/src/data/pointcalculate.h b/src/data/pointcalculate.h index 9deb811..d05f3bc 100644 --- a/src/data/pointcalculate.h +++ b/src/data/pointcalculate.h @@ -6,7 +6,7 @@ #include "filemanager.h" namespace PointCalculate{ -void setExperimentData(const QVector&); +void setExperimentData(const QVector&); QPair getStartAndEndPoint(); @@ -51,7 +51,7 @@ QPointF calculateIntersection(const QPointF p1,const QPointF p2, QVector getPeakPointGroup(); std::vector movingAverage(const std::vector& data, int windowSize); -extern QVector _dataVtr; +extern QVector _dataVtr; extern QPointF _peakPoint; extern QPointF _leftSelectedPoint,_rightSelectedPoint; } diff --git a/src/data/xlsxhandler.cpp b/src/data/xlsxhandler.cpp new file mode 100644 index 0000000..c66a778 --- /dev/null +++ b/src/data/xlsxhandler.cpp @@ -0,0 +1,71 @@ +#include "xlsxhandler.h" +#include "global.h" +#include "logger.h" + +void XlsxHandler::test() +{ + QString sourceFilePath = QDir::currentPath() + "/sample.xlsx"; + qDebug()<<"fileName:"<dimension().rowCount(); + int colCount = workSheet->dimension().columnCount(); + qDebug() << "row:" << rowCount << "col:" << colCount; + + logde<<"0:"<cellAt(1, 1)->value().toString().toStdString(); + qDebug()<cellAt(1, 1)->value().toString(); + + + int index = 2; + Global::ExperimentInfo ei; + ei.sampleName = workSheet->cellAt(index++, 2)->value().toString(); + logde<<"sample name:"<cellAt(index++, 2)->value().toString(); + ei.date = workSheet->cellAt(index++, 2)->value().toString(); + ei.operatorName = workSheet->cellAt(index++, 2)->value().toString(); + ei.phaseSize = workSheet->cellAt(index++, 2)->value().toInt(); + + QVector phaseVtr; + for(int i = 0;i < ei.phaseSize;i++){ + Phase phase; + readPhaseData(workSheet,phase); + phaseVtr.push_back(phase); + } + +} + +void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet, Phase &phase) +{ + const int startIndex = 9; +#if 0 + int index = startIndex; + phase.phaseName = workSheet->cellAt(index++, 2)->value().toString(); + phase.phaseWeight = workSheet->cellAt(index++, 2)->value().toString(); +#endif +} diff --git a/src/data/xlsxhandler.h b/src/data/xlsxhandler.h new file mode 100644 index 0000000..069b50c --- /dev/null +++ b/src/data/xlsxhandler.h @@ -0,0 +1,15 @@ +#ifndef XLSXHANDLER_H +#define XLSXHANDLER_H + +#include + +#include "xlsxdocument.h" +#include "protocol.h" + +namespace XlsxHandler { + void test(); + void readFile(const QString filePath); + void readPhaseData(QXlsx::Worksheet*,Phase&); +} + +#endif // XLSX_H diff --git a/src/global.h b/src/global.h index 66f1684..cd80afe 100644 --- a/src/global.h +++ b/src/global.h @@ -1,11 +1,11 @@ -#ifndef GLOBAL_H -#define GLOBAL_H +#ifndef __GLOBAL_H +#define __GLOBAL_H #include #include #include -#include "filemanager.h" +//#include "filemanager.h" class Global:public QObject { @@ -34,7 +34,27 @@ public: DeviceConnectionStatus getDeviceConnectionStatus(){return _deviceConnectStatus;} #endif - QVector>> _curveDataVtr; + struct ExperimentData { + float sampleTemp; + float dsc; + }; + + struct ExpeInfo + { + QString sampleName; + float sampleWeight; + QString date; + QString userName; + }; + struct ExperimentInfo{ + QString sampleName; + QString sampleWeight; + QString date; + QString operatorName; + int phaseSize; + }; + + QVector>> _curveDataVtr; signals: void sigModeModify(const Mode); diff --git a/src/main.cpp b/src/main.cpp index 46d3fc0..c053c4a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,17 +9,24 @@ #include "experimentsettingform.h" #include "filemanager.h" #include "logger.h" +#include "xlsxhandler.h" int main(int argc, char *argv[]) { + QTextCodec *codec = QTextCodec::codecForName("UTF-8"); + QTextCodec::setCodecForLocale(codec); + Logger::instance(); logde<<"main..."; QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 启用高DPI缩放 QApplication a(argc, argv); - MainWindow w; - w.show(); +// MainWindow w; +// w.show(); + + XlsxHandler::test(); + // FileManager::test(); diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/.gitignore b/src/thirdparty/QtXlsxWriter-0.3.0/.gitignore new file mode 100644 index 0000000..838be4c --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/.gitignore @@ -0,0 +1,45 @@ +syntax: glob +*.pro.user* +*.autosave +*.app +*.moc +*.prl +Makefile* +doc/html/ +*.framework/ +*.xcodeproj/ +debug/ +release/ +qtc-gdbmacros/ +*.rej +*.orig +*.obj +*.swp +*.dll +*.exp +*.ilk +*.pdb +*.lib +Thumbs.db +moc_*.cpp +qrc_*.cpp +*.o +*.so.* +*.so +*.pdb +ui_*.h +*~ +.qmake.cache +lib/* +*.orig +*.exe +*.vcproj +*.vcproj.*.user +*_resource.rc +*.sln +*.idb +*.ncb +*.suo + +*.zip +*.xlsx diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/.qmake.conf b/src/thirdparty/QtXlsxWriter-0.3.0/.qmake.conf new file mode 100644 index 0000000..b56c957 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/.qmake.conf @@ -0,0 +1,6 @@ +#Workaround for Issue #60 +CONFIG += git_build + +load(qt_build_config) + +MODULE_VERSION = 0.3.0 diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/README.md b/src/thirdparty/QtXlsxWriter-0.3.0/README.md new file mode 100644 index 0000000..43b321d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/README.md @@ -0,0 +1,135 @@ +Documentation: http://qtxlsx.debao.me + +QtXlsx is a library that can read and write Excel files. It doesn't require Microsoft Excel and can be used in any platform that Qt5 supported. +The library can be used to + +* Generate a new .xlsx file from scratch +* Extract data from an existing .xlsx file +* Edit an existing .xlsx file + +## Getting Started + +> * For linux user, if your Qt is installed through package manager tools such "apt-get", make sure that you have installed the Qt5 develop package *qtbase5-private-dev* + +### Usage(1): Use Xlsx as Qt5's addon module + +#### Building the module + +> **Note**: Perl is needed in this step. + +* Download the source code. + +* Put the source code in any directory you like + +* Go to top directory of the project in a terminal and run + +``` + qmake + make + make install +``` + +The library, the header files, and others will be installed to your system. + +> ```make html_docs``` can be used to generate documentations of the library, and ```make check``` can be used to run unit tests of the library. + +#### Using the module + +* Add following line to your qmake's project file: + +``` + QT += xlsx +``` + +* Then, using Qt Xlsx in your code + +```cpp + #include + int main() + { + QXlsx::Document xlsx; + xlsx.write("A1", "Hello Qt!"); + xlsx.saveAs("Test.xlsx"); + return 0; + } +``` + +### Usage(2): Use source code directly + +The package contains a **qtxlsx.pri** file that allows you to integrate the component into applications that use qmake for the build step. + +* Download the source code. + +* Put the source code in any directory you like. For example, 3rdparty: + +``` + |-- project.pro + |-- .... + |-- 3rdparty\ + | |-- qtxlsx\ + | | +``` + +* Add following line to your qmake project file: + +``` + include(3rdparty/qtxlsx/src/xlsx/qtxlsx.pri) +``` + +> **Note**: If you like, you can copy all files from *src/xlsx* to your application's source path. Then add following line to your project file: + +> ``` + include(qtxlsx.pri) +``` + +> **Note**: If you do not use qmake, you need to define the following macro manually + +> ``` + XLSX_NO_LIB +``` + + +* Then, using Qt Xlsx in your code + +```cpp + #include "xlsxdocument.h" + int main() + { + QXlsx::Document xlsx; + xlsx.write("A1", "Hello Qt!"); + xlsx.saveAs("Test.xlsx"); + return 0; + } +``` + +## References + +* http://www.ecma-international.org/publications/standards/Ecma-376.htm +* http://www.iso.org/iso/catalogue_detail?csnumber=51463 +* http://msdn.microsoft.com/en-us/library/ee908652%28v=office.12%29.aspx +* http://www.datypic.com/sc/ooxml/ + +### General + +* https://github.com/jmcnamara/XlsxWriter +* http://openpyxl.readthedocs.org +* http://officeopenxml.com/anatomyofOOXML-xlsx.php +* http://www.libxl.com +* http://closedxml.codeplex.com/ +* http://epplus.codeplex.com/ +* http://excelpackage.codeplex.com/ +* http://spreadsheetlight.com/ + +### Number formats + +* http://msdn.microsoft.com/en-us/library/ff529356%28v=office.12%29.aspx +* http://www.ozgrid.com/Excel/excel-custom-number-formats.htm +* http://stackoverflow.com/questions/894805/excel-number-format-what-is-409 +* http://office.microsoft.com/en-001/excel-help/create-a-custom-number-format-HP010342372.aspx + +### Formula + +* http://msdn.microsoft.com/en-us/library/ff533995%28v=office.12%29.aspx +* http://msdn.microsoft.com/en-us/library/dd906358%28v=office.12%29.aspx +* http://homepages.ecs.vuw.ac.nz/~elvis/db/Excel.shtml +* http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/examples.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/examples.pro new file mode 100644 index 0000000..13479a4 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/examples.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = xlsx + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/calendar/calendar.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/calendar/calendar.pro new file mode 100644 index 0000000..a986e00 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/calendar/calendar.pro @@ -0,0 +1,9 @@ +TARGET = calendar + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/calendar/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/calendar/main.cpp new file mode 100644 index 0000000..3ad957e --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/calendar/main.cpp @@ -0,0 +1,145 @@ +#include +#include "xlsxdocument.h" +#include "xlsxformat.h" +#include "xlsxcellrange.h" +#include "xlsxworksheet.h" + +QTXLSX_USE_NAMESPACE + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + //Select a proper locale + //QLocale::setDefault(QLocale(QLocale::English)); + + Document xlsx; + QDate today(QDate::currentDate()); + for (int month=1; month<=12; ++month) { + xlsx.addSheet(QLocale().monthName(month)); + xlsx.currentWorksheet()->setGridLinesVisible(false); + + //the header row + Format headerStyle; + headerStyle.setFontSize(48); + headerStyle.setFontColor(Qt::darkBlue); + headerStyle.setHorizontalAlignment(Format::AlignHCenter); + headerStyle.setVerticalAlignment(Format::AlignVCenter); + xlsx.setRowHeight(1, 80); + xlsx.write("A1", QString("%1 %2").arg(QLocale().monthName(month)).arg(today.year())); + xlsx.mergeCells("A1:N1", headerStyle); + + //header with month titles + for (int day=1; day<=7; ++day) { + Format monthStyle; + monthStyle.setFontSize(12); + monthStyle.setFontColor(Qt::white); + monthStyle.setFontBold(true); + monthStyle.setHorizontalAlignment(Format::AlignHCenter); + monthStyle.setVerticalAlignment(Format::AlignVCenter); + monthStyle.setFillPattern(Format::PatternSolid); + monthStyle.setPatternBackgroundColor(Qt::darkBlue); + + xlsx.setColumnWidth(day*2-1, day*2-1, 5); + xlsx.setColumnWidth(day*2, day*2, 13); + xlsx.write(2, day*2-1, QLocale().dayName(day)); + xlsx.mergeCells(CellRange(2, day*2-1, 2, day*2), monthStyle); + } + + QColor borderColor = QColor(Qt::gray); + + Format weekendLeftStyle; + weekendLeftStyle.setFontSize(14); + weekendLeftStyle.setFontBold(true); + weekendLeftStyle.setHorizontalAlignment(Format::AlignLeft); + weekendLeftStyle.setVerticalAlignment(Format::AlignTop); + weekendLeftStyle.setPatternBackgroundColor(QColor("#93CCEA")); + weekendLeftStyle.setLeftBorderStyle(Format::BorderThin); + weekendLeftStyle.setLeftBorderColor(borderColor); + weekendLeftStyle.setBottomBorderStyle(Format::BorderThin); + weekendLeftStyle.setBottomBorderColor(borderColor); + + Format weekendRightStyle; + weekendRightStyle.setHorizontalAlignment(Format::AlignHCenter); + weekendRightStyle.setVerticalAlignment(Format::AlignTop); + weekendRightStyle.setPatternBackgroundColor(QColor("#93CCEA")); + weekendRightStyle.setRightBorderStyle(Format::BorderThin); + weekendRightStyle.setRightBorderColor(borderColor); + weekendRightStyle.setBottomBorderStyle(Format::BorderThin); + weekendRightStyle.setBottomBorderColor(borderColor); + + Format workdayLeftStyle; + workdayLeftStyle.setHorizontalAlignment(Format::AlignLeft); + workdayLeftStyle.setVerticalAlignment(Format::AlignTop); + workdayLeftStyle.setPatternBackgroundColor(Qt::white); + workdayLeftStyle.setLeftBorderStyle(Format::BorderThin); + workdayLeftStyle.setLeftBorderColor(borderColor); + workdayLeftStyle.setBottomBorderStyle(Format::BorderThin); + workdayLeftStyle.setBottomBorderColor(borderColor); + + Format workdayRightStyle; + workdayRightStyle.setHorizontalAlignment(Format::AlignHCenter); + workdayRightStyle.setVerticalAlignment(Format::AlignTop); + workdayRightStyle.setPatternBackgroundColor(Qt::white); + workdayRightStyle.setRightBorderStyle(Format::BorderThin); + workdayRightStyle.setRightBorderColor(borderColor); + workdayRightStyle.setBottomBorderStyle(Format::BorderThin); + workdayRightStyle.setBottomBorderColor(borderColor); + + Format greyLeftStyle; + greyLeftStyle.setPatternBackgroundColor(Qt::lightGray); + greyLeftStyle.setLeftBorderStyle(Format::BorderThin); + greyLeftStyle.setLeftBorderColor(borderColor); + greyLeftStyle.setBottomBorderStyle(Format::BorderThin); + greyLeftStyle.setBottomBorderColor(borderColor); + + Format greyRightStyle; + greyRightStyle.setPatternBackgroundColor(Qt::lightGray); + greyRightStyle.setRightBorderStyle(Format::BorderThin); + greyRightStyle.setRightBorderColor(borderColor); + greyRightStyle.setBottomBorderStyle(Format::BorderThin); + greyRightStyle.setBottomBorderColor(borderColor); + + int rownum = 3; + for (int day=1; day<=31; ++day) { + QDate date(today.year(), month, day); + if (!date.isValid()) + break; + xlsx.setRowHeight(rownum, 100); + int dow = date.dayOfWeek(); + int colnum = dow*2-1; + + if (dow <= 5) { + xlsx.write(rownum, colnum, day, workdayLeftStyle); + xlsx.write(rownum, colnum+1, QVariant(), workdayRightStyle); + } else { + xlsx.write(rownum, colnum, day, weekendLeftStyle); + xlsx.write(rownum, colnum+1, QVariant(), weekendRightStyle); + } + + if (day == 1 && dow != 1) {//First day + for (int i=1; i +#include "xlsxdocument.h" +#include "xlsxcellrange.h" +#include "xlsxchart.h" + +using namespace QXlsx; + +int main() +{ + //![0] + Document xlsx; + for (int i=1; i<10; ++i) { + xlsx.write(i, 1, i*i*i); //A1:A9 + xlsx.write(i, 2, i*i); //B1:B9 + xlsx.write(i, 3, i*i-1); //C1:C9 + } + //![0] + + //![1] + Chart *pieChart = xlsx.insertChart(3, 3, QSize(300, 300)); + pieChart->setChartType(Chart::CT_Pie); + pieChart->addSeries(CellRange("A1:A9")); + pieChart->addSeries(CellRange("B1:B9")); + pieChart->addSeries(CellRange("C1:C9")); + + Chart *pie3DChart = xlsx.insertChart(3, 9, QSize(300, 300)); + pie3DChart->setChartType(Chart::CT_Pie3D); + pie3DChart->addSeries(CellRange("A1:C9")); + + Chart *barChart = xlsx.insertChart(23, 3, QSize(300, 300)); + barChart->setChartType(Chart::CT_Bar); + barChart->addSeries(CellRange("A1:C9")); + + Chart *bar3DChart = xlsx.insertChart(23, 9, QSize(300, 300)); + bar3DChart->setChartType(Chart::CT_Bar3D); + bar3DChart->addSeries(CellRange("A1:C9")); + + Chart *lineChart = xlsx.insertChart(43, 3, QSize(300, 300)); + lineChart->setChartType(Chart::CT_Line); + lineChart->addSeries(CellRange("A1:C9")); + + Chart *line3DChart = xlsx.insertChart(43, 9, QSize(300, 300)); + line3DChart->setChartType(Chart::CT_Line3D); + line3DChart->addSeries(CellRange("A1:C9")); + + Chart *areaChart = xlsx.insertChart(63, 3, QSize(300, 300)); + areaChart->setChartType(Chart::CT_Area); + areaChart->addSeries(CellRange("A1:C9")); + + Chart *area3DChart = xlsx.insertChart(63, 9, QSize(300, 300)); + area3DChart->setChartType(Chart::CT_Area3D); + area3DChart->addSeries(CellRange("A1:C9")); + + Chart *scatterChart = xlsx.insertChart(83, 3, QSize(300, 300)); + scatterChart->setChartType(Chart::CT_Scatter); + //Will generate three lines. + scatterChart->addSeries(CellRange("A1:A9")); + scatterChart->addSeries(CellRange("B1:B9")); + scatterChart->addSeries(CellRange("C1:C9")); + + Chart *scatterChart_2 = xlsx.insertChart(83, 9, QSize(300, 300)); + scatterChart_2->setChartType(Chart::CT_Scatter); + //Will generate two lines. + scatterChart_2->addSeries(CellRange("A1:C9")); + + Chart *doughnutChart = xlsx.insertChart(103, 3, QSize(300, 300)); + doughnutChart->setChartType(Chart::CT_Doughnut); + doughnutChart->addSeries(CellRange("A1:C9")); + //![1] + + //![2] + xlsx.saveAs("Book1.xlsx"); + //![2] + + Document xlsx2("Book1.xlsx"); + xlsx2.saveAs("Book2.xlsx"); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/chartsheet/chartsheet.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/chartsheet/chartsheet.pro new file mode 100644 index 0000000..327b163 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/chartsheet/chartsheet.pro @@ -0,0 +1,9 @@ +TARGET = chartsheet + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/chartsheet/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/chartsheet/main.cpp new file mode 100644 index 0000000..c3e7a38 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/chartsheet/main.cpp @@ -0,0 +1,32 @@ +#include +#include "xlsxdocument.h" +#include "xlsxchartsheet.h" +#include "xlsxcellrange.h" +#include "xlsxchart.h" + +using namespace QXlsx; + +int main() +{ + //![0] + Document xlsx; + for (int i=1; i<10; ++i) + xlsx.write(i, 1, i*i); + //![0] + + //![1] + xlsx.addSheet("Chart1", AbstractSheet::ST_ChartSheet); + Chartsheet *sheet = static_cast(xlsx.currentSheet()); + Chart *barChart = sheet->chart(); + barChart->setChartType(Chart::CT_Bar); + barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1")); + //![1] + + //![2] + xlsx.saveAs("Book1.xlsx"); + //![2] + + Document xlsx2("Book1.xlsx"); + xlsx2.saveAs("Book2.xlsx"); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/conditionalformatting.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/conditionalformatting.pro new file mode 100644 index 0000000..10d2978 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/conditionalformatting.pro @@ -0,0 +1,9 @@ +TARGET = hello + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/doc/src/conditionalformatting.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/doc/src/conditionalformatting.qdoc new file mode 100644 index 0000000..39e2461 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/doc/src/conditionalformatting.qdoc @@ -0,0 +1,10 @@ +/*! + \example conditionalformatting + \title Conditional Formatting Example + \brief This is a conditional formatting example. + \ingroup qtxlsx-examples + + This example demonstrates how to create a new + .xlsx file containin conditional formatting + with Qt Xlsx Library. So lets see how this is achieved. +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/main.cpp new file mode 100644 index 0000000..298238d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/conditionalformatting/main.cpp @@ -0,0 +1,76 @@ +#include +#include "xlsxdocument.h" +#include "xlsxconditionalformatting.h" + +using namespace QXlsx; + +int main() +{ + //![0] + Document xlsx; + Format hFmt; + hFmt.setFontBold(true); + xlsx.write("B1", "(-inf,40)", hFmt); + xlsx.write("C1", "[30,70]", hFmt); + xlsx.write("D1", "startsWith 2", hFmt); + xlsx.write("E1", "dataBar", hFmt); + xlsx.write("F1", "colorScale", hFmt); + + for (int row=3; row<22; ++row) { + for (int col=2; col<22; ++col) + xlsx.write(row, col, qrand() % 100); + } + //![0] + + //![cf1] + ConditionalFormatting cf1; + Format fmt1; + fmt1.setFontColor(Qt::green); + fmt1.setBorderStyle(Format::BorderDashed); + cf1.addHighlightCellsRule(ConditionalFormatting::Highlight_LessThan, "40", fmt1); + cf1.addRange("B3:B21"); + xlsx.addConditionalFormatting(cf1); + //![cf1] + + //![cf2] + ConditionalFormatting cf2; + Format fmt2; + fmt2.setBorderStyle(Format::BorderDotted); + fmt2.setBorderColor(Qt::blue); + cf2.addHighlightCellsRule(ConditionalFormatting::Highlight_Between, "30", "70", fmt2); + cf2.addRange("C3:C21"); + xlsx.addConditionalFormatting(cf2); + //![cf2] + + //![cf3] + ConditionalFormatting cf3; + Format fmt3; + fmt3.setFontStrikeOut(true); + fmt3.setFontBold(true); + cf3.addHighlightCellsRule(ConditionalFormatting::Highlight_BeginsWith, "2", fmt3); + cf3.addRange("D3:D21"); + xlsx.addConditionalFormatting(cf3); + //![cf3] + + //![cf4] + ConditionalFormatting cf4; + cf4.addDataBarRule(Qt::blue); + cf4.addRange("E3:E21"); + xlsx.addConditionalFormatting(cf4); + //![cf4] + + //![cf5] + ConditionalFormatting cf5; + cf5.add2ColorScaleRule(Qt::blue, Qt::red); + cf5.addRange("F3:F21"); + xlsx.addConditionalFormatting(cf5); + //![cf5] + + //![2] + xlsx.saveAs("Book1.xlsx"); + //![2] + + Document xlsx2("Book1.xlsx"); + xlsx2.saveAs("Book2.xlsx"); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/datavalidation/datavalidation.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/datavalidation/datavalidation.pro new file mode 100644 index 0000000..441bc66 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/datavalidation/datavalidation.pro @@ -0,0 +1,9 @@ +TARGET = datavalidation + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/datavalidation/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/datavalidation/main.cpp new file mode 100644 index 0000000..a2ab4f2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/datavalidation/main.cpp @@ -0,0 +1,22 @@ +#include +#include "xlsxdocument.h" +#include "xlsxdatavalidation.h" + +QTXLSX_USE_NAMESPACE + +int main() +{ + Document xlsx; + xlsx.write("A1", "A2 and A3:E5 only accept the number between 33 and 99"); + + //![1] + DataValidation validation(DataValidation::Whole, DataValidation::Between, "33", "99"); + validation.addRange("A2"); + validation.addRange("A3:E5"); + validation.setPromptMessage("Please Input Integer between 33 and 99"); + xlsx.addDataValidation(validation); + //![1] + + xlsx.save(); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/definename/definename.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/definename/definename.pro new file mode 100644 index 0000000..d2ba173 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/definename/definename.pro @@ -0,0 +1,9 @@ +TARGET = definename + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/definename/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/definename/main.cpp new file mode 100644 index 0000000..9491eb2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/definename/main.cpp @@ -0,0 +1,33 @@ +#include +#include "xlsxdocument.h" + +QTXLSX_USE_NAMESPACE + +int main() +{ + //![0] + Document xlsx; + for (int i=1; i<=10; ++i) { + xlsx.write(i, 1, i); + xlsx.write(i, 2, i*i); + xlsx.write(i, 3, i*i*i); + } + //![0] + //![1] + xlsx.defineName("MyCol_1", "=Sheet1!$A$1:$A$10"); + xlsx.defineName("MyCol_2", "=Sheet1!$B$1:$B$10", "This is comments"); + xlsx.defineName("MyCol_3", "=Sheet1!$C$1:$C$10", "", "Sheet1"); + xlsx.defineName("Factor", "=0.5"); + //![1] + //![2] + xlsx.write(11, 1, "=SUM(MyCol_1)"); + xlsx.write(11, 2, "=SUM(MyCol_2)"); + xlsx.write(11, 3, "=SUM(MyCol_3)"); + xlsx.write(12, 1, "=SUM(MyCol_1)*Factor"); + xlsx.write(12, 2, "=SUM(MyCol_2)*Factor"); + xlsx.write(12, 3, "=SUM(MyCol_3)*Factor"); + //![2] + + xlsx.save(); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/demo.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/demo.pro new file mode 100644 index 0000000..10c4270 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/demo.pro @@ -0,0 +1,9 @@ +TARGET = demo + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/doc/images/xlsx_demo.gif b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/doc/images/xlsx_demo.gif new file mode 100644 index 0000000..0af0799 Binary files /dev/null and b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/doc/images/xlsx_demo.gif differ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/doc/src/demo.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/doc/src/demo.qdoc new file mode 100644 index 0000000..dafabc9 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/doc/src/demo.qdoc @@ -0,0 +1,8 @@ +/*! + \example demo + \title Qt Xlsx Demo + \brief This is a demo which is used to show features of the library + \ingroup qtxlsx-examples + + \image xlsx_demo.gif +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/main.cpp new file mode 100644 index 0000000..7d1e854 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/demo/main.cpp @@ -0,0 +1,296 @@ +#include +#include "xlsxdocument.h" +#include "xlsxformat.h" +#include "xlsxcellrange.h" +#include "xlsxworksheet.h" + +QTXLSX_USE_NAMESPACE + +void writeHorizontalAlignCell(Document &xlsx, const QString &cell, const QString &text, Format::HorizontalAlignment align) +{ + Format format; + format.setHorizontalAlignment(align); + format.setBorderStyle(Format::BorderThin); + xlsx.write(cell, text, format); +} + +void writeVerticalAlignCell(Document &xlsx, const QString &range, const QString &text, Format::VerticalAlignment align) +{ + Format format; + format.setVerticalAlignment(align); + format.setBorderStyle(Format::BorderThin); + CellRange r(range); + xlsx.write(r.firstRow(), r.firstColumn(), text); + xlsx.mergeCells(r, format); +} + +void writeBorderStyleCell(Document &xlsx, const QString &cell, const QString &text, Format::BorderStyle bs) +{ + Format format; + format.setBorderStyle(bs); + xlsx.write(cell, text, format); +} + +void writeSolidFillCell(Document &xlsx, const QString &cell, const QColor &color) +{ + Format format; + format.setPatternBackgroundColor(color); + xlsx.write(cell, QVariant(), format); +} + +void writePatternFillCell(Document &xlsx, const QString &cell, Format::FillPattern pattern, const QColor &color) +{ + Format format; + format.setPatternForegroundColor(color); + format.setFillPattern(pattern); + xlsx.write(cell, QVariant(), format); +} + +void writeBorderAndFontColorCell(Document &xlsx, const QString &cell, const QString &text, const QColor &color) +{ + Format format; + format.setBorderStyle(Format::BorderThin); + format.setBorderColor(color); + format.setFontColor(color); + xlsx.write(cell, text, format); +} + +void writeFontNameCell(Document &xlsx, const QString &cell, const QString &text) +{ + Format format; + format.setFontName(text); + format.setFontSize(16); + xlsx.write(cell, text, format); +} + +void writeFontSizeCell(Document &xlsx, const QString &cell, int size) +{ + Format format; + format.setFontSize(size); + xlsx.write(cell, "Qt Xlsx", format); +} + +void writeInternalNumFormatsCell(Document &xlsx, int row, double value, int numFmt) +{ + Format format; + format.setNumberFormatIndex(numFmt); + xlsx.write(row, 1, value); + xlsx.write(row, 2, QString("Builtin NumFmt %1").arg(numFmt)); + xlsx.write(row, 3, value, format); +} + +void writeCustomNumFormatsCell(Document &xlsx, int row, double value, const QString &numFmt) +{ + Format format; + format.setNumberFormat(numFmt); + xlsx.write(row, 1, value); + xlsx.write(row, 2, numFmt); + xlsx.write(row, 3, value, format); +} + +int main() +{ + Document xlsx; + + //--------------------------------------------------------------- + //Create the first sheet (Otherwise, default "Sheet1" will be created) + xlsx.addSheet("Aligns & Borders"); + xlsx.setColumnWidth(2, 20); //Column B + xlsx.setColumnWidth(8, 12); //Column H + xlsx.currentWorksheet()->setGridLinesVisible(false); + + //Alignment + writeHorizontalAlignCell(xlsx, "B3", "AlignLeft", Format::AlignLeft); + writeHorizontalAlignCell(xlsx, "B5", "AlignHCenter", Format::AlignHCenter); + writeHorizontalAlignCell(xlsx, "B7", "AlignRight", Format::AlignRight); + writeVerticalAlignCell(xlsx, "D3:D7", "AlignTop", Format::AlignTop); + writeVerticalAlignCell(xlsx, "F3:F7", "AlignVCenter", Format::AlignVCenter); + writeVerticalAlignCell(xlsx, "H3:H7", "AlignBottom", Format::AlignBottom); + + //Border + writeBorderStyleCell(xlsx, "B13", "BorderMedium", Format::BorderMedium); + writeBorderStyleCell(xlsx, "B15", "BorderDashed", Format::BorderDashed); + writeBorderStyleCell(xlsx, "B17", "BorderDotted", Format::BorderDotted); + writeBorderStyleCell(xlsx, "B19", "BorderThick", Format::BorderThick); + writeBorderStyleCell(xlsx, "B21", "BorderDouble", Format::BorderDouble); + writeBorderStyleCell(xlsx, "B23", "BorderDashDot", Format::BorderDashDot); + + //Fill + writeSolidFillCell(xlsx, "D13", Qt::red); + writeSolidFillCell(xlsx, "D15", Qt::blue); + writeSolidFillCell(xlsx, "D17", Qt::yellow); + writeSolidFillCell(xlsx, "D19", Qt::magenta); + writeSolidFillCell(xlsx, "D21", Qt::green); + writeSolidFillCell(xlsx, "D23", Qt::gray); + writePatternFillCell(xlsx, "F13", Format::PatternMediumGray, Qt::red); + writePatternFillCell(xlsx, "F15", Format::PatternDarkHorizontal, Qt::blue); + writePatternFillCell(xlsx, "F17", Format::PatternDarkVertical, Qt::yellow); + writePatternFillCell(xlsx, "F19", Format::PatternDarkDown, Qt::magenta); + writePatternFillCell(xlsx, "F21", Format::PatternLightVertical, Qt::green); + writePatternFillCell(xlsx, "F23", Format::PatternLightTrellis, Qt::gray); + + writeBorderAndFontColorCell(xlsx, "H13", "Qt::red", Qt::red); + writeBorderAndFontColorCell(xlsx, "H15", "Qt::blue", Qt::blue); + writeBorderAndFontColorCell(xlsx, "H17", "Qt::yellow", Qt::yellow); + writeBorderAndFontColorCell(xlsx, "H19", "Qt::magenta", Qt::magenta); + writeBorderAndFontColorCell(xlsx, "H21", "Qt::green", Qt::green); + writeBorderAndFontColorCell(xlsx, "H23", "Qt::gray", Qt::gray); + + //--------------------------------------------------------------- + //Create the second sheet. + xlsx.addSheet("Fonts"); + + xlsx.write("B3", "Normal"); + Format font_bold; + font_bold.setFontBold(true); + xlsx.write("B4", "Bold", font_bold); + Format font_italic; + font_italic.setFontItalic(true); + xlsx.write("B5", "Italic", font_italic); + Format font_underline; + font_underline.setFontUnderline(Format::FontUnderlineSingle); + xlsx.write("B6", "Underline", font_underline); + Format font_strikeout; + font_strikeout.setFontStrikeOut(true); + xlsx.write("B7", "StrikeOut", font_strikeout); + + writeFontNameCell(xlsx, "D3", "Arial"); + writeFontNameCell(xlsx, "D4", "Arial Black"); + writeFontNameCell(xlsx, "D5", "Comic Sans MS"); + writeFontNameCell(xlsx, "D6", "Courier New"); + writeFontNameCell(xlsx, "D7", "Impact"); + writeFontNameCell(xlsx, "D8", "Times New Roman"); + writeFontNameCell(xlsx, "D9", "Verdana"); + + writeFontSizeCell(xlsx, "G3", 10); + writeFontSizeCell(xlsx, "G4", 12); + writeFontSizeCell(xlsx, "G5", 14); + writeFontSizeCell(xlsx, "G6", 16); + writeFontSizeCell(xlsx, "G7", 18); + writeFontSizeCell(xlsx, "G8", 20); + writeFontSizeCell(xlsx, "G9", 25); + + Format font_vertical; + font_vertical.setRotation(255); + font_vertical.setFontSize(16); + xlsx.write("J3", "vertical", font_vertical); + xlsx.mergeCells("J3:J9"); + + //--------------------------------------------------------------- + //Create the third sheet. + xlsx.addSheet("Formulas"); + xlsx.setColumnWidth(1, 2, 40); + Format rAlign; + rAlign.setHorizontalAlignment(Format::AlignRight); + Format lAlign; + lAlign.setHorizontalAlignment(Format::AlignLeft); + xlsx.write("B3", 40, lAlign); + xlsx.write("B4", 30, lAlign); + xlsx.write("B5", 50, lAlign); + xlsx.write("A7", "SUM(B3:B5)=", rAlign); + xlsx.write("B7", "=SUM(B3:B5)", lAlign); + xlsx.write("A8", "AVERAGE(B3:B5)=", rAlign); + xlsx.write("B8", "=AVERAGE(B3:B5)", lAlign); + xlsx.write("A9", "MAX(B3:B5)=", rAlign); + xlsx.write("B9", "=MAX(B3:B5)", lAlign); + xlsx.write("A10", "MIN(B3:B5)=", rAlign); + xlsx.write("B10", "=MIN(B3:B5)", lAlign); + xlsx.write("A11", "COUNT(B3:B5)=", rAlign); + xlsx.write("B11", "=COUNT(B3:B5)", lAlign); + + xlsx.write("A13", "IF(B7>100,\"large\",\"small\")=", rAlign); + xlsx.write("B13", "=IF(B7>100,\"large\",\"small\")", lAlign); + + xlsx.write("A15", "SQRT(25)=", rAlign); + xlsx.write("B15", "=SQRT(25)", lAlign); + xlsx.write("A16", "RAND()=", rAlign); + xlsx.write("B16", "=RAND()", lAlign); + xlsx.write("A17", "2*PI()=", rAlign); + xlsx.write("B17", "=2*PI()", lAlign); + + xlsx.write("A19", "UPPER(\"qtxlsx\")=", rAlign); + xlsx.write("B19", "=UPPER(\"qtxlsx\")", lAlign); + xlsx.write("A20", "LEFT(\"ubuntu\",3)=", rAlign); + xlsx.write("B20", "=LEFT(\"ubuntu\",3)", lAlign); + xlsx.write("A21", "LEN(\"Hello Qt!\")=", rAlign); + xlsx.write("B21", "=LEN(\"Hello Qt!\")", lAlign); + + Format dateFormat; + dateFormat.setHorizontalAlignment(Format::AlignLeft); + dateFormat.setNumberFormat("yyyy-mm-dd"); + xlsx.write("A23", "DATE(2013,8,13)=", rAlign); + xlsx.write("B23", "=DATE(2013,8,13)", dateFormat); + xlsx.write("A24", "DAY(B23)=", rAlign); + xlsx.write("B24", "=DAY(B23)", lAlign); + xlsx.write("A25", "MONTH(B23)=", rAlign); + xlsx.write("B25", "=MONTH(B23)", lAlign); + xlsx.write("A26", "YEAR(B23)=", rAlign); + xlsx.write("B26", "=YEAR(B23)", lAlign); + xlsx.write("A27", "DAYS360(B23,TODAY())=", rAlign); + xlsx.write("B27", "=DAYS360(B23,TODAY())", lAlign); + + xlsx.write("A29", "B3+100*(2-COS(0)))=", rAlign); + xlsx.write("B29", "=B3+100*(2-COS(0))", lAlign); + xlsx.write("A30", "ISNUMBER(B29)=", rAlign); + xlsx.write("B30", "=ISNUMBER(B29)", lAlign); + xlsx.write("A31", "AND(1,0)=", rAlign); + xlsx.write("B31", "=AND(1,0)", lAlign); + + xlsx.write("A33", "HYPERLINK(\"http://qt-project.org\")=", rAlign); + xlsx.write("B33", "=HYPERLINK(\"http://qt-project.org\")", lAlign); + + //--------------------------------------------------------------- + //Create the fourth sheet. + xlsx.addSheet("NumFormats"); + xlsx.setColumnWidth(2, 40); + writeInternalNumFormatsCell(xlsx, 4, 2.5681, 2); + writeInternalNumFormatsCell(xlsx, 5, 2500000, 3); + writeInternalNumFormatsCell(xlsx, 6, -500, 5); + writeInternalNumFormatsCell(xlsx, 7, -0.25, 9); + writeInternalNumFormatsCell(xlsx, 8, 890, 11); + writeInternalNumFormatsCell(xlsx, 9, 0.75, 12); + writeInternalNumFormatsCell(xlsx, 10, 41499, 14); + writeInternalNumFormatsCell(xlsx, 11, 41499, 17); + + writeCustomNumFormatsCell(xlsx, 13, 20.5627, "#.###"); + writeCustomNumFormatsCell(xlsx, 14, 4.8, "#.00"); + writeCustomNumFormatsCell(xlsx, 15, 1.23, "0.00 \"RMB\""); + writeCustomNumFormatsCell(xlsx, 16, 60, "[Red][<=100];[Green][>100]"); + + //--------------------------------------------------------------- + //Create the fifth sheet. + xlsx.addSheet("Merging"); + Format centerAlign; + centerAlign.setHorizontalAlignment(Format::AlignHCenter); + centerAlign.setVerticalAlignment(Format::AlignVCenter); + xlsx.write("B4", "Hello Qt!"); + xlsx.mergeCells("B4:F6", centerAlign); + xlsx.write("B8", 1); + xlsx.mergeCells("B8:C21", centerAlign); + xlsx.write("E8", 2); + xlsx.mergeCells("E8:F21", centerAlign); + + //--------------------------------------------------------------- + //Create the fifth sheet. + xlsx.addSheet("Grouping"); + qsrand(QDateTime::currentMSecsSinceEpoch()); + for (int row=2; row<31; ++row) { + for (int col=1; col<=10; ++col) + xlsx.write(row, col, qrand() % 100); + } + xlsx.groupRows(4, 7); + xlsx.groupRows(11, 26, false); + xlsx.groupRows(15, 17, false); + xlsx.groupRows(20, 22, false); + xlsx.setColumnWidth(1, 10, 10.0); + xlsx.groupColumns(1, 2); + xlsx.groupColumns(5, 8, false); + + xlsx.saveAs("Book1.xlsx"); + + //Make sure that read/write works well. + Document xlsx2("Book1.xlsx"); + xlsx2.saveAs("Book2.xlsx"); + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/doc/images/doc_property.png b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/doc/images/doc_property.png new file mode 100644 index 0000000..bd449c6 Binary files /dev/null and b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/doc/images/doc_property.png differ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/doc/src/documentproperty.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/doc/src/documentproperty.qdoc new file mode 100644 index 0000000..d4f7671 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/doc/src/documentproperty.qdoc @@ -0,0 +1,11 @@ +/*! + \example documentproperty + \title Document Properties Example + \brief This is a simplest xlsx examples. + + \image doc_property.png + + \ingroup qtxlsx-examples + + This example demonstrates how to set the document properties. +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/documentproperty.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/documentproperty.pro new file mode 100644 index 0000000..39c74d5 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/documentproperty.pro @@ -0,0 +1,10 @@ +TARGET = ducumentproperty + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/main.cpp new file mode 100644 index 0000000..1cb3f89 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/documentproperty/main.cpp @@ -0,0 +1,20 @@ +#include +#include "xlsxdocument.h" + +int main() +{ + QXlsx::Document xlsx; + xlsx.write("A1", "View the properties through:"); + xlsx.write("A2", "Office Button -> Prepare -> Properties option in Excel"); + + xlsx.setDocumentProperty("title", "This is an example spreadsheet"); + xlsx.setDocumentProperty("subject", "With document properties"); + xlsx.setDocumentProperty("creator", "Debao Zhang"); + xlsx.setDocumentProperty("company", "HMICN"); + xlsx.setDocumentProperty("category", "Example spreadsheets"); + xlsx.setDocumentProperty("keywords", "Sample, Example, Properties"); + xlsx.setDocumentProperty("description", "Created with Qt Xlsx"); + + xlsx.saveAs("Test.xlsx"); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/doc/src/extractdata.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/doc/src/extractdata.qdoc new file mode 100644 index 0000000..563cd59 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/doc/src/extractdata.qdoc @@ -0,0 +1,16 @@ +/*! + \example extractdata + \title Extract Data Example + \brief This is a simplest Qt Xlsx example. + \ingroup qtxlsx-examples + + This example demonstrates how to extract data form existing + .xlsx file with Qt Xlsx Library. So lets see how this is achieved. + + This creates a new instance of the all important Document + class which gives you access to the Excel workbook and worksheets. + \snippet extractdata/main.cpp 0 + + Extracts data from current worksheet. + \snippet extractdata/main.cpp 1 +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/extractdata.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/extractdata.pro new file mode 100644 index 0000000..6a4bf4d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/extractdata.pro @@ -0,0 +1,9 @@ +TARGET = extractdata + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/main.cpp new file mode 100644 index 0000000..041aa5d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/extractdata/main.cpp @@ -0,0 +1,41 @@ +#include +#include "xlsxdocument.h" + +int main() +{ + { + //Create a new .xlsx file. + QXlsx::Document xlsx; + xlsx.write("A1", "Hello Qt!"); + xlsx.write("A2", 12345); + xlsx.write("A3", "=44+33"); + xlsx.write("A4", true); + xlsx.write("A5", "http://qt-project.org"); + xlsx.write("A6", QDate(2013, 12, 27)); + xlsx.write("A7", QTime(6, 30)); + xlsx.saveAs("Book1.xlsx"); + } + + //![0] + QXlsx::Document xlsx("Book1.xlsx"); + //![0] + + //![1] + qDebug()<value(); + } + //![2] + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/doc/src/formulas.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/doc/src/formulas.qdoc new file mode 100644 index 0000000..a91850c --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/doc/src/formulas.qdoc @@ -0,0 +1,24 @@ +/*! + \example formulas + \title Formulas Example + \brief This is a simplest Qt Xlsx example. + \ingroup qtxlsx-examples + + This example demonstrates how to create a new + .xlsx file containing formulas + with Qt Xlsx Library. So lets see how this is achieved. + + This creates a new instance of the all important Document + class which gives you access to the Excel workbook and worksheets. + \snippet formulas/main.cpp 0 + + A default worksheet have been created by Document. Let's start + by adding some basic formulas. + \snippet formulas/main.cpp 1 + + Then add one array formula. + \snippet formulas/main.cpp 2 + + Now save the file and all its components. + \snippet formulas/main.cpp 3 +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/formulas.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/formulas.pro new file mode 100644 index 0000000..10d2978 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/formulas.pro @@ -0,0 +1,9 @@ +TARGET = hello + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/main.cpp new file mode 100644 index 0000000..c824af3 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/formulas/main.cpp @@ -0,0 +1,92 @@ +#include +#include "xlsxdocument.h" +#include "xlsxformat.h" +#include "xlsxworksheet.h" +#include "xlsxcellformula.h" + +QTXLSX_USE_NAMESPACE + +int main() +{ + //![0] + Document xlsx; + //![0] + + //![1] + xlsx.setColumnWidth(1, 2, 40); + Format rAlign; + rAlign.setHorizontalAlignment(Format::AlignRight); + Format lAlign; + lAlign.setHorizontalAlignment(Format::AlignLeft); + xlsx.write("B3", 40, lAlign); + xlsx.write("B4", 30, lAlign); + xlsx.write("B5", 50, lAlign); + xlsx.write("A7", "SUM(B3:B5)=", rAlign); + xlsx.write("B7", "=SUM(B3:B5)", lAlign); + xlsx.write("A8", "AVERAGE(B3:B5)=", rAlign); + xlsx.write("B8", "=AVERAGE(B3:B5)", lAlign); + xlsx.write("A9", "MAX(B3:B5)=", rAlign); + xlsx.write("B9", "=MAX(B3:B5)", lAlign); + xlsx.write("A10", "MIN(B3:B5)=", rAlign); + xlsx.write("B10", "=MIN(B3:B5)", lAlign); + xlsx.write("A11", "COUNT(B3:B5)=", rAlign); + xlsx.write("B11", "=COUNT(B3:B5)", lAlign); + + xlsx.write("A13", "IF(B7>100,\"large\",\"small\")=", rAlign); + xlsx.write("B13", "=IF(B7>100,\"large\",\"small\")", lAlign); + + xlsx.write("A15", "SQRT(25)=", rAlign); + xlsx.write("B15", "=SQRT(25)", lAlign); + xlsx.write("A16", "RAND()=", rAlign); + xlsx.write("B16", "=RAND()", lAlign); + xlsx.write("A17", "2*PI()=", rAlign); + xlsx.write("B17", "=2*PI()", lAlign); + + xlsx.write("A19", "UPPER(\"qtxlsx\")=", rAlign); + xlsx.write("B19", "=UPPER(\"qtxlsx\")", lAlign); + xlsx.write("A20", "LEFT(\"ubuntu\",3)=", rAlign); + xlsx.write("B20", "=LEFT(\"ubuntu\",3)", lAlign); + xlsx.write("A21", "LEN(\"Hello Qt!\")=", rAlign); + xlsx.write("B21", "=LEN(\"Hello Qt!\")", lAlign); + //![1] + + //![2] + xlsx.addSheet("ArrayFormula"); + Worksheet *sheet = xlsx.currentWorksheet(); + + for (int row=2; row<20; ++row) { + sheet->write(row, 2, row*2); //B2:B19 + sheet->write(row, 3, row*3); //C2:C19 + } + sheet->writeFormula("D2", CellFormula("B2:B19+C2:C19", "D2:D19", CellFormula::ArrayType)); + sheet->writeFormula("E2", CellFormula("=CONCATENATE(\"The total is \",D2:D19,\" units\")", "E2:E19", CellFormula::ArrayType)); + //![2] + + //![21] + xlsx.addSheet("SharedFormula"); + sheet = xlsx.currentWorksheet(); + + for (int row=2; row<20; ++row) { + sheet->write(row, 2, row*2); //B2:B19 + sheet->write(row, 3, row*3); //C2:C19 + } + sheet->writeFormula("D2", CellFormula("=B2+C2", "D2:D19", CellFormula::SharedType)); + sheet->writeFormula("E2", CellFormula("=CONCATENATE(\"The total is \",D2,\" units\")", "E2:E19", CellFormula::SharedType)); + + //![21] + + //![3] + xlsx.save(); + //![3] + + //Make sure that read/write works well. + Document xlsx2("Book1.xlsx"); + Worksheet *sharedFormulaSheet = dynamic_cast(xlsx2.sheet("SharedFormula")); + for (int row=2; row<20; ++row) { + qDebug()<read(row, 4); + } + + xlsx2.saveAs("Book2.xlsx"); + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/doc/images/hello.png b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/doc/images/hello.png new file mode 100644 index 0000000..294bba5 Binary files /dev/null and b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/doc/images/hello.png differ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/doc/src/hello.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/doc/src/hello.qdoc new file mode 100644 index 0000000..008947b --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/doc/src/hello.qdoc @@ -0,0 +1,22 @@ +/*! + \example hello + \title Hello QtXlsx Example + \brief This is a simplest Qt Xlsx example. + \ingroup qtxlsx-examples + + This example demonstrates how to create a new + .xlsx file containing some basic data and calculations + with Qt Xlsx Library. So lets see how this is achieved. + \image hello.png + + This creates a new instance of the all important Document + class which gives you access to the Excel workbook and worksheets. + \snippet hello/main.cpp 0 + + A default worksheet have been created by Document. Let's start + by adding some basic data. + \snippet hello/main.cpp 1 + + Now save the file and all its components. + \snippet hello/main.cpp 2 +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/hello.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/hello.pro new file mode 100644 index 0000000..10d2978 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/hello.pro @@ -0,0 +1,9 @@ +TARGET = hello + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/main.cpp new file mode 100644 index 0000000..54a5a2d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hello/main.cpp @@ -0,0 +1,25 @@ +#include +#include "xlsxdocument.h" + +int main() +{ + //![0] + QXlsx::Document xlsx; + //![0] + + //![1] + xlsx.write("A1", "Hello Qt!"); + xlsx.write("A2", 12345); + xlsx.write("A3", "=44+33"); + xlsx.write("A4", true); + xlsx.write("A5", "http://qt-project.org"); + xlsx.write("A6", QDate(2013, 12, 27)); + xlsx.write("A7", QTime(6, 30)); + //![1] + + //![2] + xlsx.save(); + //![2] + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hyperlinks/hyperlinks.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hyperlinks/hyperlinks.pro new file mode 100644 index 0000000..c64e480 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hyperlinks/hyperlinks.pro @@ -0,0 +1,9 @@ +TARGET = hyperlinks + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hyperlinks/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hyperlinks/main.cpp new file mode 100644 index 0000000..74333cc --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/hyperlinks/main.cpp @@ -0,0 +1,25 @@ +#include +#include "xlsxdocument.h" + +int main() +{ + //![0] + QXlsx::Document xlsx; + //![0] + + //![1] + xlsx.write("A1", "http://qt-project.org"); + xlsx.write("A2", "http://qt-project.org/wiki#0f68b904e33d9ac04605aecc958bcf52"); + xlsx.write("A3", "mailto:info@qt-project.org"); + xlsx.write("A4", "file:///C:/User/test/abc.txt"); + //![1] + + //![2] + xlsx.save(); + //![2] + + QXlsx::Document xlsx2("Book1.xlsx"); + xlsx2.saveAs("Book2.xlsx"); + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/image/image.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/image/image.pro new file mode 100644 index 0000000..4b708c0 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/image/image.pro @@ -0,0 +1,9 @@ +TARGET = image + +#include(../../../src/xlsx/qtxlsx.pri) +QT += xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/image/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/image/main.cpp new file mode 100644 index 0000000..7dcf9c4 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/image/main.cpp @@ -0,0 +1,19 @@ +#include +#include "xlsxdocument.h" + +int main(int argc, char** argv) +{ + QGuiApplication(argc, argv); + + QXlsx::Document xlsx; + QImage image(40, 30, QImage::Format_RGB32); + image.fill(Qt::green); + for (int i=0; i<10; ++i) + xlsx.insertImage(10*i, 5, image); + xlsx.saveAs("Book1.xlsx"); + + QXlsx::Document xlsx2("Book1.xlsx"); + xlsx2.saveAs("Book2.xlsx"); + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/doc/images/xlsx-mergecells.png b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/doc/images/xlsx-mergecells.png new file mode 100644 index 0000000..fdd266b Binary files /dev/null and b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/doc/images/xlsx-mergecells.png differ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/doc/src/mergecells.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/doc/src/mergecells.qdoc new file mode 100644 index 0000000..3198cc3 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/doc/src/mergecells.qdoc @@ -0,0 +1,19 @@ +/*! + \example mergecells + \title Merge Cells Example + \brief Demonstrates how to merge cells + \ingroup qtxlsx-examples + + This example demonstrates how to generate a + simplest .xlsx file which contians merged cells with + Qt Xlsx Library. + + \image xlsx-mergecells.png + + Create an format which will be applied to the merged cells: + \snippet mergecells/main.cpp 0 + + Merge cells. + \snippet mergecells/main.cpp 1 + +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/main.cpp new file mode 100644 index 0000000..28e5e9d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/main.cpp @@ -0,0 +1,26 @@ +#include "xlsxdocument.h" +#include "xlsxformat.h" + +QTXLSX_USE_NAMESPACE + +int main() +{ + Document xlsx; + //![0] + Format format; + format.setHorizontalAlignment(Format::AlignHCenter); + format.setVerticalAlignment(Format::AlignVCenter); + //![0] + //![1] + xlsx.write("B4", "Hello Qt!"); + xlsx.mergeCells("B4:F6", format); + xlsx.write("B8", 1); + xlsx.mergeCells("B8:C21", format); + xlsx.write("E8", 2); + xlsx.mergeCells("E8:F21", format); + //![1] + xlsx.save(); + + return 0; +} + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/mergecells.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/mergecells.pro new file mode 100644 index 0000000..8ceb295 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/mergecells/mergecells.pro @@ -0,0 +1,9 @@ +TARGET = mergecells + +#include(../../../src/xlsx/qtxlsx.pri) +QT += xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/numberformat/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/numberformat/main.cpp new file mode 100644 index 0000000..1fb4b9a --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/numberformat/main.cpp @@ -0,0 +1,52 @@ +#include +#include "xlsxdocument.h" +#include "xlsxformat.h" + +int main(int argc, char** argv) +{ + QGuiApplication(argc, argv); + + QXlsx::Document xlsx; + xlsx.setColumnWidth(1, 4, 20.0); + + QXlsx::Format header; + header.setFontBold(true); + header.setFontSize(20); + + //Custom number formats + QStringList numFormats; + numFormats<<"Qt #" + <<"yyyy-mmm-dd" + <<"$ #,##0.00" + <<"[red]0.00"; + xlsx.write(1, 1, "Raw data", header); + xlsx.write(1, 2, "Format", header); + xlsx.write(1, 3, "Shown value", header); + for (int i=0; i +#include "xlsxdocument.h" +#include "xlsxrichstring.h" +#include "xlsxworkbook.h" +#include "xlsxformat.h" + +int main() +{ + //![0] + QXlsx::Document xlsx; + //![0] + + //![1] + QXlsx::Format blue; + blue.setFontColor(Qt::blue); + QXlsx::Format red; + red.setFontColor(Qt::red); + red.setFontSize(15); + QXlsx::Format bold; + bold.setFontBold(true); + + QXlsx::RichString rich; + rich.addFragment("Hello ", blue); + rich.addFragment("Qt ", red); + rich.addFragment("Xlsx", bold); + xlsx.write("B2", rich); + + xlsx.workbook()->setHtmlToRichStringEnabled(true); + xlsx.write("B4", "Hello Qt Xlsx"); + + xlsx.write("B6", "Qt Xlsx"); + + //![1] + + //![2] + xlsx.saveAs("Test1.xlsx"); + //![2] + + QXlsx::Document("Test1.xlsx"); + xlsx.saveAs("Test2.xlsx"); + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/richtext/richtext.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/richtext/richtext.pro new file mode 100644 index 0000000..10d2978 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/richtext/richtext.pro @@ -0,0 +1,9 @@ +TARGET = hello + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/rowcolumn/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/rowcolumn/main.cpp new file mode 100644 index 0000000..b485d27 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/rowcolumn/main.cpp @@ -0,0 +1,38 @@ +#include +#include "xlsxdocument.h" +#include "xlsxformat.h" + +int main() +{ + QXlsx::Document xlsx; + xlsx.write(1, 2, "Row:0, Col:2 ==> (C1)"); + + //Set the height of the first row to 50.0(points) + xlsx.setRowHeight(1, 50.0); + + //Set the width of the third column to 40.0(chars) + xlsx.setColumnWidth(3, 3, 40.0); + + //Set style for the row 11th. + QXlsx::Format format1; + format1.setFontBold(true); + format1.setFontColor(QColor(Qt::blue)); + format1.setFontSize(20); + xlsx.write(11, 1, "Hello Row Style"); + xlsx.write(11, 6, "Blue Color"); + xlsx.setRowFormat(11, format1); + xlsx.setRowHeight(11, 41); + + //Set style for the col [9th, 16th) + QXlsx::Format format2; + format2.setFontBold(true); + format2.setFontColor(QColor(Qt::magenta)); + for (int row=12; row<=30; row++) + for (int col=9; col<=15; col++) + xlsx.write(row, col, row+col); + xlsx.setColumnWidth(9, 16, 5.0); + xlsx.setColumnFormat(9, 16, format2); + + xlsx.save(); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/rowcolumn/rowcolumn.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/rowcolumn/rowcolumn.pro new file mode 100644 index 0000000..4b708c0 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/rowcolumn/rowcolumn.pro @@ -0,0 +1,9 @@ +TARGET = image + +#include(../../../src/xlsx/qtxlsx.pri) +QT += xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/doc/src/style.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/doc/src/style.qdoc new file mode 100644 index 0000000..c24bb7b --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/doc/src/style.qdoc @@ -0,0 +1,10 @@ +/*! + \title Qt Xlsx Examples - Style + \example style + \title Xlsx Style Example + \brief This is a simplest xlsx examples. + \ingroup qtxlsx-examples + + This example demonstrates how to generate a + .xlsx file with Qt Xlsx Library. +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/main.cpp new file mode 100644 index 0000000..ae99412 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/main.cpp @@ -0,0 +1,48 @@ +#include +#include "xlsxdocument.h" +#include "xlsxformat.h" + +int main() +{ + QXlsx::Document xlsx; + QXlsx::Format format1; + format1.setFontColor(QColor(Qt::red)); + format1.setFontSize(15); + format1.setHorizontalAlignment(QXlsx::Format::AlignHCenter); + format1.setBorderStyle(QXlsx::Format::BorderDashDotDot); + xlsx.write("A1", "Hello Qt!", format1); + xlsx.write("B3", 12345, format1); + + QXlsx::Format format2; + format2.setFontBold(true); + format2.setFontUnderline(QXlsx::Format::FontUnderlineDouble); + format2.setFillPattern(QXlsx::Format::PatternLightUp); + xlsx.write("C5", "=44+33", format2); + xlsx.write("D7", true, format2); + + QXlsx::Format format3; + format3.setFontBold(true); + format3.setFontColor(QColor(Qt::blue)); + format3.setFontSize(20); + xlsx.write(11, 1, "Hello Row Style"); + xlsx.write(11, 6, "Blue Color"); + xlsx.setRowFormat(11, 41, format3); + + QXlsx::Format format4; + format4.setFontBold(true); + format4.setFontColor(QColor(Qt::magenta)); + for (int row=21; row<=40; row++) + for (int col=9; col<16; col++) + xlsx.write(row, col, row+col); + xlsx.setColumnFormat(9, 16, format4); + + xlsx.write("A5", QDate(2013, 8, 29)); + + QXlsx::Format format6; + format6.setPatternBackgroundColor(QColor(Qt::green)); + xlsx.write("A6", "Background color: green", format6); + + xlsx.saveAs("book1.xlsx"); + + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/style.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/style.pro new file mode 100644 index 0000000..3fbdcd6 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/style/style.pro @@ -0,0 +1,9 @@ +TARGET = style + +#include(../../../src/xlsx/qtxlsx.pri) +QT += xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/doc/src/worksheetoperations.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/doc/src/worksheetoperations.qdoc new file mode 100644 index 0000000..87dab42 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/doc/src/worksheetoperations.qdoc @@ -0,0 +1,8 @@ +/*! + \example worksheetoperations + \title Worksheet Operations Example + \brief Copy, delete, move worksheet + \ingroup qtxlsx-examples + + This example demonstrates how to copy, delete, move worksheet. +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/main.cpp new file mode 100644 index 0000000..d0c23a2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/main.cpp @@ -0,0 +1,53 @@ +#include +#include "xlsxdocument.h" +#include "xlsxabstractsheet.h" + +QTXLSX_USE_NAMESPACE + +int main() +{ + //![Create a xlsx file] + Document xlsx; + + for (int i=1; i<20; ++i) { + for (int j=1; j<15; ++j) + xlsx.write(i, j, QString("R %1 C %2").arg(i).arg(j)); + } + xlsx.addSheet(); + xlsx.write(2, 2, "Hello Qt Xlsx"); + xlsx.addSheet(); + xlsx.write(3, 3, "This will be deleted..."); + + xlsx.addSheet("HiddenSheet"); + xlsx.currentSheet()->setHidden(true); + xlsx.write("A1", "This sheet is hidden."); + + xlsx.addSheet("VeryHiddenSheet"); + xlsx.sheet("VeryHiddenSheet")->setSheetState(AbstractSheet::SS_VeryHidden); + xlsx.write("A1", "This sheet is very hidden."); + + xlsx.save();//Default name is "Book1.xlsx" + //![Create a xlsx file] + + Document xlsx2("Book1.xlsx"); + //![add_copy_move_delete] + xlsx2.renameSheet("Sheet1", "TheFirstSheet"); + + xlsx2.copySheet("TheFirstSheet", "CopyOfTheFirst"); + + xlsx2.selectSheet("CopyOfTheFirst"); + xlsx2.write(25, 2, "On the Copy Sheet"); + + xlsx2.deleteSheet("Sheet3"); + + xlsx2.moveSheet("Sheet2", 0); + //![add_copy_move_delete] + + //![show_hidden_sheets] + xlsx2.sheet("HiddenSheet")->setVisible(true); + xlsx2.sheet("VeryHiddenSheet")->setVisible(true); + //![show_hidden_sheets] + + xlsx2.saveAs("Book2.xlsx"); + return 0; +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/worksheetoperations.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/worksheetoperations.pro new file mode 100644 index 0000000..ce90d1c --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/worksheetoperations/worksheetoperations.pro @@ -0,0 +1,9 @@ +TARGET = worksheetoperations + +#include(../../../src/xlsx/qtxlsx.pri) +QT+=xlsx + +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsx.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsx.pro new file mode 100644 index 0000000..7af77f8 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsx.pro @@ -0,0 +1,23 @@ +TEMPLATE = subdirs +SUBDIRS = hello \ + extractdata \ + style \ + documentproperty \ + image \ + mergecells \ + rowcolumn \ + numberformat \ + datavalidation \ + definename \ + formulas \ + richtext \ + conditionalformatting \ + worksheetoperations \ + hyperlinks \ + chart \ + chartsheet \ + calendar \ + demo + +qtHaveModule(widgets): SUBDIRS += xlsxwidget + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/main.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/main.cpp new file mode 100644 index 0000000..845774a --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/main.cpp @@ -0,0 +1,41 @@ +#include +#include "xlsxdocument.h" +#include "xlsxworksheet.h" +#include "xlsxcellrange.h" +#include "xlsxsheetmodel.h" + +using namespace QXlsx; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + //![0] + QString filePath = QFileDialog::getOpenFileName(0, "Open xlsx file", QString(), "*.xlsx"); + if (filePath.isEmpty()) + return -1; + //![0] + + //![1] + QTabWidget tabWidget; + tabWidget.setWindowTitle(filePath + " - Qt Xlsx Demo"); + tabWidget.setTabPosition(QTabWidget::South); + //![1] + + //![2] + Document xlsx(filePath); + foreach (QString sheetName, xlsx.sheetNames()) { + Worksheet *sheet = dynamic_cast(xlsx.sheet(sheetName)); + if (sheet) { + QTableView *view = new QTableView(&tabWidget); + view->setModel(new SheetModel(sheet, view)); + foreach (CellRange range, sheet->mergedCells()) + view->setSpan(range.firstRow()-1, range.firstColumn()-1, range.rowCount(), range.columnCount()); + tabWidget.addTab(view, sheetName); + } + } + //![2] + + tabWidget.show(); + return app.exec(); +} diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp new file mode 100644 index 0000000..d2142c6 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxsheetmodel.h" +#include "xlsxsheetmodel_p.h" +#include "xlsxworksheet.h" + +#include + +QT_BEGIN_NAMESPACE_XLSX + +SheetModelPrivate::SheetModelPrivate(SheetModel *p) + :q_ptr(p) +{ + +} + +/*! + * \class SheetModel + * + * Helper class for gui applicaiton user + * + * \note SheetModel indices start from 0, while Worksheet + * column/row indices start from 1. + */ + +/*! + * Creates a model object with the given \a sheet and \a parent. + */ +SheetModel::SheetModel(Worksheet *sheet, QObject *parent) + :QAbstractTableModel(parent), d_ptr(new SheetModelPrivate(this)) +{ + d_ptr->sheet = sheet; +} + +/*! + * Destroys the model. + */ +SheetModel::~SheetModel() +{ + delete d_ptr; +} + +int SheetModel::rowCount(const QModelIndex &/*parent*/) const +{ + Q_D(const SheetModel); + return d->sheet->dimension().lastRow(); +} + + +int SheetModel::columnCount(const QModelIndex &/*parent*/) const +{ + Q_D(const SheetModel); + return d->sheet->dimension().lastColumn(); +} + +Qt::ItemFlags SheetModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable; +} + +QVariant SheetModel::data(const QModelIndex &index, int role) const +{ + Q_D(const SheetModel); + + if (!index.isValid()) + return QVariant(); + + Cell *cell = d->sheet->cellAt(index.row()+1, index.column()+1); + if (!cell) + return QVariant(); + QVariant userFriendlyValue = d->sheet->read(index.row()+1, index.column()+1); + + if (role == Qt::DisplayRole) { + if (cell->isDateTime()) + return userFriendlyValue; + return cell->value(); + } else if (role == Qt::EditRole) { + return userFriendlyValue; + } else if (role == Qt::TextAlignmentRole) { + Qt::Alignment align; + switch (cell->format().horizontalAlignment()) { + case Format::AlignLeft: + align |= Qt::AlignLeft; + break; + case Format::AlignRight: + align |= Qt::AlignRight; + break; + case Format::AlignHCenter: + align |= Qt::AlignHCenter; + break; + case Format::AlignHJustify: + align |= Qt::AlignJustify; + break; + default: + break; + } + switch (cell->format().verticalAlignment()) { + case Format::AlignTop: + align |= Qt::AlignTop; + break; + case Format::AlignBottom: + align |= Qt::AlignBottom; + break; + case Format::AlignVCenter: + align |= Qt::AlignVCenter; + break; + default: + break; + } + return QVariant(align); + } else if (role == Qt::FontRole) { + if (cell->format().hasFontData()) + return cell->format().font(); + } else if (role == Qt::ForegroundRole) { + if (cell->format().fontColor().isValid()) + return QBrush(cell->format().fontColor()); + } else if (role == Qt::BackgroundRole) { + if (cell->format().patternBackgroundColor().isValid()) + return QBrush(cell->format().patternBackgroundColor()); + } + + return QVariant(); +} + +/* + * Copy from xlsxutility.cpp, so this example don't depend on the xlsx-private + * This function should be removed once this class moved to the xlsx library. + */ +static QString col_to_name(int col_num) +{ + QString col_str; + + int remainder; + while (col_num) { + remainder = col_num % 26; + if (remainder == 0) + remainder = 26; + col_str.prepend(QChar('A'+remainder-1)); + col_num = (col_num - 1) / 26; + } + + return col_str; +} + +QVariant SheetModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole) { + if (orientation == Qt::Horizontal) + return col_to_name(section + 1); + else + return QString::number(section + 1); + } + return QVariant(); +} + +bool SheetModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + Q_D(const SheetModel); + + if (!index.isValid()) + return false; + + if (role == Qt::EditRole) { + if (d->sheet->write(index.row()+1, index.column()+1, value) == 0) + return true; + } + + return false; +} + +/*! + * Returns the sheet object. + */ +Worksheet *SheetModel::sheet() const +{ + Q_D(const SheetModel); + return d->sheet; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel.h b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel.h new file mode 100644 index 0000000..b500ff3 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_XLSXSHEETMODEL_H +#define QXLSX_XLSXSHEETMODEL_H + +#include "xlsxglobal.h" +#include + +QT_BEGIN_NAMESPACE_XLSX + +class Worksheet; +class SheetModelPrivate; + +class SheetModel : public QAbstractTableModel +{ + Q_OBJECT + Q_DECLARE_PRIVATE(SheetModel) +public: + explicit SheetModel(Worksheet *sheet, QObject *parent = 0); + ~SheetModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + Qt::ItemFlags flags(const QModelIndex & index) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + + Worksheet *sheet() const; +signals: + +public slots: + +private: + SheetModelPrivate * const d_ptr; +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_XLSXSHEETMODEL_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel_p.h new file mode 100644 index 0000000..fe69674 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxsheetmodel_p.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef XLSXSHEETMODEL_P_H +#define XLSXSHEETMODEL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxsheetmodel.h" + +QT_BEGIN_NAMESPACE_XLSX + +class SheetModelPrivate +{ + Q_DECLARE_PUBLIC(SheetModel) +public: + SheetModelPrivate(SheetModel *p); + + Worksheet *sheet; + SheetModel *q_ptr; +}; + +QT_END_NAMESPACE_XLSX + +#endif // XLSXSHEETMODEL_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxwidget.pro b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxwidget.pro new file mode 100644 index 0000000..f303abc --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/examples/xlsx/xlsxwidget/xlsxwidget.pro @@ -0,0 +1,12 @@ +TARGET = xlsxwidget +QT += widgets + +#include(../../../src/xlsx/qtxlsx.pri) +QT+= xlsx + +SOURCES += main.cpp \ + xlsxsheetmodel.cpp + +HEADERS += \ + xlsxsheetmodel.h \ + xlsxsheetmodel_p.h diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/qtxlsx.pro b/src/thirdparty/QtXlsxWriter-0.3.0/qtxlsx.pro new file mode 100644 index 0000000..58c33f2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/qtxlsx.pro @@ -0,0 +1 @@ +load(qt_parts) diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/src.pro b/src/thirdparty/QtXlsxWriter-0.3.0/src/src.pro new file mode 100644 index 0000000..07d244c --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/src.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS = xlsx diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/qtxlsx.qdocconf b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/qtxlsx.qdocconf new file mode 100644 index 0000000..ef11181 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/qtxlsx.qdocconf @@ -0,0 +1,75 @@ +include($QT_INSTALL_DOCS/global/qt-html-templates-offline.qdocconf) +include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) + +project = QtXlsx +description = Qt Xlsx Reference Documentation +url = http://qtxlsx.debao.me +version = $QT_VERSION + +qhp.projects = QtXlsx + +qhp.QtXlsx.file = qtxlsx.qhp +qhp.QtXlsx.namespace = me.debao.qtxlsx.$QT_VERSION_TAG +qhp.QtXlsx.virtualFolder = qtxlsx +qhp.QtXlsx.indexTitle = Qt Xlsx +qhp.QtXlsx.indexRoot = + +qhp.QtXlsx.filterAttributes = qtxlsx $QT_VERSION qtrefdoc +qhp.QtXlsx.customFilters.Qt.name = QtXlsx $QT_VERSION +qhp.QtXlsx.customFilters.Qt.filterAttributes = qtxlsx $QT_VERSION +qhp.QtXlsx.subprojects = overviews classes qmltypes examples +qhp.QtXlsx.subprojects.overviews.title = Overview +qhp.QtXlsx.subprojects.overviews.indexTitle = Qt Xlsx +qhp.QtXlsx.subprojects.overviews.selectors = fake:page,group,module +qhp.QtXlsx.subprojects.classes.title = C++ Classes +qhp.QtXlsx.subprojects.classes.indexTitle = Qt Xlsx C++ Classes +qhp.QtXlsx.subprojects.classes.selectors = class fake:headerfile +qhp.QtXlsx.subprojects.classes.sortPages = true +qhp.QtXlsx.subprojects.examples.title = Examples +qhp.QtXlsx.subprojects.examples.indexTitle = Qt Xlsx Examples +qhp.QtXlsx.subprojects.examples.selectors = fake:example + +tagfile = ../../../doc/qtxlsx/qtxlsx.tags + +headerdirs += .. + +sourcedirs += .. + +exampledirs += ../../../examples/xlsx \ + snippets/ + +# Specify the install path under QT_INSTALL_EXAMPLES +examplesinstallpath = xlsx + +imagedirs += images + +depends += qtcore qtdoc qtgui + +HTML.footer = \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + "\n" \ + "
\n" \ + "
\n" \ + "
\n" \ + "

\n" \ + " © 2013-2014 Debao Zhang. \n" \ + " Documentation contributions included herein are the copyrights of\n" \ + " their respective owners.

\n" \ + "

\n" \ + " The documentation provided herein is licensed under the terms of the\n" \ + " GNU Free Documentation\n" \ + " License version 1.3 as published by the Free Software Foundation.

\n" \ + "

\n" \ + " Documentation sources may be obtained from \n" \ + " github.com/dbzhang800.

\n" \ + "

\n" \ + " Qt and their respective logos are trademarks of Digia Plc \n" \ + " in Finland and/or other countries worldwide. All other trademarks are property\n" \ + " of their respective owners. Privacy Policy

\n" \ + "
\n" \ + "
\n" \ + "
\n" \ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/snippets/doc_src_qtxlsx.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/snippets/doc_src_qtxlsx.cpp new file mode 100644 index 0000000..eab3ac2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/snippets/doc_src_qtxlsx.cpp @@ -0,0 +1,8 @@ + +//! [0] +#include +//! [0] + +//! [1] +#include +//! [1] diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/snippets/doc_src_qtxlsx.pro b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/snippets/doc_src_qtxlsx.pro new file mode 100644 index 0000000..b2789f7 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/snippets/doc_src_qtxlsx.pro @@ -0,0 +1,3 @@ +#! [1] +QT += xlsx +#! [1] diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/examples.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/examples.qdoc new file mode 100644 index 0000000..6defee7 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/examples.qdoc @@ -0,0 +1,8 @@ +/*! + \group qtxlsx-examples + \title Qt Xlsx Examples + \brief Examples for the Qt Xlsx module + \ingroup all-examples + + Qt Xlsx comes with the following examples: +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/qtxlsx-index.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/qtxlsx-index.qdoc new file mode 100644 index 0000000..8ef7b48 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/qtxlsx-index.qdoc @@ -0,0 +1,72 @@ +/**************************************************************************** +** Copyright (c) 2013 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +/*! + \title Qt Xlsx + \page index.html + \brief Qt Xlsx provides functionality for handling .xlsx files. + + The \l{Qt Xlsx C++ Classes}{Qt Xlsx Module} provides a set of classes to read and write Excel files. It doesn't require + Microsoft Excel and can be used in any platform that Qt5 supported. The library can be used to + + \list + \li \l{Hello QtXlsx Example}{Generate a new .xlsx file from scratch} + \li \l{Extract Data Example}{Extract data from an existing .xlsx file} + \li Edit an existing .xlsx file + \endlist + + \image xlsx_demo.gif + + \table + \row + \li Source code: \li \l{https://github.com/dbzhang800/QtXlsxWriter} + \row + \li Issures: \li \l{https://github.com/dbzhang800/QtXlsxWriter/issues} + \row + \li License: \li MIT + \endtable + + \section1 Getting Started + + To include the definitions of the module's classes, using the following directive: + + \code + #include + \endcode + + To link against the module, add this line to your qmake .pro file: + + \code + QT += xlsx + \endcode + + More information can be found in \l{Qt Xlsx Build} page. + + \section1 Related information + \list + \li \l{Qt Xlsx C++ Classes} + \li \l{Qt Xlsx Examples} + \endlist +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/qtxlsx.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/qtxlsx.qdoc new file mode 100644 index 0000000..cdc70f1 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/qtxlsx.qdoc @@ -0,0 +1,36 @@ +/**************************************************************************** +** Copyright (c) 2013 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +/*! + \module QtXlsx + \title Qt Xlsx C++ Classes + \ingroup modules + + \brief The Qt Xlsx module provides functionality for handling .xlsx files. + + .xlsx is a zipped, XML-based file format developed by Microsoft for + representing spreadsheets. +*/ + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/usage.qdoc b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/usage.qdoc new file mode 100644 index 0000000..fabbe9b --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/doc/src/usage.qdoc @@ -0,0 +1,83 @@ +/*! + \page building + \title Qt Xlsx Build + + \note QZipWriter and QZipReader which live in gui-private is used in + this library. For linux user, if your Qt is installed through package + manager tools such "apt-get", make sure that you have installed the Qt5 + develop package *qtbase5-private-dev* ; + if you Qt is built from source by yourself, + or download from qt-project.org directly, nothing need to do. + + \section1 Usage(1): Use Xlsx as Qt5's addon module + + 1. Download the source code from \l {https://github.com/dbzhang800/QtXlsxWriter/archive/master.zip} {github.com}. + + 2. Put the source code in any directory you like. At the toplevel directory run + + \note Perl is needed in this step. + + \code + qmake + make + make install + \endcode + + The library, the header files, and others will be installed to your system. + + 3. Add following line to your qmake's project file: + + \code + QT += xlsx + \endcode + + 4. Then, using Qt Xlsx in your code + + \code + #include "xlsxdocument.h" + int main() + { + QXlsx::Document xlsx; + xlsx.write("A1", "Hello Qt!"); + xlsx.saveAs("Test.xlsx"); + return 0; + } + \endcode + + \section1 Usage(2): Use source code directly + + The package contains a qtxlsx.pri file that allows you to integrate + the component into applications that use qmake for the build step. + + 1. Download the source code from \l {https://github.com/dbzhang800/QtXlsxWriter/archive/master.zip} {github.com} + + 2. Put the source code in any directory you like. For example, 3rdparty: + + \code + |-- project.pro + |-- .... + |-- 3rdparty\ + | |-- qtxlsx\ + | | + \endcode + + 3. Add following line to your qmake project file: + + \code + include(3rdparty/qtxlsx/src/xlsx/qtxlsx.pri) + \endcode + + \note If you like, you can copy all files from *src/xlsx* to your application's source path. Then add following line to your project file: + + \code + include(qtxlsx.pri) + \endcode + + \note If you do not use qmake, you need to define the following macro manually + + \code + XLSX_NO_LIB + \endcode + + 4. Then, using Qt Xlsx in your code +*/ diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/qtxlsx.pri b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/qtxlsx.pri new file mode 100644 index 0000000..a781146 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/qtxlsx.pri @@ -0,0 +1,84 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +QT += core gui gui-private +!build_xlsx_lib:DEFINES += XLSX_NO_LIB + +HEADERS += $$PWD/xlsxdocpropscore_p.h \ + $$PWD/xlsxdocpropsapp_p.h \ + $$PWD/xlsxrelationships_p.h \ + $$PWD/xlsxutility_p.h \ + $$PWD/xlsxsharedstrings_p.h \ + $$PWD/xlsxcontenttypes_p.h \ + $$PWD/xlsxtheme_p.h \ + $$PWD/xlsxformat.h \ + $$PWD/xlsxworkbook.h \ + $$PWD/xlsxstyles_p.h \ + $$PWD/xlsxabstractsheet.h \ + $$PWD/xlsxabstractsheet_p.h \ + $$PWD/xlsxworksheet.h \ + $$PWD/xlsxworksheet_p.h \ + $$PWD/xlsxchartsheet.h \ + $$PWD/xlsxchartsheet_p.h \ + $$PWD/xlsxzipwriter_p.h \ + $$PWD/xlsxworkbook_p.h \ + $$PWD/xlsxformat_p.h \ + $$PWD/xlsxglobal.h \ + $$PWD/xlsxdrawing_p.h \ + $$PWD/xlsxzipreader_p.h \ + $$PWD/xlsxdocument.h \ + $$PWD/xlsxdocument_p.h \ + $$PWD/xlsxcell.h \ + $$PWD/xlsxcell_p.h \ + $$PWD/xlsxdatavalidation.h \ + $$PWD/xlsxdatavalidation_p.h \ + $$PWD/xlsxcellreference.h \ + $$PWD/xlsxcellrange.h \ + $$PWD/xlsxrichstring_p.h \ + $$PWD/xlsxrichstring.h \ + $$PWD/xlsxconditionalformatting.h \ + $$PWD/xlsxconditionalformatting_p.h \ + $$PWD/xlsxcolor_p.h \ + $$PWD/xlsxnumformatparser_p.h \ + $$PWD/xlsxdrawinganchor_p.h \ + $$PWD/xlsxmediafile_p.h \ + $$PWD/xlsxabstractooxmlfile.h \ + $$PWD/xlsxabstractooxmlfile_p.h \ + $$PWD/xlsxchart.h \ + $$PWD/xlsxchart_p.h \ + $$PWD/xlsxsimpleooxmlfile_p.h \ + $$PWD/xlsxcellformula.h \ + $$PWD/xlsxcellformula_p.h + +SOURCES += $$PWD/xlsxdocpropscore.cpp \ + $$PWD/xlsxdocpropsapp.cpp \ + $$PWD/xlsxrelationships.cpp \ + $$PWD/xlsxutility.cpp \ + $$PWD/xlsxsharedstrings.cpp \ + $$PWD/xlsxcontenttypes.cpp \ + $$PWD/xlsxtheme.cpp \ + $$PWD/xlsxformat.cpp \ + $$PWD/xlsxstyles.cpp \ + $$PWD/xlsxworkbook.cpp \ + $$PWD/xlsxabstractsheet.cpp \ + $$PWD/xlsxworksheet.cpp \ + $$PWD/xlsxchartsheet.cpp \ + $$PWD/xlsxzipwriter.cpp \ + $$PWD/xlsxdrawing.cpp \ + $$PWD/xlsxzipreader.cpp \ + $$PWD/xlsxdocument.cpp \ + $$PWD/xlsxcell.cpp \ + $$PWD/xlsxdatavalidation.cpp \ + $$PWD/xlsxcellreference.cpp \ + $$PWD/xlsxcellrange.cpp \ + $$PWD/xlsxrichstring.cpp \ + $$PWD/xlsxconditionalformatting.cpp \ + $$PWD/xlsxcolor.cpp \ + $$PWD/xlsxnumformatparser.cpp \ + $$PWD/xlsxdrawinganchor.cpp \ + $$PWD/xlsxmediafile.cpp \ + $$PWD/xlsxabstractooxmlfile.cpp \ + $$PWD/xlsxchart.cpp \ + $$PWD/xlsxsimpleooxmlfile.cpp \ + $$PWD/xlsxcellformula.cpp + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsx.pro b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsx.pro new file mode 100644 index 0000000..1449014 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsx.pro @@ -0,0 +1,16 @@ +TARGET = QtXlsx + +QMAKE_DOCS = $$PWD/doc/qtxlsx.qdocconf + +load(qt_module) + +CONFIG += build_xlsx_lib +include(qtxlsx.pri) + +#Define this macro if you want to run tests, so more AIPs will get exported. +#DEFINES += XLSX_TEST + +QMAKE_TARGET_COMPANY = "Debao Zhang" +QMAKE_TARGET_COPYRIGHT = "Copyright (C) 2013-2014 Debao Zhang " +QMAKE_TARGET_DESCRIPTION = ".Xlsx file wirter for Qt5" + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile.cpp new file mode 100644 index 0000000..36d15a0 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxabstractooxmlfile.h" +#include "xlsxabstractooxmlfile_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +AbstractOOXmlFilePrivate::AbstractOOXmlFilePrivate(AbstractOOXmlFile *q, AbstractOOXmlFile::CreateFlag flag=AbstractOOXmlFile::F_NewFromScratch) + :relationships(new Relationships), flag(flag), q_ptr(q) +{ + +} + +AbstractOOXmlFilePrivate::~AbstractOOXmlFilePrivate() +{ + +} + +/*! + * \internal + * + * \class AbstractOOXmlFile + * + * Base class of all the ooxml part file. + */ + +AbstractOOXmlFile::AbstractOOXmlFile(CreateFlag flag) + :d_ptr(new AbstractOOXmlFilePrivate(this, flag)) +{ +} + +AbstractOOXmlFile::AbstractOOXmlFile(AbstractOOXmlFilePrivate *d) + :d_ptr(d) +{ + +} + +AbstractOOXmlFile::~AbstractOOXmlFile() +{ + if (d_ptr->relationships) + delete d_ptr->relationships; + delete d_ptr; +} + +QByteArray AbstractOOXmlFile::saveToXmlData() const +{ + QByteArray data; + QBuffer buffer(&data); + buffer.open(QIODevice::WriteOnly); + saveToXmlFile(&buffer); + + return data; +} + +bool AbstractOOXmlFile::loadFromXmlData(const QByteArray &data) +{ + QBuffer buffer; + buffer.setData(data); + buffer.open(QIODevice::ReadOnly); + + return loadFromXmlFile(&buffer); +} + +/*! + * \internal + */ +void AbstractOOXmlFile::setFilePath(const QString path) +{ + Q_D(AbstractOOXmlFile); + d->filePathInPackage = path; +} + +/*! + * \internal + */ +QString AbstractOOXmlFile::filePath() const +{ + Q_D(const AbstractOOXmlFile); + return d->filePathInPackage; +} + + +/*! + * \internal + */ +Relationships *AbstractOOXmlFile::relationships() const +{ + Q_D(const AbstractOOXmlFile); + return d->relationships; +} + + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile.h new file mode 100644 index 0000000..a5a791c --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_XLSXABSTRACTOOXMLFILE_H +#define QXLSX_XLSXABSTRACTOOXMLFILE_H + +#include "xlsxglobal.h" + +class QIODevice; +class QByteArray; + +QT_BEGIN_NAMESPACE_XLSX +class Relationships; +class AbstractOOXmlFilePrivate; + +class Q_XLSX_EXPORT AbstractOOXmlFile +{ + Q_DECLARE_PRIVATE(AbstractOOXmlFile) +public: + enum CreateFlag + { + F_NewFromScratch, + F_LoadFromExists + }; + + virtual ~AbstractOOXmlFile(); + + virtual void saveToXmlFile(QIODevice *device) const = 0; + virtual bool loadFromXmlFile(QIODevice *device) = 0; + + virtual QByteArray saveToXmlData() const; + virtual bool loadFromXmlData(const QByteArray &data); + + Relationships *relationships() const; + + void setFilePath(const QString path); + QString filePath() const; + +protected: + AbstractOOXmlFile(CreateFlag flag); + AbstractOOXmlFile(AbstractOOXmlFilePrivate *d); + + AbstractOOXmlFilePrivate *d_ptr; +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_XLSXABSTRACTOOXMLFILE_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile_p.h new file mode 100644 index 0000000..a1a2e60 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractooxmlfile_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef XLSXOOXMLFILE_P_H +#define XLSXOOXMLFILE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxabstractooxmlfile.h" +#include "xlsxrelationships_p.h" + +#include + +QT_BEGIN_NAMESPACE_XLSX + +class XLSX_AUTOTEST_EXPORT AbstractOOXmlFilePrivate +{ + Q_DECLARE_PUBLIC(AbstractOOXmlFile) + +public: + AbstractOOXmlFilePrivate(AbstractOOXmlFile *q, AbstractOOXmlFile::CreateFlag flag); + virtual ~AbstractOOXmlFilePrivate(); + + QString filePathInPackage;//such as "xl/worksheets/sheet1.xml" + //used when load the .xlsx file + Relationships *relationships; + AbstractOOXmlFile::CreateFlag flag; + AbstractOOXmlFile *q_ptr; +}; + +QT_END_NAMESPACE_XLSX + +#endif // XLSXOOXMLFILE_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet.cpp new file mode 100644 index 0000000..2cf6eee --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxabstractsheet.h" +#include "xlsxabstractsheet_p.h" +#include "xlsxworkbook.h" + +QT_BEGIN_NAMESPACE_XLSX + +AbstractSheetPrivate::AbstractSheetPrivate(AbstractSheet *p, AbstractSheet::CreateFlag flag) + : AbstractOOXmlFilePrivate(p, flag) +{ + type = AbstractSheet::ST_WorkSheet; + sheetState = AbstractSheet::SS_Visible; +} + +AbstractSheetPrivate::~AbstractSheetPrivate() +{ +} + +/*! + \class AbstractSheet + \inmodule QtXlsx + \brief Base class for worksheet, chartsheet, etc. +*/ + +/*! + \enum AbstractSheet::SheetType + + \value ST_WorkSheet + \value ST_ChartSheet + \omitvalue ST_DialogSheet + \omitvalue ST_MacroSheet +*/ + +/*! + \enum AbstractSheet::SheetState + + \value SS_Visible + \value SS_Hidden + \value SS_VeryHidden User cann't make a veryHidden sheet visible in normal way. +*/ + +/*! + \fn AbstractSheet::copy(const QString &distName, int distId) const + + Copies the current sheet to a sheet called \a distName with \a distId. + Returns the new sheet. + */ + +/*! + * \internal + */ +AbstractSheet::AbstractSheet(const QString &name, int id, Workbook *workbook, AbstractSheetPrivate *d) : + AbstractOOXmlFile(d) +{ + d_func()->name = name; + d_func()->id = id; + d_func()->workbook = workbook; +} + + +/*! + * Returns the name of the sheet. + */ +QString AbstractSheet::sheetName() const +{ + Q_D(const AbstractSheet); + return d->name; +} + +/*! + * \internal + */ +void AbstractSheet::setSheetName(const QString &sheetName) +{ + Q_D(AbstractSheet); + d->name = sheetName; +} + +/*! + * Returns the type of the sheet. + */ +AbstractSheet::SheetType AbstractSheet::sheetType() const +{ + Q_D(const AbstractSheet); + return d->type; +} + +/*! + * \internal + */ +void AbstractSheet::setSheetType(SheetType type) +{ + Q_D(AbstractSheet); + d->type = type; +} + +/*! + * Returns the state of the sheet. + * + * \sa isHidden(), isVisible(), setSheetState() + */ +AbstractSheet::SheetState AbstractSheet::sheetState() const +{ + Q_D(const AbstractSheet); + return d->sheetState; +} + +/*! + * Set the state of the sheet to \a state. + */ +void AbstractSheet::setSheetState(SheetState state) +{ + Q_D(AbstractSheet); + d->sheetState = state; +} + +/*! + * Returns true if the sheet is not visible, otherwise false will be returned. + * + * \sa sheetState(), setHidden() + */ +bool AbstractSheet::isHidden() const +{ + Q_D(const AbstractSheet); + return d->sheetState != SS_Visible; +} + +/*! + * Returns true if the sheet is visible. + */ +bool AbstractSheet::isVisible() const +{ + return !isHidden(); +} + +/*! + * Make the sheet hiden or visible based on \a hidden. + */ +void AbstractSheet::setHidden(bool hidden) +{ + Q_D(AbstractSheet); + if (hidden == isHidden()) + return; + + d->sheetState = hidden ? SS_Hidden : SS_Visible; +} + +/*! + * Convenience function, equivalent to setHidden(! \a visible). + */ +void AbstractSheet::setVisible(bool visible) +{ + setHidden(!visible); +} + +/*! + * \internal + */ +int AbstractSheet::sheetId() const +{ + Q_D(const AbstractSheet); + return d->id; +} + +/*! + * \internal + */ +Drawing *AbstractSheet::drawing() const +{ + Q_D(const AbstractSheet); + return d->drawing.data(); +} + +/*! + * Return the workbook + */ +Workbook *AbstractSheet::workbook() const +{ + Q_D(const AbstractSheet); + return d->workbook; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet.h new file mode 100644 index 0000000..7aa416d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXABSTRACTSHEET_H +#define XLSXABSTRACTSHEET_H + +#include "xlsxabstractooxmlfile.h" +#include +#include + +QT_BEGIN_NAMESPACE_XLSX +class Workbook; +class Drawing; +class AbstractSheetPrivate; +class Q_XLSX_EXPORT AbstractSheet : public AbstractOOXmlFile +{ + Q_DECLARE_PRIVATE(AbstractSheet) +public: + enum SheetType { + ST_WorkSheet, + ST_ChartSheet, + ST_DialogSheet, + ST_MacroSheet + }; + + enum SheetState { + SS_Visible, + SS_Hidden, + SS_VeryHidden + }; + + QString sheetName() const; + SheetType sheetType() const; + SheetState sheetState() const; + void setSheetState(SheetState ss); + bool isHidden() const; + bool isVisible() const; + void setHidden(bool hidden); + void setVisible(bool visible); + + Workbook *workbook() const; + +protected: + friend class Workbook; + AbstractSheet(const QString &sheetName, int sheetId, Workbook *book, AbstractSheetPrivate *d); + virtual AbstractSheet *copy(const QString &distName, int distId) const = 0; + void setSheetName(const QString &sheetName); + void setSheetType(SheetType type); + int sheetId() const; + + Drawing *drawing() const; +}; + +QT_END_NAMESPACE_XLSX +#endif // XLSXABSTRACTSHEET_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet_p.h new file mode 100644 index 0000000..7d0f344 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxabstractsheet_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXABSTRACTSHEET_P_H +#define XLSXABSTRACTSHEET_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxglobal.h" +#include "xlsxabstractsheet.h" +#include "xlsxabstractooxmlfile_p.h" + +#include + +namespace QXlsx { + +class XLSX_AUTOTEST_EXPORT AbstractSheetPrivate : public AbstractOOXmlFilePrivate +{ + Q_DECLARE_PUBLIC(AbstractSheet) +public: + AbstractSheetPrivate(AbstractSheet *p, AbstractSheet::CreateFlag flag); + ~AbstractSheetPrivate(); + + Workbook *workbook; + QSharedPointer drawing; + + QString name; + int id; + AbstractSheet::SheetState sheetState; + AbstractSheet::SheetType type; +}; + +} +#endif // XLSXABSTRACTSHEET_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell.cpp new file mode 100644 index 0000000..fcaf7a6 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxcell.h" +#include "xlsxcell_p.h" +#include "xlsxformat.h" +#include "xlsxformat_p.h" +#include "xlsxutility_p.h" +#include "xlsxworksheet.h" +#include "xlsxworkbook.h" +#include + +QT_BEGIN_NAMESPACE_XLSX + +CellPrivate::CellPrivate(Cell *p) : + q_ptr(p) +{ + +} + +CellPrivate::CellPrivate(const CellPrivate * const cp) + : value(cp->value), formula(cp->formula), cellType(cp->cellType) + , format(cp->format), richString(cp->richString), parent(cp->parent) +{ + +} + +/*! + \class Cell + \inmodule QtXlsx + \brief The Cell class provides a API that is used to handle the worksheet cell. + +*/ + +/*! + \enum Cell::CellType + \value BooleanType Boolean type + \value NumberType Number type, can be blank or used with forumula + \value ErrorType Error type + \value SharedStringType Shared string type + \value StringType String type, can be used with forumula + \value InlineStringType Inline string type + */ + +/*! + * \internal + * Created by Worksheet only. + */ +Cell::Cell(const QVariant &data, CellType type, const Format &format, Worksheet *parent) : + d_ptr(new CellPrivate(this)) +{ + d_ptr->value = data; + d_ptr->cellType = type; + d_ptr->format = format; + d_ptr->parent = parent; +} + +/*! + * \internal + */ +Cell::Cell(const Cell * const cell): + d_ptr(new CellPrivate(cell->d_ptr)) +{ + d_ptr->q_ptr = this; +} + +/*! + * Destroys the Cell and cleans up. + */ +Cell::~Cell() +{ + delete d_ptr; +} + +/*! + * Return the dataType of this Cell + */ +Cell::CellType Cell::cellType() const +{ + Q_D(const Cell); + return d->cellType; +} + +/*! + * Return the data content of this Cell + */ +QVariant Cell::value() const +{ + Q_D(const Cell); + return d->value; +} + +/*! + * Return the style used by this Cell. If no style used, 0 will be returned. + */ +Format Cell::format() const +{ + Q_D(const Cell); + return d->format; +} + +/*! + * Returns true if the cell has one formula. + */ +bool Cell::hasFormula() const +{ + Q_D(const Cell); + return d->formula.isValid(); +} + +/*! + * Return the formula contents if the dataType is Formula + */ +CellFormula Cell::formula() const +{ + Q_D(const Cell); + return d->formula; +} + +/*! + * Returns whether the value is probably a dateTime or not + */ +bool Cell::isDateTime() const +{ + Q_D(const Cell); + if (d->cellType == NumberType && d->value.toDouble() >=0 + && d->format.isValid() && d->format.isDateTimeFormat()) { + return true; + } + return false; +} + +/*! + * Return the data time value. + */ +QDateTime Cell::dateTime() const +{ + Q_D(const Cell); + if (!isDateTime()) + return QDateTime(); + return datetimeFromNumber(d->value.toDouble(), d->parent->workbook()->isDate1904()); +} + +/*! + * Returns whether the cell is probably a rich string or not + */ +bool Cell::isRichString() const +{ + Q_D(const Cell); + if (d->cellType != SharedStringType && d->cellType != InlineStringType + && d->cellType != StringType) + return false; + + return d->richString.isRichString(); +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell.h new file mode 100644 index 0000000..7aec8ce --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef QXLSX_XLSXCELL_H +#define QXLSX_XLSXCELL_H + +#include "xlsxglobal.h" +#include "xlsxformat.h" +#include + +QT_BEGIN_NAMESPACE_XLSX + +class Worksheet; +class Format; +class CellFormula; +class CellPrivate; +class WorksheetPrivate; + +class Q_XLSX_EXPORT Cell +{ + Q_DECLARE_PRIVATE(Cell) +public: + enum CellType { + BooleanType, //t="b" + NumberType, //t="n" (default) + ErrorType, //t="e" + SharedStringType, //t="s" + StringType, //t="str" + InlineStringType //t="inlineStr" + }; + + CellType cellType() const; + QVariant value() const; + Format format() const; + + bool hasFormula() const; + CellFormula formula() const; + + bool isDateTime() const; + QDateTime dateTime() const; + + bool isRichString() const; + + ~Cell(); +private: + friend class Worksheet; + friend class WorksheetPrivate; + + Cell(const QVariant &data=QVariant(), CellType type=NumberType, const Format &format=Format(), Worksheet *parent=0); + Cell(const Cell * const cell); + CellPrivate * const d_ptr; +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_XLSXCELL_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell_p.h new file mode 100644 index 0000000..b537ff2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcell_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXCELL_P_H +#define XLSXCELL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxglobal.h" +#include "xlsxcell.h" +#include "xlsxcellrange.h" +#include "xlsxrichstring.h" +#include "xlsxcellformula.h" +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +class CellPrivate +{ + Q_DECLARE_PUBLIC(Cell) +public: + CellPrivate(Cell *p); + CellPrivate(const CellPrivate * const cp); + + QVariant value; + CellFormula formula; + Cell::CellType cellType; + Format format; + + RichString richString; + + Worksheet *parent; + Cell *q_ptr; +}; + +QT_END_NAMESPACE_XLSX + +#endif // XLSXCELL_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula.cpp new file mode 100644 index 0000000..858d347 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxcellformula.h" +#include "xlsxcellformula_p.h" +#include "xlsxutility_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +CellFormulaPrivate::CellFormulaPrivate(const QString &formula_, const CellRange &ref_, CellFormula::FormulaType type_) + :formula(formula_), type(type_), reference(ref_), ca(false), si(0) +{ + //Remove the formula '=' sign if exists + if (formula.startsWith(QLatin1String("="))) + formula.remove(0,1); + else if (formula.startsWith(QLatin1String("{=")) && formula.endsWith(QLatin1String("}"))) + formula = formula.mid(2, formula.length()-3); +} + +CellFormulaPrivate::CellFormulaPrivate(const CellFormulaPrivate &other) + : QSharedData(other) + , formula(other.formula), type(other.type), reference(other.reference) + , ca(other.ca), si(other.si) +{ + +} + +CellFormulaPrivate::~CellFormulaPrivate() +{ + +} + +/*! + \class CellFormula + \inmodule QtXlsx + \brief The CellFormula class provides a API that is used to handle the cell formula. + +*/ + +/*! + \enum CellFormula::FormulaType + \value NormalType + \value ArrayType + \value DataTableType + \value SharedType +*/ + +/*! + * Creates a new formula. + */ +CellFormula::CellFormula() +{ + //The d pointer is initialized with a null pointer +} + +/*! + * Creates a new formula with the given \a formula and \a type. + */ +CellFormula::CellFormula(const char *formula, FormulaType type) + :d(new CellFormulaPrivate(QString::fromLatin1(formula), CellRange(), type)) +{ + +} + +/*! + * Creates a new formula with the given \a formula and \a type. + */ +CellFormula::CellFormula(const QString &formula, FormulaType type) + :d(new CellFormulaPrivate(formula, CellRange(), type)) +{ + +} + +/*! + * Creates a new formula with the given \a formula, \a ref and \a type. + */ +CellFormula::CellFormula(const QString &formula, const CellRange &ref, FormulaType type) + :d(new CellFormulaPrivate(formula, ref, type)) +{ + +} + +/*! + Creates a new formula with the same attributes as the \a other formula. + */ +CellFormula::CellFormula(const CellFormula &other) + :d(other.d) +{ +} + +/*! + Assigns the \a other formula to this formula, and returns a + reference to this formula. + */ +CellFormula &CellFormula::operator =(const CellFormula &other) +{ + d = other.d; + return *this; +} + +/*! + * Destroys this formula. + */ +CellFormula::~CellFormula() +{ + +} + +/*! + * Returns the type of the formula. + */ +CellFormula::FormulaType CellFormula::formulaType() const +{ + return d ? d->type : NormalType; +} + +/*! + * Returns the contents of the formula. + */ +QString CellFormula::formulaText() const +{ + return d ? d->formula : QString(); +} + +/*! + * Returns the reference cells of the formula. For normal formula, + * this will return an invalid CellRange object. + */ +CellRange CellFormula::reference() const +{ + return d ? d->reference : CellRange(); +} + +/*! + * Returns whether the formula is valid. + */ +bool CellFormula::isValid() const +{ + return d; +} + +/*! + * Returns the shared index for shared formula. + */ +int CellFormula::sharedIndex() const +{ + return d && d->type == SharedType ? d->si : -1; +} + +/*! + * \internal + */ +bool CellFormula::saveToXml(QXmlStreamWriter &writer) const +{ + writer.writeStartElement(QStringLiteral("f")); + QString t; + switch (d->type) { + case CellFormula::ArrayType: + t = QStringLiteral("array"); + break; + case CellFormula::SharedType: + t = QStringLiteral("shared"); + break; + default: + break; + } + if (!t.isEmpty()) + writer.writeAttribute(QStringLiteral("t"), t); + if (d->reference.isValid()) + writer.writeAttribute(QStringLiteral("ref"), d->reference.toString()); + if (d->ca) + writer.writeAttribute(QStringLiteral("ca"), QStringLiteral("1")); + if (d->type == CellFormula::SharedType) + writer.writeAttribute(QStringLiteral("si"), QString::number(d->si)); + + if (!d->formula.isEmpty()) + writer.writeCharacters(d->formula); + + writer.writeEndElement(); //f + + return true; +} + +/*! + * \internal + */ +bool CellFormula::loadFromXml(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("f")); + if (!d) + d = new CellFormulaPrivate(QString(), CellRange(), NormalType); + + QXmlStreamAttributes attributes = reader.attributes(); + QString typeString = attributes.value(QLatin1String("t")).toString(); + if (typeString == QLatin1String("array")) + d->type = ArrayType; + else if (typeString == QLatin1String("shared")) + d->type = SharedType; + else + d->type = NormalType; + + if (attributes.hasAttribute(QLatin1String("ref"))) { + QString refString = attributes.value(QLatin1String("ref")).toString(); + d->reference = CellRange(refString); + } + + QString ca = attributes.value(QLatin1String("si")).toString(); + d->ca = parseXsdBoolean(ca, false); + + if (attributes.hasAttribute(QLatin1String("si"))) + d->si = attributes.value(QLatin1String("si")).toString().toInt(); + + d->formula = reader.readElementText(); + return true; +} + +/*! + * \internal + */ +bool CellFormula::operator ==(const CellFormula &formula) const +{ + return d->formula == formula.d->formula && d->type == formula.d->type + && d->si ==formula.d->si; +} + +/*! + * \internal + */ +bool CellFormula::operator !=(const CellFormula &formula) const +{ + return d->formula != formula.d->formula || d->type != formula.d->type + || d->si !=formula.d->si; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula.h new file mode 100644 index 0000000..0d4679b --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef QXLSX_XLSXCELLFORMULA_H +#define QXLSX_XLSXCELLFORMULA_H + +#include "xlsxglobal.h" +#include + +class QXmlStreamWriter; +class QXmlStreamReader; + +QT_BEGIN_NAMESPACE_XLSX + +class CellFormulaPrivate; +class CellRange; +class Worksheet; +class WorksheetPrivate; + +class Q_XLSX_EXPORT CellFormula +{ +public: + enum FormulaType { + NormalType, + ArrayType, + DataTableType, + SharedType + }; + + CellFormula(); + CellFormula(const char *formula, FormulaType type=NormalType); + CellFormula(const QString &formula, FormulaType type=NormalType); + CellFormula(const QString &formula, const CellRange &ref, FormulaType type); + CellFormula(const CellFormula &other); + ~CellFormula(); + CellFormula &operator =(const CellFormula &other); + bool isValid() const; + + FormulaType formulaType() const; + QString formulaText() const; + CellRange reference() const; + int sharedIndex() const; + + bool operator == (const CellFormula &formula) const; + bool operator != (const CellFormula &formula) const; + + bool saveToXml(QXmlStreamWriter &writer) const; + bool loadFromXml(QXmlStreamReader &reader); +private: + friend class Worksheet; + friend class WorksheetPrivate; + QExplicitlySharedDataPointer d; +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_XLSXCELLFORMULA_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula_p.h new file mode 100644 index 0000000..6aeddc9 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellformula_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXCELLFORMULA_P_H +#define XLSXCELLFORMULA_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxglobal.h" +#include "xlsxcellformula.h" +#include "xlsxcellrange.h" + +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +class CellFormulaPrivate : public QSharedData +{ +public: + CellFormulaPrivate(const QString &formula, const CellRange &reference, CellFormula::FormulaType type); + CellFormulaPrivate(const CellFormulaPrivate &other); + ~CellFormulaPrivate(); + + QString formula; //formula contents + CellFormula::FormulaType type; + CellRange reference; + bool ca; //Calculate Cell + int si; //Shared group index +}; + +QT_END_NAMESPACE_XLSX + +#endif // XLSXCELLFORMULA_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellrange.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellrange.cpp new file mode 100644 index 0000000..6251ab7 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellrange.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxcellrange.h" +#include "xlsxcellreference.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +/*! + \class CellRange + \brief For a range "A1:B2" or single cell "A1" + \inmodule QtXlsx + + The CellRange class stores the top left and bottom + right rows and columns of a range in a worksheet. +*/ + +/*! + Constructs an range, i.e. a range + whose rowCount() and columnCount() are 0. +*/ +CellRange::CellRange() + : top(-1), left(-1), bottom(-2), right(-2) +{ +} + +/*! + Constructs the range from the given \a top, \a + left, \a bottom and \a right rows and columns. + + \sa topRow(), leftColumn(), bottomRow(), rightColumn() +*/ +CellRange::CellRange(int top, int left, int bottom, int right) + : top(top), left(left), bottom(bottom), right(right) +{ +} + +CellRange::CellRange(const CellReference &topLeft, const CellReference &bottomRight) + : top(topLeft.row()), left(topLeft.column()) + , bottom(bottomRight.row()), right(bottomRight.column()) +{ +} + +/*! + \overload + Constructs the range form the given \a range string. +*/ +CellRange::CellRange(const QString &range) +{ + init(range); +} + +/*! + \overload + Constructs the range form the given \a range string. +*/ +CellRange::CellRange(const char *range) +{ + init(QString::fromLatin1(range)); +} + +void CellRange::init(const QString &range) +{ + QStringList rs = range.split(QLatin1Char(':')); + if (rs.size() == 2) { + CellReference start(rs[0]); + CellReference end(rs[1]); + top = start.row(); + left = start.column(); + bottom = end.row(); + right = end.column(); + } else { + CellReference p(rs[0]); + top = p.row(); + left = p.column(); + bottom = p.row(); + right = p.column(); + } +} + +/*! + Constructs a the range by copying the given \a + other range. +*/ +CellRange::CellRange(const CellRange &other) + : top(other.top), left(other.left), bottom(other.bottom), right(other.right) +{ +} + +/*! + Destroys the range. +*/ +CellRange::~CellRange() +{ +} + +/*! + Convert the range to string notation, such as "A1:B5". +*/ +QString CellRange::toString(bool row_abs, bool col_abs) const +{ + if (!isValid()) + return QString(); + + if (left == right && top == bottom) { + //Single cell + return CellReference(top, left).toString(row_abs, col_abs); + } + + QString cell_1 = CellReference(top, left).toString(row_abs, col_abs); + QString cell_2 = CellReference(bottom, right).toString(row_abs, col_abs); + return cell_1 + QLatin1String(":") + cell_2; +} + +/*! + * Returns true if the Range is valid. + */ +bool CellRange::isValid() const +{ + return left <= right && top <= bottom; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellrange.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellrange.h new file mode 100644 index 0000000..5a510b0 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellrange.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef QXLSX_XLSXCELLRANGE_H +#define QXLSX_XLSXCELLRANGE_H +#include "xlsxglobal.h" +#include "xlsxcellreference.h" + +QT_BEGIN_NAMESPACE_XLSX + +class Q_XLSX_EXPORT CellRange +{ +public: + CellRange(); + CellRange(int firstRow, int firstColumn, int lastRow, int lastColumn); + CellRange(const CellReference &topLeft, const CellReference &bottomRight); + CellRange(const QString &range); + CellRange(const char *range); + CellRange(const CellRange &other); + ~CellRange(); + + QString toString(bool row_abs=false, bool col_abs=false) const; + bool isValid() const; + inline void setFirstRow(int row) { top = row; } + inline void setLastRow(int row) { bottom = row; } + inline void setFirstColumn(int col) { left = col; } + inline void setLastColumn(int col) { right = col; } + inline int firstRow() const { return top; } + inline int lastRow() const { return bottom; } + inline int firstColumn() const { return left; } + inline int lastColumn() const { return right; } + inline int rowCount() const { return bottom - top + 1; } + inline int columnCount() const { return right - left + 1; } + inline CellReference topLeft() const { return CellReference(top, left); } + inline CellReference topRight() const { return CellReference(top, right); } + inline CellReference bottomLeft() const { return CellReference(bottom, left); } + inline CellReference bottomRight() const { return CellReference(bottom, right); } + + inline bool operator ==(const CellRange &other) const + { + return top==other.top && bottom==other.bottom + && left == other.left && right == other.right; + } + inline bool operator !=(const CellRange &other) const + { + return top!=other.top || bottom!=other.bottom + || left != other.left || right != other.right; + } +private: + void init(const QString &range); + int top, left, bottom, right; +}; + +QT_END_NAMESPACE_XLSX + +Q_DECLARE_TYPEINFO(QXlsx::CellRange, Q_MOVABLE_TYPE); + +#endif // QXLSX_XLSXCELLRANGE_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellreference.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellreference.cpp new file mode 100644 index 0000000..e7cf5da --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellreference.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxcellreference.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +namespace { + +int intPow(int x, int p) +{ + if (p == 0) return 1; + if (p == 1) return x; + + int tmp = intPow(x, p/2); + if (p%2 == 0) return tmp * tmp; + else return x * tmp * tmp; +} + +QString col_to_name(int col_num) +{ + static QMap col_cache; + + if (!col_cache.contains(col_num)) { + QString col_str; + int remainder; + while (col_num) { + remainder = col_num % 26; + if (remainder == 0) + remainder = 26; + col_str.prepend(QChar('A'+remainder-1)); + col_num = (col_num - 1) / 26; + } + col_cache.insert(col_num, col_str); + } + + return col_cache[col_num]; +} + +int col_from_name(const QString &col_str) +{ + int col = 0; + int expn = 0; + for (int i=col_str.size()-1; i>-1; --i) { + col += (col_str[i].unicode() - 'A' + 1) * intPow(26, expn); + expn++; + } + + return col; +} +} //namespace + +/*! + \class CellReference + \brief For one single cell such as "A1" + \inmodule QtXlsx + + The CellReference class stores the cell location in a worksheet. +*/ + +/*! + Constructs an invalid Cell Reference +*/ +CellReference::CellReference() + : _row(-1), _column(-1) +{ +} + +/*! + Constructs the Reference from the given \a row, and \a column. +*/ +CellReference::CellReference(int row, int column) + : _row(row), _column(column) +{ +} + +/*! + \overload + Constructs the Reference form the given \a cell string. +*/ +CellReference::CellReference(const QString &cell) +{ + init(cell); +} + +/*! + \overload + Constructs the Reference form the given \a cell string. +*/ +CellReference::CellReference(const char *cell) +{ + init(QString::fromLatin1(cell)); +} + +void CellReference::init(const QString &cell_str) +{ + static QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$")); + QRegularExpressionMatch match = re.match(cell_str); + if (match.hasMatch()) { + const QString col_str = match.captured(1); + const QString row_str = match.captured(2); + _row = row_str.toInt(); + _column = col_from_name(col_str); + } +} + +/*! + Constructs a Reference by copying the given \a + other Reference. +*/ +CellReference::CellReference(const CellReference &other) + : _row(other._row), _column(other._column) +{ +} + +/*! + Destroys the Reference. +*/ +CellReference::~CellReference() +{ +} + +/*! + Convert the Reference to string notation, such as "A1" or "$A$1". + If current object is invalid, an empty string will be returned. +*/ +QString CellReference::toString(bool row_abs, bool col_abs) const +{ + if (!isValid()) + return QString(); + + QString cell_str; + if (col_abs) + cell_str.append(QLatin1Char('$')); + cell_str.append(col_to_name(_column)); + if (row_abs) + cell_str.append(QLatin1Char('$')); + cell_str.append(QString::number(_row)); + return cell_str; +} + +/*! + * Returns true if the Reference is valid. + */ +bool CellReference::isValid() const +{ + return _row > 0 && _column > 0; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellreference.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellreference.h new file mode 100644 index 0000000..6a917c2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcellreference.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef QXLSX_XLSXCELLREFERENCE_H +#define QXLSX_XLSXCELLREFERENCE_H +#include "xlsxglobal.h" + +QT_BEGIN_NAMESPACE_XLSX + +class Q_XLSX_EXPORT CellReference +{ +public: + CellReference(); + CellReference(int row, int column); + CellReference(const QString &cell); + CellReference(const char *cell); + CellReference(const CellReference &other); + ~CellReference(); + + QString toString(bool row_abs=false, bool col_abs=false) const; + static CellReference fromString(const QString &cell); + bool isValid() const; + inline void setRow(int row) { _row = row; } + inline void setColumn(int col) { _column = col; } + inline int row() const { return _row; } + inline int column() const { return _column; } + + inline bool operator ==(const CellReference &other) const + { + return _row==other._row && _column==other._column; + } + inline bool operator !=(const CellReference &other) const + { + return _row!=other._row || _column!=other._column; + } +private: + void init(const QString &cell); + int _row, _column; +}; + +QT_END_NAMESPACE_XLSX + +Q_DECLARE_TYPEINFO(QXlsx::CellReference, Q_MOVABLE_TYPE); + +#endif // QXLSX_XLSXCELLREFERENCE_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart.cpp new file mode 100644 index 0000000..a69f5c2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart.cpp @@ -0,0 +1,645 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxchart_p.h" +#include "xlsxworksheet.h" +#include "xlsxcellrange.h" +#include "xlsxutility_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +ChartPrivate::ChartPrivate(Chart *q, Chart::CreateFlag flag) + :AbstractOOXmlFilePrivate(q, flag), chartType(static_cast(0)) +{ + +} + +ChartPrivate::~ChartPrivate() +{ + +} + +/*! + * \class Chart + * \inmodule QtXlsx + * \brief Main class for the charts. + */ + +/*! + \enum Chart::ChartType + + \value CT_Area + \value CT_Area3D, + \value CT_Line, + \value CT_Line3D, + \value CT_Scatter, + \value CT_Pie, + \value CT_Pie3D, + \value CT_Doughnut, + \value CT_Bar, + \value CT_Bar3D, + + \omitvalue CT_Stock, + \omitvalue CT_Radar, + \omitvalue CT_OfPie, + \omitvalue CT_Surface, + \omitvalue CT_Surface3D, + \omitvalue CT_Bubble +*/ + +/*! + * \internal + */ +Chart::Chart(AbstractSheet *parent, CreateFlag flag) + :AbstractOOXmlFile(new ChartPrivate(this, flag)) +{ + d_func()->sheet = parent; +} + +/*! + * Destroys the chart. + */ +Chart::~Chart() +{ +} + +/*! + * Add the data series which is in the range \a range of the \a sheet. + */ +void Chart::addSeries(const CellRange &range, AbstractSheet *sheet) +{ + Q_D(Chart); + if (!range.isValid()) + return; + if (sheet && sheet->sheetType() != AbstractSheet::ST_WorkSheet) + return; + if (!sheet && d->sheet->sheetType() != AbstractSheet::ST_WorkSheet) + return; + + QString sheetName = sheet ? sheet->sheetName() : d->sheet->sheetName(); + //In case sheetName contains space or ' + sheetName = escapeSheetName(sheetName); + + if (range.columnCount() == 1 || range.rowCount() == 1) { + QSharedPointer series = QSharedPointer(new XlsxSeries); + series->numberDataSource_numRef = sheetName + QLatin1String("!") + range.toString(true, true); + d->seriesList.append(series); + } else if (range.columnCount() < range.rowCount()) { + //Column based series + int firstDataColumn = range.firstColumn(); + QString axDataSouruce_numRef; + if (d->chartType == CT_Scatter || d->chartType == CT_Bubble) { + firstDataColumn += 1; + CellRange subRange(range.firstRow(), range.firstColumn(), range.lastRow(), range.firstColumn()); + axDataSouruce_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); + } + + for (int col=firstDataColumn; col<=range.lastColumn(); ++col) { + CellRange subRange(range.firstRow(), col, range.lastRow(), col); + QSharedPointer series = QSharedPointer(new XlsxSeries); + series->axDataSource_numRef = axDataSouruce_numRef; + series->numberDataSource_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); + d->seriesList.append(series); + } + + } else { + //Row based series + int firstDataRow = range.firstRow(); + QString axDataSouruce_numRef; + if (d->chartType == CT_Scatter || d->chartType == CT_Bubble) { + firstDataRow += 1; + CellRange subRange(range.firstRow(), range.firstColumn(), range.firstRow(), range.lastColumn()); + axDataSouruce_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); + } + + for (int row=firstDataRow; row<=range.lastRow(); ++row) { + CellRange subRange(row, range.firstColumn(), row, range.lastColumn()); + QSharedPointer series = QSharedPointer(new XlsxSeries); + series->axDataSource_numRef = axDataSouruce_numRef; + series->numberDataSource_numRef = sheetName + QLatin1String("!") + subRange.toString(true, true); + d->seriesList.append(series); + } + } +} + +/*! + * Set the type of the chart to \a type + */ +void Chart::setChartType(ChartType type) +{ + Q_D(Chart); + d->chartType = type; +} + +/*! + * \internal + * + */ +void Chart::setChartStyle(int id) +{ + Q_UNUSED(id) + //!Todo +} + +/*! + * \internal + */ +void Chart::saveToXmlFile(QIODevice *device) const +{ + Q_D(const Chart); + + QXmlStreamWriter writer(device); + + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("c:chartSpace")); + writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); + writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); + writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + + d->saveXmlChart(writer); + + writer.writeEndElement();//c:chartSpace + writer.writeEndDocument(); +} + +/*! + * \internal + */ +bool Chart::loadFromXmlFile(QIODevice *device) +{ + Q_D(Chart); + + QXmlStreamReader reader(device); + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("chart")) { + if (!d->loadXmlChart(reader)) + return false; + } + } + } + return true; +} + +bool ChartPrivate::loadXmlChart(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("chart")); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("plotArea")) { + if (!loadXmlPlotArea(reader)) + return false; + } else if (reader.name() == QLatin1String("legend")) { + //!Todo + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("chart")) { + break; + } + } + return true; +} + +bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("plotArea")); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("layout")) { + //!ToDo + } else if (reader.name().endsWith(QLatin1String("Chart"))) { + //For pieChart, barChart, ... + loadXmlXxxChart(reader); + } else if (reader.name().endsWith(QLatin1String("Ax"))) { + //For valAx, catAx, serAx, dateAx + loadXmlAxis(reader); + } + + } else if (reader.tokenType() == QXmlStreamReader::EndElement && + reader.name() == QLatin1String("plotArea")) { + break; + } + } + return true; +} + +bool ChartPrivate::loadXmlXxxChart(QXmlStreamReader &reader) +{ + QStringRef name = reader.name(); + if (name == QLatin1String("pieChart")) chartType = Chart::CT_Pie; + else if (name == QLatin1String("pie3DChart")) chartType = Chart::CT_Pie3D; + else if (name == QLatin1String("barChart")) chartType = Chart::CT_Bar; + else if (name == QLatin1String("bar3DChart")) chartType = Chart::CT_Bar3D; + else if (name == QLatin1String("lineChart")) chartType = Chart::CT_Line; + else if (name == QLatin1String("line3DChart")) chartType = Chart::CT_Line3D; + else if (name == QLatin1String("scatterChart")) chartType = Chart::CT_Scatter; + else if (name == QLatin1String("areaChart")) chartType = Chart::CT_Area; + else if (name == QLatin1String("area3DChart")) chartType = Chart::CT_Area3D; + else if (name == QLatin1String("doughnutChart")) chartType = Chart::CT_Doughnut; + else qDebug()<<"Cann't load chart: "< series = QSharedPointer(new XlsxSeries); + seriesList.append(series); + + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QLatin1String("ser"))) { + if (reader.readNextStartElement()) { + QStringRef name = reader.name(); + if (name == QLatin1String("cat") || name == QLatin1String("xVal")) { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == name)) { + if (reader.readNextStartElement()) { + if (reader.name() == QLatin1String("numRef")) + series->axDataSource_numRef = loadXmlNumRef(reader); + } + } + } else if (name == QLatin1String("val") || name == QLatin1String("yVal")) { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == name)) { + if (reader.readNextStartElement()) { + if (reader.name() == QLatin1String("numRef")) + series->numberDataSource_numRef = loadXmlNumRef(reader); + } + } + } else if (name == QLatin1String("extLst")) { + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == name)) { + reader.readNextStartElement(); + } + } + } + } + + return true; +} + + +QString ChartPrivate::loadXmlNumRef(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("numRef")); + + while (!reader.atEnd() && !(reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QLatin1String("numRef"))) { + if (reader.readNextStartElement()) { + if (reader.name() == QLatin1String("f")) + return reader.readElementText(); + } + } + + return QString(); +} + +void ChartPrivate::saveXmlChart(QXmlStreamWriter &writer) const +{ + writer.writeStartElement(QStringLiteral("c:chart")); + writer.writeStartElement(QStringLiteral("c:plotArea")); + switch (chartType) { + case Chart::CT_Pie: + case Chart::CT_Pie3D: + saveXmlPieChart(writer); + break; + case Chart::CT_Bar: + case Chart::CT_Bar3D: + saveXmlBarChart(writer); + break; + case Chart::CT_Line: + case Chart::CT_Line3D: + saveXmlLineChart(writer); + break; + case Chart::CT_Scatter: + saveXmlScatterChart(writer); + break; + case Chart::CT_Area: + case Chart::CT_Area3D: + saveXmlAreaChart(writer); + break; + case Chart::CT_Doughnut: + saveXmlDoughnutChart(writer); + break; + default: + break; + } + saveXmlAxes(writer); + writer.writeEndElement(); //plotArea + +// saveXmlLegend(writer); + + writer.writeEndElement(); //chart +} + +void ChartPrivate::saveXmlPieChart(QXmlStreamWriter &writer) const +{ + QString name = chartType==Chart::CT_Pie ? QStringLiteral("c:pieChart") : QStringLiteral("c:pie3DChart"); + + writer.writeStartElement(name); + + //Do the same behavior as Excel, Pie prefer varyColors + writer.writeEmptyElement(QStringLiteral("c:varyColors")); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); + + for (int i=0; i(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1))); + const_cast(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0))); + } + + //Note: Bar3D have 2~3 axes + Q_ASSERT(axisList.size()==2 || (axisList.size()==3 && chartType==Chart::CT_Bar3D)); + + for (int i=0; iaxisId)); + } + + writer.writeEndElement(); //barChart, bar3DChart +} + +void ChartPrivate::saveXmlLineChart(QXmlStreamWriter &writer) const +{ + QString name = chartType==Chart::CT_Line ? QStringLiteral("c:lineChart") : QStringLiteral("c:line3DChart"); + + writer.writeStartElement(name); + + writer.writeEmptyElement(QStringLiteral("grouping")); + + for (int i=0; i(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1))); + const_cast(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0))); + if (chartType==Chart::CT_Line3D) + const_cast(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Ser, XlsxAxis::Bottom, 2, 0))); + } + + Q_ASSERT((axisList.size()==2||chartType==Chart::CT_Line)|| (axisList.size()==3 && chartType==Chart::CT_Line3D)); + + for (int i=0; iaxisId)); + } + + writer.writeEndElement(); //lineChart, line3DChart +} + +void ChartPrivate::saveXmlScatterChart(QXmlStreamWriter &writer) const +{ + const QString name = QStringLiteral("c:scatterChart"); + + writer.writeStartElement(name); + + writer.writeEmptyElement(QStringLiteral("c:scatterStyle")); + + for (int i=0; i(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Bottom, 0, 1))); + const_cast(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0))); + } + + Q_ASSERT(axisList.size()==2); + + for (int i=0; iaxisId)); + } + + writer.writeEndElement(); //c:scatterChart +} + +void ChartPrivate::saveXmlAreaChart(QXmlStreamWriter &writer) const +{ + QString name = chartType==Chart::CT_Area ? QStringLiteral("c:areaChart") : QStringLiteral("c:area3DChart"); + + writer.writeStartElement(name); + + writer.writeEmptyElement(QStringLiteral("grouping")); + + for (int i=0; i(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Cat, XlsxAxis::Bottom, 0, 1))); + const_cast(this)->axisList.append(QSharedPointer(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Left, 1, 0))); + } + + //Note: Area3D have 2~3 axes + Q_ASSERT(axisList.size()==2 || (axisList.size()==3 && chartType==Chart::CT_Area3D)); + + for (int i=0; iaxisId)); + } + + writer.writeEndElement(); //lineChart, line3DChart +} + +void ChartPrivate::saveXmlDoughnutChart(QXmlStreamWriter &writer) const +{ + QString name = QStringLiteral("c:doughnutChart"); + + writer.writeStartElement(name); + + writer.writeEmptyElement(QStringLiteral("c:varyColors")); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); + + for (int i=0; iaxDataSource_numRef.isEmpty()) { + if (chartType == Chart::CT_Scatter || chartType == Chart::CT_Bubble) + writer.writeStartElement(QStringLiteral("c:xVal")); + else + writer.writeStartElement(QStringLiteral("c:cat")); + writer.writeStartElement(QStringLiteral("c:numRef")); + writer.writeTextElement(QStringLiteral("c:f"), ser->axDataSource_numRef); + writer.writeEndElement();//c:numRef + writer.writeEndElement();//c:cat or c:xVal + } + + if (!ser->numberDataSource_numRef.isEmpty()) { + if (chartType == Chart::CT_Scatter || chartType == Chart::CT_Bubble) + writer.writeStartElement(QStringLiteral("c:yVal")); + else + writer.writeStartElement(QStringLiteral("c:val")); + writer.writeStartElement(QStringLiteral("c:numRef")); + writer.writeTextElement(QStringLiteral("c:f"), ser->numberDataSource_numRef); + writer.writeEndElement();//c:numRef + writer.writeEndElement();//c:val or c:yVal + } + + writer.writeEndElement();//c:ser +} + +bool ChartPrivate::loadXmlAxis(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name().endsWith(QLatin1String("Ax"))); + QString name = reader.name().toString(); + + XlsxAxis *axis = new XlsxAxis; + if (name == QLatin1String("valAx")) + axis->type = XlsxAxis::T_Val; + else if (name == QLatin1String("catAx")) + axis->type = XlsxAxis::T_Cat; + else if (name == QLatin1String("serAx")) + axis->type = XlsxAxis::T_Ser; + else + axis->type = XlsxAxis::T_Date; + + axisList.append(QSharedPointer(axis)); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("axPos")) { + QXmlStreamAttributes attrs = reader.attributes(); + QStringRef pos = attrs.value(QLatin1String("val")); + if (pos==QLatin1String("l")) + axis->axisPos = XlsxAxis::Left; + else if (pos==QLatin1String("r")) + axis->axisPos = XlsxAxis::Right; + else if (pos==QLatin1String("b")) + axis->axisPos = XlsxAxis::Bottom; + else + axis->axisPos = XlsxAxis::Top; + } else if (reader.name() == QLatin1String("axId")) { + axis->axisId = reader.attributes().value(QLatin1String("val")).toString().toInt(); + } else if (reader.name() == QLatin1String("crossAx")) { + axis->crossAx = reader.attributes().value(QLatin1String("val")).toString().toInt(); + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == name) { + break; + } + } + + return true; +} + +void ChartPrivate::saveXmlAxes(QXmlStreamWriter &writer) const +{ + for (int i=0; itype) { + case XlsxAxis::T_Cat: name = QStringLiteral("c:catAx"); break; + case XlsxAxis::T_Val: name = QStringLiteral("c:valAx"); break; + case XlsxAxis::T_Ser: name = QStringLiteral("c:serAx"); break; + case XlsxAxis::T_Date: name = QStringLiteral("c:dateAx"); break; + default: break; + } + + QString pos; + switch (axis->axisPos) { + case XlsxAxis::Top: pos = QStringLiteral("t"); break; + case XlsxAxis::Bottom: pos = QStringLiteral("b"); break; + case XlsxAxis::Left: pos = QStringLiteral("l"); break; + case XlsxAxis::Right: pos = QStringLiteral("r"); break; + default: break; + } + + writer.writeStartElement(name); + writer.writeEmptyElement(QStringLiteral("c:axId")); + writer.writeAttribute(QStringLiteral("val"), QString::number(axis->axisId)); + + writer.writeStartElement(QStringLiteral("c:scaling")); + writer.writeEmptyElement(QStringLiteral("c:orientation")); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("minMax")); + writer.writeEndElement();//c:scaling + + writer.writeEmptyElement(QStringLiteral("c:axPos")); + writer.writeAttribute(QStringLiteral("val"), pos); + + writer.writeEmptyElement(QStringLiteral("c:crossAx")); + writer.writeAttribute(QStringLiteral("val"), QString::number(axis->crossAx)); + + writer.writeEndElement();//name + } +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart.h new file mode 100644 index 0000000..fcd8e2d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_CHART_H +#define QXLSX_CHART_H + +#include "xlsxabstractooxmlfile.h" + +#include + +class QXmlStreamReader; +class QXmlStreamWriter; + +QT_BEGIN_NAMESPACE_XLSX + +class AbstractSheet; +class Worksheet; +class ChartPrivate; +class CellRange; +class DrawingAnchor; + +class Q_XLSX_EXPORT Chart : public AbstractOOXmlFile +{ + Q_DECLARE_PRIVATE(Chart) + +public: + enum ChartType { + CT_Area = 1, //Zero is internally used for unknown types + CT_Area3D, + CT_Line, + CT_Line3D, + CT_Stock, + CT_Radar, + CT_Scatter, + CT_Pie, + CT_Pie3D, + CT_Doughnut, + CT_Bar, + CT_Bar3D, + CT_OfPie, + CT_Surface, + CT_Surface3D, + CT_Bubble + }; + + ~Chart(); + + void addSeries(const CellRange &range, AbstractSheet *sheet=0); + void setChartType(ChartType type); + void setChartStyle(int id); + + void saveToXmlFile(QIODevice *device) const; + bool loadFromXmlFile(QIODevice *device); + +private: + friend class AbstractSheet; + friend class Worksheet; + friend class Chartsheet; + friend class DrawingAnchor; + + Chart(AbstractSheet *parent, CreateFlag flag); +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_CHART_H + diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart_p.h new file mode 100644 index 0000000..4fcd0fb --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchart_p.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_CHART_P_H +#define QXLSX_CHART_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxabstractooxmlfile_p.h" +#include "xlsxchart.h" + +#include + +class QXmlStreamReader; +class QXmlStreamWriter; + +namespace QXlsx { + +class XlsxSeries +{ +public: + //At present, we care about number cell ranges only! + QString numberDataSource_numRef; //yval, val + QString axDataSource_numRef; //xval, cat +}; + +class XlsxAxis +{ +public: + enum Type + { + T_Cat, + T_Val, + T_Date, + T_Ser + }; + + enum Pos + { + Left, + Right, + Top, + Bottom + }; + + XlsxAxis(){} + + XlsxAxis(Type t, Pos p, int id, int crossId) + :type(t), axisPos(p), axisId(id), crossAx(crossId) + { + } + + Type type; + Pos axisPos; //l,r,b,t + int axisId; + int crossAx; +}; + +class ChartPrivate : public AbstractOOXmlFilePrivate +{ + Q_DECLARE_PUBLIC(Chart) + +public: + ChartPrivate(Chart *q, Chart::CreateFlag flag); + ~ChartPrivate(); + + bool loadXmlChart(QXmlStreamReader &reader); + bool loadXmlPlotArea(QXmlStreamReader &reader); + bool loadXmlXxxChart(QXmlStreamReader &reader); + bool loadXmlSer(QXmlStreamReader &reader); + QString loadXmlNumRef(QXmlStreamReader &reader); + bool loadXmlAxis(QXmlStreamReader &reader); + + void saveXmlChart(QXmlStreamWriter &writer) const; + void saveXmlPieChart(QXmlStreamWriter &writer) const; + void saveXmlBarChart(QXmlStreamWriter &writer) const; + void saveXmlLineChart(QXmlStreamWriter &writer) const; + void saveXmlScatterChart(QXmlStreamWriter &writer) const; + void saveXmlAreaChart(QXmlStreamWriter &writer) const; + void saveXmlDoughnutChart(QXmlStreamWriter &writer) const; + void saveXmlSer(QXmlStreamWriter &writer, XlsxSeries *ser, int id) const; + void saveXmlAxes(QXmlStreamWriter &writer) const; + + Chart::ChartType chartType; + + QList > seriesList; + QList > axisList; + + AbstractSheet *sheet; +}; + +} // namespace QXlsx + +#endif // QXLSX_CHART_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet.cpp new file mode 100644 index 0000000..5cf477c --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet.cpp @@ -0,0 +1,159 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxchartsheet.h" +#include "xlsxchartsheet_p.h" +#include "xlsxworkbook.h" +#include "xlsxutility_p.h" +#include "xlsxdrawing_p.h" +#include "xlsxdrawinganchor_p.h" +#include "xlsxchart.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +ChartsheetPrivate::ChartsheetPrivate(Chartsheet *p, Chartsheet::CreateFlag flag) + : AbstractSheetPrivate(p, flag), chart(0) +{ + +} + +ChartsheetPrivate::~ChartsheetPrivate() +{ +} + +/*! + \class Chartsheet + \inmodule QtXlsx + \brief Represent one chartsheet in the workbook. +*/ + +/*! + * \internal + */ +Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFlag flag) + :AbstractSheet(name, id, workbook, new ChartsheetPrivate(this, flag)) +{ + setSheetType(ST_ChartSheet); + + if (flag == Chartsheet::F_NewFromScratch) { + d_func()->drawing = QSharedPointer(new Drawing(this, flag)); + + DrawingAbsoluteAnchor *anchor = new DrawingAbsoluteAnchor(drawing(), DrawingAnchor::Picture); + + anchor->pos = QPoint(0, 0); + anchor->ext = QSize(9293679, 6068786); + + QSharedPointer chart = QSharedPointer(new Chart(this, flag)); + chart->setChartType(Chart::CT_Bar); + anchor->setObjectGraphicFrame(chart); + + d_func()->chart = chart.data(); + } +} + +/*! + * \internal + * + * Make a copy of this sheet. + */ + +Chartsheet *Chartsheet::copy(const QString &distName, int distId) const +{ + //:Todo + Q_UNUSED(distName) + Q_UNUSED(distId) + return 0; +} + +/*! + * Destroys this workssheet. + */ +Chartsheet::~Chartsheet() +{ +} + +/*! + * Returns the chart object of the sheet. + */ +Chart *Chartsheet::chart() +{ + Q_D(Chartsheet); + + return d->chart; +} + +void Chartsheet::saveToXmlFile(QIODevice *device) const +{ + Q_D(const Chartsheet); + d->relationships->clear(); + + QXmlStreamWriter writer(device); + + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeDefaultNamespace(QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); + writer.writeNamespace(QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), QStringLiteral("r")); + writer.writeStartElement(QStringLiteral("chartsheet")); + + writer.writeStartElement(QStringLiteral("sheetViews")); + writer.writeEmptyElement(QStringLiteral("sheetView")); + writer.writeAttribute(QStringLiteral("workbookViewId"), QString::number(0)); + writer.writeAttribute(QStringLiteral("zoomToFit"), QStringLiteral("1")); + writer.writeEndElement(); //sheetViews + + int idx = d->workbook->drawings().indexOf(d->drawing.data()); + d->relationships->addWorksheetRelationship(QStringLiteral("/drawing"), QStringLiteral("../drawings/drawing%1.xml").arg(idx+1)); + + writer.writeEmptyElement(QStringLiteral("drawing")); + writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(d->relationships->count())); + + writer.writeEndElement();//chartsheet + writer.writeEndDocument(); +} + +bool Chartsheet::loadFromXmlFile(QIODevice *device) +{ + Q_D(Chartsheet); + + QXmlStreamReader reader(device); + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("drawing")) { + QString rId = reader.attributes().value(QStringLiteral("r:id")).toString(); + QString name = d->relationships->getRelationshipById(rId).target; + QString path = QDir::cleanPath(splitPath(filePath())[0] + QLatin1String("/") + name); + d->drawing = QSharedPointer(new Drawing(this, F_LoadFromExists)); + d->drawing->setFilePath(path); + } + } + } + + return true; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet.h new file mode 100644 index 0000000..6c5ee98 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXCHARTSHEET_H +#define XLSXCHARTSHEET_H + +#include "xlsxabstractsheet.h" +#include +#include + +QT_BEGIN_NAMESPACE_XLSX +class Workbook; +class DocumentPrivate; +class ChartsheetPrivate; +class Chart; +class Q_XLSX_EXPORT Chartsheet : public AbstractSheet +{ + Q_DECLARE_PRIVATE(Chartsheet) +public: + + ~Chartsheet(); + Chart *chart(); + +private: + friend class DocumentPrivate; + friend class Workbook; + Chartsheet(const QString &sheetName, int sheetId, Workbook *book, CreateFlag flag); + Chartsheet *copy(const QString &distName, int distId) const; + + void saveToXmlFile(QIODevice *device) const; + bool loadFromXmlFile(QIODevice *device); +}; + +QT_END_NAMESPACE_XLSX +#endif // XLSXCHARTSHEET_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet_p.h new file mode 100644 index 0000000..817da88 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxchartsheet_p.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXCHARTSHEET_P_H +#define XLSXCHARTSHEET_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxglobal.h" +#include "xlsxchartsheet.h" +#include "xlsxabstractsheet_p.h" + +namespace QXlsx { + +class XLSX_AUTOTEST_EXPORT ChartsheetPrivate : public AbstractSheetPrivate +{ + Q_DECLARE_PUBLIC(Chartsheet) +public: + ChartsheetPrivate(Chartsheet *p, Chartsheet::CreateFlag flag); + ~ChartsheetPrivate(); + + Chart *chart; +}; + +} +#endif // XLSXCHARTSHEET_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcolor.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcolor.cpp new file mode 100644 index 0000000..b1ed463 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcolor.cpp @@ -0,0 +1,198 @@ +#include "xlsxcolor_p.h" +#include "xlsxstyles_p.h" +#include "xlsxutility_p.h" + +#include +#include +#include +#include + +namespace QXlsx { + + +XlsxColor::XlsxColor(const QColor &color) +{ + if (color.isValid()) + val.setValue(color); +} + +XlsxColor::XlsxColor(const QString &theme, const QString &tint) + :val(QStringList()<() && val.value().isValid()) + return true; + return false; +} + +bool XlsxColor::isIndexedColor() const +{ + return val.userType() == QMetaType::Int; +} + +bool XlsxColor::isThemeColor() const +{ + return val.userType() == QMetaType::QStringList; +} + +bool XlsxColor::isInvalid() const +{ + return !val.isValid(); +} + +QColor XlsxColor::rgbColor() const +{ + if (isRgbColor()) + return val.value(); + return QColor(); +} + +int XlsxColor::indexedColor() const +{ + if (isIndexedColor()) + return val.toInt(); + return -1; +} + +QStringList XlsxColor::themeColor() const +{ + if (isThemeColor()) + return val.toStringList(); + return QStringList(); +} + +bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const +{ + if (!node.isEmpty()) + writer.writeEmptyElement(node); //color, bgColor, fgColor + else + writer.writeEmptyElement(QStringLiteral("color")); + + if (val.userType() == qMetaTypeId()) { + writer.writeAttribute(QStringLiteral("rgb"), XlsxColor::toARGBString(val.value())); + } else if (val.userType() == QMetaType::QStringList) { + QStringList themes = val.toStringList(); + writer.writeAttribute(QStringLiteral("theme"), themes[0]); + if (!themes[1].isEmpty()) + writer.writeAttribute(QStringLiteral("tint"), themes[1]); + } else if (val.userType() == QMetaType::Int) { + writer.writeAttribute(QStringLiteral("indexed"), val.toString()); + } else { + writer.writeAttribute(QStringLiteral("auto"), QStringLiteral("1")); + } + + return true; +} + +bool XlsxColor::loadFromXml(QXmlStreamReader &reader) +{ + QXmlStreamAttributes attributes = reader.attributes(); + + if (attributes.hasAttribute(QLatin1String("rgb"))) { + QString colorString = attributes.value(QLatin1String("rgb")).toString(); + val.setValue(fromARGBString(colorString)); + } else if (attributes.hasAttribute(QLatin1String("indexed"))) { + int index = attributes.value(QLatin1String("indexed")).toString().toInt(); + val.setValue(index); + } else if (attributes.hasAttribute(QLatin1String("theme"))) { + QString theme = attributes.value(QLatin1String("theme")).toString(); + QString tint = attributes.value(QLatin1String("tint")).toString(); + val.setValue(QStringList()<(), this); +} + + +QColor XlsxColor::fromARGBString(const QString &c) +{ + Q_ASSERT(c.length() == 8); + QColor color; + color.setAlpha(c.mid(0, 2).toInt(0, 16)); + color.setRed(c.mid(2, 2).toInt(0, 16)); + color.setGreen(c.mid(4, 2).toInt(0, 16)); + color.setBlue(c.mid(6, 2).toInt(0, 16)); + return color; +} + +QString XlsxColor::toARGBString(const QColor &c) +{ + QString color; + color.sprintf("%02X%02X%02X%02X", c.alpha(), c.red(), c.green(), c.blue()); + return color; +} + +#if !defined(QT_NO_DATASTREAM) +QDataStream &operator<<(QDataStream &s, const XlsxColor &color) +{ + if (color.isInvalid()) + s<<0; + else if (color.isRgbColor()) + s<<1<>(QDataStream &s, XlsxColor &color) +{ + int marker(4); + s>>marker; + if (marker == 0) { + color = XlsxColor(); + } else if (marker == 1) { + QColor c; + s>>c; + color = XlsxColor(c); + } else if (marker == 2) { + int indexed; + s>>indexed; + color = XlsxColor(indexed); + } else if (marker == 3) { + QStringList list; + s>>list; + color = XlsxColor(list[0], list[1]); + } + + return s; +} + +#endif + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const XlsxColor &c) +{ + if (c.isInvalid()) + dbg.nospace() << "XlsxColor(invalid)"; + else if (c.isRgbColor()) + dbg.nospace() << c.rgbColor(); + else if (c.isIndexedColor()) + dbg.nospace() << "XlsxColor(indexed," << c.indexedColor() << ")"; + else if (c.isThemeColor()) + dbg.nospace() << "XlsxColor(theme," << c.themeColor().join(QLatin1Char(':')) << ")"; + + return dbg.space(); +} + +#endif + +} // namespace QXlsx diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcolor_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcolor_p.h new file mode 100644 index 0000000..eff1b0b --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcolor_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_XLSXCOLOR_P_H +#define QXLSX_XLSXCOLOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxglobal.h" +#include +#include + +class QXmlStreamWriter; +class QXmlStreamReader; + +namespace QXlsx { + +class Styles; + +class Q_XLSX_EXPORT XlsxColor +{ +public: + explicit XlsxColor(const QColor &color = QColor()); + explicit XlsxColor(const QString &theme, const QString &tint=QString()); + explicit XlsxColor (int index); + + bool isThemeColor() const; + bool isIndexedColor() const; + bool isRgbColor() const; + bool isInvalid() const; + + QColor rgbColor() const; + int indexedColor() const; + QStringList themeColor() const; + + operator QVariant() const; + + static QColor fromARGBString(const QString &c); + static QString toARGBString(const QColor &c); + + bool saveToXml(QXmlStreamWriter &writer, const QString &node=QString()) const; + bool loadFromXml(QXmlStreamReader &reader); + +private: + QVariant val; +}; + +#if !defined(QT_NO_DATASTREAM) +Q_XLSX_EXPORT QDataStream &operator<<(QDataStream &, const XlsxColor &); +Q_XLSX_EXPORT QDataStream &operator>>(QDataStream &, XlsxColor &); +#endif + +#ifndef QT_NO_DEBUG_STREAM +Q_XLSX_EXPORT QDebug operator<<(QDebug dbg, const XlsxColor &c); +#endif + +} // namespace QXlsx + +Q_DECLARE_METATYPE(QXlsx::XlsxColor) + +#endif // QXLSX_XLSXCOLOR_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting.cpp new file mode 100644 index 0000000..03561fe --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting.cpp @@ -0,0 +1,735 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxconditionalformatting.h" +#include "xlsxconditionalformatting_p.h" +#include "xlsxworksheet.h" +#include "xlsxcellrange.h" +#include "xlsxstyles_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +ConditionalFormattingPrivate::ConditionalFormattingPrivate() +{ + +} + +ConditionalFormattingPrivate::ConditionalFormattingPrivate(const ConditionalFormattingPrivate &other) + :QSharedData(other) +{ + +} + +ConditionalFormattingPrivate::~ConditionalFormattingPrivate() +{ + +} + +void ConditionalFormattingPrivate::writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData &cfvo) const +{ + writer.writeEmptyElement(QStringLiteral("cfvo")); + QString type; + switch(cfvo.type) { + case ConditionalFormatting::VOT_Formula: type=QStringLiteral("formula"); break; + case ConditionalFormatting::VOT_Max: type=QStringLiteral("max"); break; + case ConditionalFormatting::VOT_Min: type=QStringLiteral("min"); break; + case ConditionalFormatting::VOT_Num: type=QStringLiteral("num"); break; + case ConditionalFormatting::VOT_Percent: type=QStringLiteral("percent"); break; + case ConditionalFormatting::VOT_Percentile: type=QStringLiteral("percentile"); break; + default: break; + } + writer.writeAttribute(QStringLiteral("type"), type); + writer.writeAttribute(QStringLiteral("val"), cfvo.value); + if (!cfvo.gte) + writer.writeAttribute(QStringLiteral("gte"), QStringLiteral("0")); +} + +/*! + * \class ConditionalFormatting + * \brief Conditional formatting for single cell or ranges + * \inmodule QtXlsx + * + * The conditional formatting can be applied to a single cell or ranges of cells. + */ + + +/*! + \enum ConditionalFormatting::HighlightRuleType + + \value Highlight_LessThan + \value Highlight_LessThanOrEqual + \value Highlight_Equal + \value Highlight_NotEqual + \value Highlight_GreaterThanOrEqual + \value Highlight_GreaterThan + \value Highlight_Between + \value Highlight_NotBetween + + \value Highlight_ContainsText + \value Highlight_NotContainsText + \value Highlight_BeginsWith + \value Highlight_EndsWith + + \value Highlight_TimePeriod + + \value Highlight_Duplicate + \value Highlight_Unique + + \value Highlight_Blanks + \value Highlight_NoBlanks + \value Highlight_Errors + \value Highlight_NoErrors + + \value Highlight_Top + \value Highlight_TopPercent + \value Highlight_Bottom + \value Highlight_BottomPercent + + \value Highlight_AboveAverage + \value Highlight_AboveOrEqualAverage + \value Highlight_BelowAverage + \value Highlight_BelowOrEqualAverage + \value Highlight_AboveStdDev1 + \value Highlight_AboveStdDev2 + \value Highlight_AboveStdDev3 + \value Highlight_BelowStdDev1 + \value Highlight_BelowStdDev2 + \value Highlight_BelowStdDev3 + + \value Highlight_Expression +*/ + +/*! + \enum ConditionalFormatting::ValueObjectType + + \value VOT_Formula + \value VOT_Max + \value VOT_Min + \value VOT_Num + \value VOT_Percent + \value VOT_Percentile +*/ + +/*! + Construct a conditional formatting object +*/ +ConditionalFormatting::ConditionalFormatting() + :d(new ConditionalFormattingPrivate()) +{ + +} + +/*! + Constructs a copy of \a other. +*/ +ConditionalFormatting::ConditionalFormatting(const ConditionalFormatting &other) + :d(other.d) +{ + +} + +/*! + Assigns \a other to this conditional formatting and returns a reference to + this conditional formatting. + */ +ConditionalFormatting &ConditionalFormatting::operator=(const ConditionalFormatting &other) +{ + this->d = other.d; + return *this; +} + + +/*! + * Destroy the object. + */ +ConditionalFormatting::~ConditionalFormatting() +{ +} + +/*! + * Add a hightlight rule with the given \a type, \a formula1, \a formula2, + * \a format and \a stopIfTrue. + * Return false if failed. + */ +bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const QString &formula2, const Format &format, bool stopIfTrue) +{ + if (format.isEmpty()) + return false; + + bool skipFormula = false; + + QSharedPointer cfRule(new XlsxCfRuleData); + if (type >= Highlight_LessThan && type <= Highlight_NotBetween) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("cellIs"); + QString op; + switch (type) { + case Highlight_Between: op = QStringLiteral("between"); break; + case Highlight_Equal: op = QStringLiteral("equal"); break; + case Highlight_GreaterThan: op = QStringLiteral("greaterThan"); break; + case Highlight_GreaterThanOrEqual: op = QStringLiteral("greaterThanOrEqual"); break; + case Highlight_LessThan: op = QStringLiteral("lessThan"); break; + case Highlight_LessThanOrEqual: op = QStringLiteral("lessThanOrEqual"); break; + case Highlight_NotBetween: op = QStringLiteral("notBetween"); break; + case Highlight_NotEqual: op = QStringLiteral("notEqual"); break; + default: break; + } + cfRule->attrs[XlsxCfRuleData::A_operator] = op; + } else if (type >= Highlight_ContainsText && type <= Highlight_EndsWith) { + if (type == Highlight_ContainsText) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsText"); + cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("containsText"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(SEARCH(\"%1\",%2)))").arg(formula1); + } else if (type == Highlight_NotContainsText) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsText"); + cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("notContains"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(SEARCH(\"%2\",%1))").arg(formula1); + } else if (type == Highlight_BeginsWith) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("beginsWith"); + cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("beginsWith"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEFT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1); + } else { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("endsWith"); + cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("endsWith"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("RIGHT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1); + } + cfRule->attrs[XlsxCfRuleData::A_text] = formula1; + skipFormula = true; + } else if (type == Highlight_TimePeriod) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("timePeriod"); + //:Todo + return false; + } else if (type == Highlight_Duplicate) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("duplicateValues"); + } else if (type == Highlight_Unique) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("uniqueValues"); + } else if (type == Highlight_Errors) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsErrors"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(%1)"); + skipFormula = true; + } else if (type == Highlight_NoErrors) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsErrors"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(%1))"); + skipFormula = true; + } else if (type == Highlight_Blanks) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsBlanks"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEN(TRIM(%1))=0"); + skipFormula = true; + } else if (type == Highlight_NoBlanks) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsBlanks"); + cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEN(TRIM(%1))>0"); + skipFormula = true; + } else if (type >= Highlight_Top && type <= Highlight_BottomPercent) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("top10"); + if (type == Highlight_Bottom || type == Highlight_BottomPercent) + cfRule->attrs[XlsxCfRuleData::A_bottom] = QStringLiteral("1"); + if (type == Highlight_TopPercent || type == Highlight_BottomPercent) + cfRule->attrs[XlsxCfRuleData::A_percent] = QStringLiteral("1"); + cfRule->attrs[XlsxCfRuleData::A_rank] = !formula1.isEmpty() ? formula1 : QStringLiteral("10"); + skipFormula = true; + } else if (type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3) { + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("aboveAverage"); + if (type >= Highlight_BelowAverage && type <= Highlight_BelowStdDev3) + cfRule->attrs[XlsxCfRuleData::A_aboveAverage] = QStringLiteral("0"); + if (type == Highlight_AboveOrEqualAverage || type == Highlight_BelowOrEqualAverage) + cfRule->attrs[XlsxCfRuleData::A_equalAverage] = QStringLiteral("1"); + if (type == Highlight_AboveStdDev1 || type == Highlight_BelowStdDev1) + cfRule->attrs[XlsxCfRuleData::A_stdDev] = QStringLiteral("1"); + else if (type == Highlight_AboveStdDev2 || type == Highlight_BelowStdDev2) + cfRule->attrs[XlsxCfRuleData::A_stdDev] = QStringLiteral("2"); + else if (type == Highlight_AboveStdDev3 || type == Highlight_BelowStdDev3) + cfRule->attrs[XlsxCfRuleData::A_stdDev] = QStringLiteral("3"); + } else if (type == Highlight_Expression){ + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("expression"); + } else { + return false; + } + + cfRule->dxfFormat = format; + if (stopIfTrue) + cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; + if (!skipFormula) { + if (!formula1.isEmpty()) + cfRule->attrs[XlsxCfRuleData::A_formula1] = formula1.startsWith(QLatin1String("=")) ? formula1.mid(1) : formula1; + if (!formula2.isEmpty()) + cfRule->attrs[XlsxCfRuleData::A_formula2] = formula2.startsWith(QLatin1String("=")) ? formula2.mid(1) : formula2; + } + d->cfRules.append(cfRule); + return true; +} + +/*! + * \overload + * + * Add a hightlight rule with the given \a type \a format and \a stopIfTrue. + */ +bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const Format &format, bool stopIfTrue) +{ + if ((type >= Highlight_AboveAverage && type <= Highlight_BelowStdDev3) + || (type >= Highlight_Duplicate && type <= Highlight_NoErrors)) { + return addHighlightCellsRule(type, QString(), QString(), format, stopIfTrue); + } + + return false; +} + +/*! + * \overload + * + * Add a hightlight rule with the given \a type, \a formula, \a format and \a stopIfTrue. + * Return false if failed. + */ +bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const QString &formula, const Format &format, bool stopIfTrue) +{ + if (type == Highlight_Between || type == Highlight_NotBetween) + return false; + + return addHighlightCellsRule(type, formula, QString(), format, stopIfTrue); +} + +/*! + * Add a dataBar rule with the given \a color, \a type1, \a val1 + * , \a type2, \a val2, \a showData and \a stopIfTrue. + * Return false if failed. + */ +bool ConditionalFormatting::addDataBarRule(const QColor &color, ValueObjectType type1, const QString &val1, ValueObjectType type2, const QString &val2, bool showData, bool stopIfTrue) +{ + QSharedPointer cfRule(new XlsxCfRuleData); + + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("dataBar"); + cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(color); + if (stopIfTrue) + cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; + if (!showData) + cfRule->attrs[XlsxCfRuleData::A_hideData] = true; + + XlsxCfVoData cfvo1(type1, val1); + XlsxCfVoData cfvo2(type2, val2); + cfRule->attrs[XlsxCfRuleData::A_cfvo1] = QVariant::fromValue(cfvo1); + cfRule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(cfvo2); + + d->cfRules.append(cfRule); + return true; +} + +/*! + * \overload + * Add a dataBar rule with the given \a color, \a showData and \a stopIfTrue. + */ +bool ConditionalFormatting::addDataBarRule(const QColor &color, bool showData, bool stopIfTrue) +{ + return addDataBarRule(color, VOT_Min, QStringLiteral("0"), VOT_Max, QStringLiteral("0"), showData, stopIfTrue); +} + +/*! + * Add a colorScale rule with the given \a minColor, \a maxColor and \a stopIfTrue. + * Return false if failed. + */ +bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue) +{ + ValueObjectType type1 = VOT_Min; + ValueObjectType type2 = VOT_Max; + QString val1 = QStringLiteral("0"); + QString val2 = QStringLiteral("0"); + + QSharedPointer cfRule(new XlsxCfRuleData); + + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); + cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor); + cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(maxColor); + if (stopIfTrue) + cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; + + XlsxCfVoData cfvo1(type1, val1); + XlsxCfVoData cfvo2(type2, val2); + cfRule->attrs[XlsxCfRuleData::A_cfvo1] = QVariant::fromValue(cfvo1); + cfRule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(cfvo2); + + d->cfRules.append(cfRule); + return true; +} + +/*! + * Add a colorScale rule with the given \a minColor, \a midColor, \a maxColor and \a stopIfTrue. + * Return false if failed. + */ +bool ConditionalFormatting::add3ColorScaleRule(const QColor &minColor, const QColor &midColor, const QColor &maxColor, bool stopIfTrue) +{ + ValueObjectType type1 = VOT_Min; + ValueObjectType type2 = VOT_Percent; + ValueObjectType type3 = VOT_Max; + QString val1 = QStringLiteral("0"); + QString val2 = QStringLiteral("50"); + QString val3 = QStringLiteral("0"); + + QSharedPointer cfRule(new XlsxCfRuleData); + + cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); + cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor); + cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(midColor); + cfRule->attrs[XlsxCfRuleData::A_color3] = XlsxColor(maxColor); + + if (stopIfTrue) + cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; + + XlsxCfVoData cfvo1(type1, val1); + XlsxCfVoData cfvo2(type2, val2); + XlsxCfVoData cfvo3(type3, val3); + cfRule->attrs[XlsxCfRuleData::A_cfvo1] = QVariant::fromValue(cfvo1); + cfRule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(cfvo2); + cfRule->attrs[XlsxCfRuleData::A_cfvo3] = QVariant::fromValue(cfvo3); + + d->cfRules.append(cfRule); + return true; +} + +/*! + Returns the ranges on which the validation will be applied. + */ +QList ConditionalFormatting::ranges() const +{ + return d->ranges; +} + +/*! + Add the \a cell on which the conditional formatting will apply to. + */ +void ConditionalFormatting::addCell(const CellReference &cell) +{ + d->ranges.append(CellRange(cell, cell)); +} + +/*! + \overload + Add the cell(\a row, \a col) on which the conditional formatting will apply to. + */ +void ConditionalFormatting::addCell(int row, int col) +{ + d->ranges.append(CellRange(row, col, row, col)); +} + +/*! + \overload + Add the range(\a firstRow, \a firstCol, \a lastRow, \a lastCol) on + which the conditional formatting will apply to. + */ +void ConditionalFormatting::addRange(int firstRow, int firstCol, int lastRow, int lastCol) +{ + d->ranges.append(CellRange(firstRow, firstCol, lastRow, lastCol)); +} + +/*! + Add the \a range on which the conditional formatting will apply to. + */ +void ConditionalFormatting::addRange(const CellRange &range) +{ + d->ranges.append(range); +} + +bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRuleData *rule, Styles *styles) +{ + Q_ASSERT(reader.name() == QLatin1String("cfRule")); + QXmlStreamAttributes attrs = reader.attributes(); + if (attrs.hasAttribute(QLatin1String("type"))) + rule->attrs[XlsxCfRuleData::A_type] = attrs.value(QLatin1String("type")).toString(); + if (attrs.hasAttribute(QLatin1String("dxfId"))) { + int id = attrs.value(QLatin1String("dxfId")).toString().toInt(); + if (styles) + rule->dxfFormat = styles->dxfFormat(id); + else + rule->dxfFormat.setDxfIndex(id); + } + rule->priority = attrs.value(QLatin1String("priority")).toString().toInt(); + if (attrs.value(QLatin1String("stopIfTrue")) == QLatin1String("1")) { + //default is false + rule->attrs[XlsxCfRuleData::A_stopIfTrue] = QLatin1String("1"); + } + if (attrs.value(QLatin1String("aboveAverage")) == QLatin1String("0")) { + //default is true + rule->attrs[XlsxCfRuleData::A_aboveAverage] = QLatin1String("0"); + } + if (attrs.value(QLatin1String("percent")) == QLatin1String("1")) { + //default is false + rule->attrs[XlsxCfRuleData::A_percent] = QLatin1String("1"); + } + if (attrs.value(QLatin1String("bottom")) == QLatin1String("1")) { + //default is false + rule->attrs[XlsxCfRuleData::A_bottom] = QLatin1String("1"); + } + if (attrs.hasAttribute(QLatin1String("operator"))) + rule->attrs[XlsxCfRuleData::A_operator] = attrs.value(QLatin1String("operator")).toString(); + + if (attrs.hasAttribute(QLatin1String("text"))) + rule->attrs[XlsxCfRuleData::A_text] = attrs.value(QLatin1String("text")).toString(); + + if (attrs.hasAttribute(QLatin1String("timePeriod"))) + rule->attrs[XlsxCfRuleData::A_timePeriod] = attrs.value(QLatin1String("timePeriod")).toString(); + + if (attrs.hasAttribute(QLatin1String("rank"))) + rule->attrs[XlsxCfRuleData::A_rank] = attrs.value(QLatin1String("rank")).toString(); + + if (attrs.hasAttribute(QLatin1String("stdDev"))) + rule->attrs[XlsxCfRuleData::A_stdDev] = attrs.value(QLatin1String("stdDev")).toString(); + + if (attrs.value(QLatin1String("equalAverage")) == QLatin1String("1")) { + //default is false + rule->attrs[XlsxCfRuleData::A_equalAverage] = QLatin1String("1"); + } + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("formula")) { + QString f = reader.readElementText(); + if (!rule->attrs.contains(XlsxCfRuleData::A_formula1)) + rule->attrs[XlsxCfRuleData::A_formula1] = f; + else if (!rule->attrs.contains(XlsxCfRuleData::A_formula2)) + rule->attrs[XlsxCfRuleData::A_formula2] = f; + else if (!rule->attrs.contains(XlsxCfRuleData::A_formula3)) + rule->attrs[XlsxCfRuleData::A_formula3] = f; + } else if (reader.name() == QLatin1String("dataBar")) { + readCfDataBar(reader, rule); + } else if (reader.name() == QLatin1String("colorScale")) { + readCfColorScale(reader, rule); + } + } + if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QStringLiteral("conditionalFormatting")) { + break; + } + } + return true; +} + +bool ConditionalFormattingPrivate::readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *rule) +{ + Q_ASSERT(reader.name() == QLatin1String("dataBar")); + QXmlStreamAttributes attrs = reader.attributes(); + if (attrs.value(QLatin1String("showValue")) == QLatin1String("0")) + rule->attrs[XlsxCfRuleData::A_hideData] = QStringLiteral("1"); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("cfvo")) { + XlsxCfVoData data; + readCfVo(reader, data); + if (!rule->attrs.contains(XlsxCfRuleData::A_cfvo1)) + rule->attrs[XlsxCfRuleData::A_cfvo1] = QVariant::fromValue(data); + else + rule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(data); + } else if (reader.name() == QLatin1String("color")) { + XlsxColor color; + color.loadFromXml(reader); + rule->attrs[XlsxCfRuleData::A_color1] = color; + } + } + if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QStringLiteral("dataBar")) { + break; + } + } + + return true; +} + +bool ConditionalFormattingPrivate::readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *rule) +{ + Q_ASSERT(reader.name() == QLatin1String("colorScale")); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("cfvo")) { + XlsxCfVoData data; + readCfVo(reader, data); + if (!rule->attrs.contains(XlsxCfRuleData::A_cfvo1)) + rule->attrs[XlsxCfRuleData::A_cfvo1] = QVariant::fromValue(data); + else if (!rule->attrs.contains(XlsxCfRuleData::A_cfvo2)) + rule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(data); + else + rule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(data); + } else if (reader.name() == QLatin1String("color")) { + XlsxColor color; + color.loadFromXml(reader); + if (!rule->attrs.contains(XlsxCfRuleData::A_color1)) + rule->attrs[XlsxCfRuleData::A_color1] = color; + else if (!rule->attrs.contains(XlsxCfRuleData::A_color2)) + rule->attrs[XlsxCfRuleData::A_color2] = color; + else + rule->attrs[XlsxCfRuleData::A_color3] = color; + } + } + if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QStringLiteral("colorScale")) { + break; + } + } + + return true; +} + +bool ConditionalFormattingPrivate::readCfVo(QXmlStreamReader &reader, XlsxCfVoData &cfvo) +{ + Q_ASSERT(reader.name() == QStringLiteral("cfvo")); + + QXmlStreamAttributes attrs = reader.attributes(); + + QString type = attrs.value(QLatin1String("type")).toString(); + ConditionalFormatting::ValueObjectType t; + if (type == QLatin1String("formula")) + t = ConditionalFormatting::VOT_Formula; + else if (type == QLatin1String("max")) + t = ConditionalFormatting::VOT_Max; + else if (type == QLatin1String("min")) + t = ConditionalFormatting::VOT_Min; + else if (type == QLatin1String("num")) + t = ConditionalFormatting::VOT_Num; + else if (type == QLatin1String("percent")) + t = ConditionalFormatting::VOT_Percent; + else //if (type == QLatin1String("percentile")) + t = ConditionalFormatting::VOT_Percentile; + + cfvo.type = t; + cfvo.value = attrs.value(QLatin1String("val")).toString(); + if (attrs.value(QLatin1String("gte")) == QLatin1String("0")) { + //default is true + cfvo.gte = false; + } + return true; +} + +bool ConditionalFormatting::loadFromXml(QXmlStreamReader &reader, Styles *styles) +{ + Q_ASSERT(reader.name() == QStringLiteral("conditionalFormatting")); + + d->ranges.clear(); + d->cfRules.clear(); + QXmlStreamAttributes attrs = reader.attributes(); + QString sqref = attrs.value(QLatin1String("sqref")).toString(); + foreach (QString range, sqref.split(QLatin1Char(' '))) + this->addRange(range); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("cfRule")) { + QSharedPointer cfRule(new XlsxCfRuleData); + d->readCfRule(reader, cfRule.data(), styles); + d->cfRules.append(cfRule); + } + } + if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QStringLiteral("conditionalFormatting")) { + break; + } + } + + + return true; +} + +bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const +{ + writer.writeStartElement(QStringLiteral("conditionalFormatting")); + QStringList sqref; + foreach (CellRange range, ranges()) + sqref.append(range.toString()); + writer.writeAttribute(QStringLiteral("sqref"), sqref.join(QLatin1Char(' '))); + + for (int i=0; icfRules.size(); ++i) { + const QSharedPointer &rule = d->cfRules[i]; + writer.writeStartElement(QStringLiteral("cfRule")); + writer.writeAttribute(QStringLiteral("type"), rule->attrs[XlsxCfRuleData::A_type].toString()); + if (rule->dxfFormat.dxfIndexValid()) + writer.writeAttribute(QStringLiteral("dxfId"), QString::number(rule->dxfFormat.dxfIndex())); + writer.writeAttribute(QStringLiteral("priority"), QString::number(rule->priority)); + if (rule->attrs.contains(XlsxCfRuleData::A_stopIfTrue)) + writer.writeAttribute(QStringLiteral("stopIfTrue"), rule->attrs[XlsxCfRuleData::A_stopIfTrue].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_aboveAverage)) + writer.writeAttribute(QStringLiteral("aboveAverage"), rule->attrs[XlsxCfRuleData::A_aboveAverage].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_percent)) + writer.writeAttribute(QStringLiteral("percent"), rule->attrs[XlsxCfRuleData::A_percent].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_bottom)) + writer.writeAttribute(QStringLiteral("bottom"), rule->attrs[XlsxCfRuleData::A_bottom].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_operator)) + writer.writeAttribute(QStringLiteral("operator"), rule->attrs[XlsxCfRuleData::A_operator].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_text)) + writer.writeAttribute(QStringLiteral("text"), rule->attrs[XlsxCfRuleData::A_text].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_timePeriod)) + writer.writeAttribute(QStringLiteral("timePeriod"), rule->attrs[XlsxCfRuleData::A_timePeriod].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_rank)) + writer.writeAttribute(QStringLiteral("rank"), rule->attrs[XlsxCfRuleData::A_rank].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_stdDev)) + writer.writeAttribute(QStringLiteral("stdDev"), rule->attrs[XlsxCfRuleData::A_stdDev].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_equalAverage)) + writer.writeAttribute(QStringLiteral("equalAverage"), rule->attrs[XlsxCfRuleData::A_equalAverage].toString()); + + if (rule->attrs[XlsxCfRuleData::A_type] == QLatin1String("dataBar")) { + writer.writeStartElement(QStringLiteral("dataBar")); + if (rule->attrs.contains(XlsxCfRuleData::A_hideData)) + writer.writeAttribute(QStringLiteral("showValue"), QStringLiteral("0")); + d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo1].value()); + d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo2].value()); + rule->attrs[XlsxCfRuleData::A_color1].value().saveToXml(writer); + writer.writeEndElement();//dataBar + } else if (rule->attrs[XlsxCfRuleData::A_type] == QLatin1String("colorScale")) { + writer.writeStartElement(QStringLiteral("colorScale")); + d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo1].value()); + d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo2].value()); + if (rule->attrs.contains(XlsxCfRuleData::A_cfvo3)) + d->writeCfVo(writer, rule->attrs[XlsxCfRuleData::A_cfvo3].value()); + + rule->attrs[XlsxCfRuleData::A_color1].value().saveToXml(writer); + rule->attrs[XlsxCfRuleData::A_color2].value().saveToXml(writer); + if (rule->attrs.contains(XlsxCfRuleData::A_color3)) + rule->attrs[XlsxCfRuleData::A_color3].value().saveToXml(writer); + + writer.writeEndElement();//colorScale + } + + + if (rule->attrs.contains(XlsxCfRuleData::A_formula1_temp)) { + QString startCell = ranges()[0].toString().split(QLatin1Char(':'))[0]; + writer.writeTextElement(QStringLiteral("formula"), rule->attrs[XlsxCfRuleData::A_formula1_temp].toString().arg(startCell)); + } else if (rule->attrs.contains(XlsxCfRuleData::A_formula1)) { + writer.writeTextElement(QStringLiteral("formula"), rule->attrs[XlsxCfRuleData::A_formula1].toString()); + } + if (rule->attrs.contains(XlsxCfRuleData::A_formula2)) + writer.writeTextElement(QStringLiteral("formula"), rule->attrs[XlsxCfRuleData::A_formula2].toString()); + if (rule->attrs.contains(XlsxCfRuleData::A_formula3)) + writer.writeTextElement(QStringLiteral("formula"), rule->attrs[XlsxCfRuleData::A_formula3].toString()); + + writer.writeEndElement(); //cfRule + } + + writer.writeEndElement(); //conditionalFormatting + return true; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting.h new file mode 100644 index 0000000..45378f7 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef QXLSX_XLSXCONDITIONALFORMATTING_H +#define QXLSX_XLSXCONDITIONALFORMATTING_H + +#include "xlsxglobal.h" +#include "xlsxcellrange.h" +#include "xlsxcellreference.h" +#include +#include +#include + +class QXmlStreamReader; +class QXmlStreamWriter; +class QColor; +class ConditionalFormattingTest; + +QT_BEGIN_NAMESPACE_XLSX + +class Format; +class Worksheet; +class Styles; + +class ConditionalFormattingPrivate; +class Q_XLSX_EXPORT ConditionalFormatting +{ +public: + enum HighlightRuleType { + Highlight_LessThan, + Highlight_LessThanOrEqual, + Highlight_Equal, + Highlight_NotEqual, + Highlight_GreaterThanOrEqual, + Highlight_GreaterThan, + Highlight_Between, + Highlight_NotBetween, + + Highlight_ContainsText, + Highlight_NotContainsText, + Highlight_BeginsWith, + Highlight_EndsWith, + + Highlight_TimePeriod, + + Highlight_Duplicate, + Highlight_Unique, + Highlight_Blanks, + Highlight_NoBlanks, + Highlight_Errors, + Highlight_NoErrors, + + Highlight_Top, + Highlight_TopPercent, + Highlight_Bottom, + Highlight_BottomPercent, + + Highlight_AboveAverage, + Highlight_AboveOrEqualAverage, + Highlight_AboveStdDev1, + Highlight_AboveStdDev2, + Highlight_AboveStdDev3, + Highlight_BelowAverage, + Highlight_BelowOrEqualAverage, + Highlight_BelowStdDev1, + Highlight_BelowStdDev2, + Highlight_BelowStdDev3, + + Highlight_Expression + }; + + enum ValueObjectType + { + VOT_Formula, + VOT_Max, + VOT_Min, + VOT_Num, + VOT_Percent, + VOT_Percentile + }; + + ConditionalFormatting(); + ConditionalFormatting(const ConditionalFormatting &other); + ~ConditionalFormatting(); + + bool addHighlightCellsRule(HighlightRuleType type, const Format &format, bool stopIfTrue=false); + bool addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const Format &format, bool stopIfTrue=false); + bool addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const QString &formula2, const Format &format, bool stopIfTrue=false); + bool addDataBarRule(const QColor &color, bool showData=true, bool stopIfTrue=false); + bool addDataBarRule(const QColor &color, ValueObjectType type1, const QString &val1, ValueObjectType type2, const QString &val2, bool showData=true, bool stopIfTrue=false); + bool add2ColorScaleRule(const QColor &minColor, const QColor &maxColor, bool stopIfTrue=false); + bool add3ColorScaleRule(const QColor &minColor, const QColor &midColor, const QColor &maxColor, bool stopIfTrue=false); + + QList ranges() const; + + void addCell(const CellReference &cell); + void addCell(int row, int col); + void addRange(int firstRow, int firstCol, int lastRow, int lastCol); + void addRange(const CellRange &range); + + //needed by QSharedDataPointer!! + ConditionalFormatting &operator=(const ConditionalFormatting &other); + +private: + friend class Worksheet; + friend class ::ConditionalFormattingTest; + bool saveToXml(QXmlStreamWriter &writer) const; + bool loadFromXml(QXmlStreamReader &reader, Styles *styles=0); + QSharedDataPointer d; +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_XLSXCONDITIONALFORMATTING_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting_p.h new file mode 100644 index 0000000..ff71e5b --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxconditionalformatting_p.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef XLSXCONDITIONALFORMATTING_P_H +#define XLSXCONDITIONALFORMATTING_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxconditionalformatting.h" +#include "xlsxformat.h" +#include "xlsxcolor_p.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +class XlsxCfVoData +{ +public: + XlsxCfVoData() + :gte(true) + { + } + + XlsxCfVoData(ConditionalFormatting::ValueObjectType type, const QString &value, bool gte=true) + :type(type), value(value), gte(gte) + { + } + + ConditionalFormatting::ValueObjectType type; + QString value; + bool gte; +}; + +class XlsxCfRuleData +{ +public: + enum Attribute { + A_type, + A_dxfId, + //A_priority, + A_stopIfTrue, + A_aboveAverage, + A_percent, + A_bottom, + A_operator, + A_text, + A_timePeriod, + A_rank, + A_stdDev, + A_equalAverage, + + A_dxfFormat, + A_formula1, + A_formula2, + A_formula3, + A_formula1_temp, + + A_color1, + A_color2, + A_color3, + + A_cfvo1, + A_cfvo2, + A_cfvo3, + + A_hideData + }; + + XlsxCfRuleData() + :priority(1) + {} + + int priority; + Format dxfFormat; + QMap attrs; +}; + +class ConditionalFormattingPrivate : public QSharedData +{ +public: + ConditionalFormattingPrivate(); + ConditionalFormattingPrivate(const ConditionalFormattingPrivate &other); + ~ConditionalFormattingPrivate(); + + void writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData& cfvo) const; + bool readCfVo(QXmlStreamReader &reader, XlsxCfVoData& cfvo); + bool readCfRule(QXmlStreamReader &reader, XlsxCfRuleData *cfRule, Styles *styles); + bool readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *cfRule); + bool readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *cfRule); + + QList >cfRules; + QList ranges; +}; + +QT_END_NAMESPACE_XLSX + +Q_DECLARE_METATYPE(QXlsx::XlsxCfVoData) +#endif // XLSXCONDITIONALFORMATTING_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcontenttypes.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcontenttypes.cpp new file mode 100644 index 0000000..8a500ac --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxcontenttypes.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxcontenttypes_p.h" +#include +#include +#include +#include +#include +#include + +namespace QXlsx { + +ContentTypes::ContentTypes(CreateFlag flag) + :AbstractOOXmlFile(flag) +{ + m_package_prefix = QStringLiteral("application/vnd.openxmlformats-package."); + m_document_prefix = QStringLiteral("application/vnd.openxmlformats-officedocument."); + + m_defaults.insert(QStringLiteral("rels"), m_package_prefix + QStringLiteral("relationships+xml")); + m_defaults.insert(QStringLiteral("xml"), QStringLiteral("application/xml")); +} + +void ContentTypes::addDefault(const QString &key, const QString &value) +{ + m_defaults.insert(key, value); +} + +void ContentTypes::addOverride(const QString &key, const QString &value) +{ + m_overrides.insert(key, value); +} + +void ContentTypes::addDocPropApp() +{ + addOverride(QStringLiteral("/docProps/app.xml"), m_document_prefix + QStringLiteral("extended-properties+xml")); +} + +void ContentTypes::addDocPropCore() +{ + addOverride(QStringLiteral("/docProps/core.xml"), m_package_prefix + QStringLiteral("core-properties+xml")); +} + +void ContentTypes::addStyles() +{ + addOverride(QStringLiteral("/xl/styles.xml"), m_document_prefix + QStringLiteral("spreadsheetml.styles+xml")); +} + +void ContentTypes::addTheme() +{ + addOverride(QStringLiteral("/xl/theme/theme1.xml"), m_document_prefix + QStringLiteral("theme+xml")); +} + +void ContentTypes::addWorkbook() +{ + addOverride(QStringLiteral("/xl/workbook.xml"), m_document_prefix + QStringLiteral("spreadsheetml.sheet.main+xml")); +} + +void ContentTypes::addWorksheetName(const QString &name) +{ + addOverride(QStringLiteral("/xl/worksheets/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.worksheet+xml")); +} + +void ContentTypes::addChartsheetName(const QString &name) +{ + addOverride(QStringLiteral("/xl/chartsheets/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.chartsheet+xml")); +} + +void ContentTypes::addDrawingName(const QString &name) +{ + addOverride(QStringLiteral("/xl/drawings/%1.xml").arg(name), m_document_prefix + QStringLiteral("drawing+xml")); +} + +void ContentTypes::addChartName(const QString &name) +{ + addOverride(QStringLiteral("/xl/charts/%1.xml").arg(name), m_document_prefix + QStringLiteral("drawingml.chart+xml")); +} + +void ContentTypes::addCommentName(const QString &name) +{ + addOverride(QStringLiteral("/xl/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.comments+xml")); +} + +void ContentTypes::addTableName(const QString &name) +{ + addOverride(QStringLiteral("/xl/tables/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.table+xml")); +} + +void ContentTypes::addExternalLinkName(const QString &name) +{ + addOverride(QStringLiteral("/xl/externalLinks/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.externalLink+xml")); +} + +void ContentTypes::addSharedString() +{ + addOverride(QStringLiteral("/xl/sharedStrings.xml"), m_document_prefix + QStringLiteral("spreadsheetml.sharedStrings+xml")); +} + +void ContentTypes::addVmlName() +{ + addOverride(QStringLiteral("vml"), m_document_prefix + QStringLiteral("vmlDrawing")); +} + +void ContentTypes::addCalcChain() +{ + addOverride(QStringLiteral("/xl/calcChain.xml"), m_document_prefix + QStringLiteral("spreadsheetml.calcChain+xml")); +} + +void ContentTypes::addVbaProject() +{ + //:TODO + addOverride(QStringLiteral("bin"), QStringLiteral("application/vnd.ms-office.vbaProject")); +} + +void ContentTypes::clearOverrides() +{ + m_overrides.clear(); +} + +void ContentTypes::saveToXmlFile(QIODevice *device) const +{ + QXmlStreamWriter writer(device); + + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("Types")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/content-types")); + + { + QMapIterator it(m_defaults); + while (it.hasNext()) { + it.next(); + writer.writeStartElement(QStringLiteral("Default")); + writer.writeAttribute(QStringLiteral("Extension"), it.key()); + writer.writeAttribute(QStringLiteral("ContentType"), it.value()); + writer.writeEndElement();//Default + } + } + + { + QMapIterator it(m_overrides); + while (it.hasNext()) { + it.next(); + writer.writeStartElement(QStringLiteral("Override")); + writer.writeAttribute(QStringLiteral("PartName"), it.key()); + writer.writeAttribute(QStringLiteral("ContentType"), it.value()); + writer.writeEndElement(); //Override + } + } + + writer.writeEndElement();//Types + writer.writeEndDocument(); + +} + +bool ContentTypes::loadFromXmlFile(QIODevice *device) +{ + m_defaults.clear(); + m_overrides.clear(); + + QXmlStreamReader reader(device); + while (!reader.atEnd()) { + QXmlStreamReader::TokenType token = reader.readNext(); + if (token == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("Default")) { + QXmlStreamAttributes attrs = reader.attributes(); + QString extension = attrs.value(QLatin1String("Extension")).toString(); + QString type = attrs.value(QLatin1String("ContentType")).toString(); + m_defaults.insert(extension, type); + } else if (reader.name() == QLatin1String("Override")) { + QXmlStreamAttributes attrs = reader.attributes(); + QString partName = attrs.value(QLatin1String("PartName")).toString(); + QString type = attrs.value(QLatin1String("ContentType")).toString(); + m_overrides.insert(partName, type); + } + } + + if (reader.hasError()) { + qDebug()< +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXCONTENTTYPES_H +#define XLSXCONTENTTYPES_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxabstractooxmlfile.h" + +#include +#include +#include + +class QIODevice; + +namespace QXlsx { + +class ContentTypes : public AbstractOOXmlFile +{ +public: + ContentTypes(CreateFlag flag); + + void addDefault(const QString &key, const QString &value); + void addOverride(const QString &key, const QString &value); + + //Convenient funcation for addOverride() + void addDocPropCore(); + void addDocPropApp(); + void addStyles(); + void addTheme(); + void addWorkbook(); + void addWorksheetName(const QString &name); + void addChartsheetName(const QString &name); + void addChartName(const QString &name); + void addDrawingName(const QString &name); + void addCommentName(const QString &name); + void addTableName(const QString &name); + void addExternalLinkName(const QString &name); + void addSharedString(); + void addVmlName(); + void addCalcChain(); + void addVbaProject(); + + void clearOverrides(); + + void saveToXmlFile(QIODevice *device) const; + bool loadFromXmlFile(QIODevice *device); +private: + QMap m_defaults; + QMap m_overrides; + + QString m_package_prefix; + QString m_document_prefix; +}; + +} +#endif // XLSXCONTENTTYPES_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation.cpp new file mode 100644 index 0000000..c538c72 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation.cpp @@ -0,0 +1,552 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxdatavalidation.h" +#include "xlsxdatavalidation_p.h" +#include "xlsxworksheet.h" +#include "xlsxcellrange.h" + +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +DataValidationPrivate::DataValidationPrivate() + :validationType(DataValidation::None), validationOperator(DataValidation::Between) + , errorStyle(DataValidation::Stop), allowBlank(false), isPromptMessageVisible(true) + , isErrorMessageVisible(true) +{ + +} + +DataValidationPrivate::DataValidationPrivate(DataValidation::ValidationType type, DataValidation::ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank) + :validationType(type), validationOperator(op) + , errorStyle(DataValidation::Stop), allowBlank(allowBlank), isPromptMessageVisible(true) + , isErrorMessageVisible(true), formula1(formula1), formula2(formula2) +{ + +} + +DataValidationPrivate::DataValidationPrivate(const DataValidationPrivate &other) + :QSharedData(other) + , validationType(DataValidation::None), validationOperator(DataValidation::Between) + , errorStyle(DataValidation::Stop), allowBlank(false), isPromptMessageVisible(true) + , isErrorMessageVisible(true) +{ + +} + +DataValidationPrivate::~DataValidationPrivate() +{ + +} + +/*! + * \class DataValidation + * \brief Data validation for single cell or a range + * \inmodule QtXlsx + * + * The data validation can be applied to a single cell or a range of cells. + */ + +/*! + * \enum DataValidation::ValidationType + * + * The enum type defines the type of data that you wish to validate. + * + * \value None the type of data is unrestricted. This is the same as not applying a data validation. + * \value Whole restricts the cell to integer values. Means "Whole number"? + * \value Decimal restricts the cell to decimal values. + * \value List restricts the cell to a set of user specified values. + * \value Date restricts the cell to date values. + * \value Time restricts the cell to time values. + * \value TextLength restricts the cell data based on an integer string length. + * \value Custom restricts the cell based on an external Excel formula that returns a true/false value. + */ + +/*! + * \enum DataValidation::ValidationOperator + * + * The enum type defines the criteria by which the data in the + * cell is validated + * + * \value Between + * \value NotBetween + * \value Equal + * \value NotEqual + * \value LessThan + * \value LessThanOrEqual + * \value GreaterThan + * \value GreaterThanOrEqual + */ + +/*! + * \enum DataValidation::ErrorStyle + * + * The enum type defines the type of error dialog that + * is displayed. + * + * \value Stop + * \value Warning + * \value Information + */ + +/*! + * Construct a data validation object with the given \a type, \a op, \a formula1 + * \a formula2, and \a allowBlank. + */ +DataValidation::DataValidation(ValidationType type, ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank) + :d(new DataValidationPrivate(type, op, formula1, formula2, allowBlank)) +{ + +} + +/*! + Construct a data validation object +*/ +DataValidation::DataValidation() + :d(new DataValidationPrivate()) +{ + +} + +/*! + Constructs a copy of \a other. +*/ +DataValidation::DataValidation(const DataValidation &other) + :d(other.d) +{ + +} + +/*! + Assigns \a other to this validation and returns a reference to this validation. + */ +DataValidation &DataValidation::operator=(const DataValidation &other) +{ + this->d = other.d; + return *this; +} + + +/*! + * Destroy the object. + */ +DataValidation::~DataValidation() +{ +} + +/*! + Returns the validation type. + */ +DataValidation::ValidationType DataValidation::validationType() const +{ + return d->validationType; +} + +/*! + Returns the validation operator. + */ +DataValidation::ValidationOperator DataValidation::validationOperator() const +{ + return d->validationOperator; +} + +/*! + Returns the validation error style. + */ +DataValidation::ErrorStyle DataValidation::errorStyle() const +{ + return d->errorStyle; +} + +/*! + Returns the formula1. + */ +QString DataValidation::formula1() const +{ + return d->formula1; +} + +/*! + Returns the formula2. + */ +QString DataValidation::formula2() const +{ + return d->formula2; +} + +/*! + Returns whether blank is allowed. + */ +bool DataValidation::allowBlank() const +{ + return d->allowBlank; +} + +/*! + Returns the error message. + */ +QString DataValidation::errorMessage() const +{ + return d->errorMessage; +} + +/*! + Returns the error message title. + */ +QString DataValidation::errorMessageTitle() const +{ + return d->errorMessageTitle; +} + +/*! + Returns the prompt message. + */ +QString DataValidation::promptMessage() const +{ + return d->promptMessage; +} + +/*! + Returns the prompt message title. + */ +QString DataValidation::promptMessageTitle() const +{ + return d->promptMessageTitle; +} + +/*! + Returns the whether prompt message is shown. + */ +bool DataValidation::isPromptMessageVisible() const +{ + return d->isPromptMessageVisible; +} + +/*! + Returns the whether error message is shown. + */ +bool DataValidation::isErrorMessageVisible() const +{ + return d->isErrorMessageVisible; +} + +/*! + Returns the ranges on which the validation will be applied. + */ +QList DataValidation::ranges() const +{ + return d->ranges; +} + +/*! + Sets the validation type to \a type. + */ +void DataValidation::setValidationType(DataValidation::ValidationType type) +{ + d->validationType = type; +} + +/*! + Sets the validation operator to \a op. + */ +void DataValidation::setValidationOperator(DataValidation::ValidationOperator op) +{ + d->validationOperator = op; +} + +/*! + Sets the error style to \a es. + */ +void DataValidation::setErrorStyle(DataValidation::ErrorStyle es) +{ + d->errorStyle = es; +} + +/*! + Sets the formula1 to \a formula. + */ +void DataValidation::setFormula1(const QString &formula) +{ + if (formula.startsWith(QLatin1Char('='))) + d->formula1 = formula.mid(1); + else + d->formula1 = formula; +} + +/*! + Sets the formulas to \a formula. + */ +void DataValidation::setFormula2(const QString &formula) +{ + if (formula.startsWith(QLatin1Char('='))) + d->formula2 = formula.mid(1); + else + d->formula2 = formula; +} + +/*! + Sets the error message to \a error with title \a title. + */ +void DataValidation::setErrorMessage(const QString &error, const QString &title) +{ + d->errorMessage = error; + d->errorMessageTitle = title; +} + +/*! + Sets the prompt message to \a prompt with title \a title. + */ +void DataValidation::setPromptMessage(const QString &prompt, const QString &title) +{ + d->promptMessage = prompt; + d->promptMessageTitle = title; +} + +/*! + Enable/disabe blank allow based on \a enable. + */ +void DataValidation::setAllowBlank(bool enable) +{ + d->allowBlank = enable; +} + +/*! + Enable/disabe prompt message visible based on \a visible. + */ +void DataValidation::setPromptMessageVisible(bool visible) +{ + d->isPromptMessageVisible = visible; +} + +/*! + Enable/disabe error message visible based on \a visible. + */ +void DataValidation::setErrorMessageVisible(bool visible) +{ + d->isErrorMessageVisible = visible; +} + +/*! + Add the \a cell on which the DataValidation will apply to. + */ +void DataValidation::addCell(const CellReference &cell) +{ + d->ranges.append(CellRange(cell, cell)); +} + +/*! + \overload + Add the cell(\a row, \a col) on which the DataValidation will apply to. + */ +void DataValidation::addCell(int row, int col) +{ + d->ranges.append(CellRange(row, col, row, col)); +} + +/*! + \overload + Add the range(\a firstRow, \a firstCol, \a lastRow, \a lastCol) on + which the DataValidation will apply to. + */ +void DataValidation::addRange(int firstRow, int firstCol, int lastRow, int lastCol) +{ + d->ranges.append(CellRange(firstRow, firstCol, lastRow, lastCol)); +} + +/*! + Add the \a range on which the DataValidation will apply to. + */ +void DataValidation::addRange(const CellRange &range) +{ + d->ranges.append(range); +} + +/*! + * \internal + */ +bool DataValidation::saveToXml(QXmlStreamWriter &writer) const +{ + static QMap typeMap; + static QMap opMap; + static QMap esMap; + if (typeMap.isEmpty()) { + typeMap.insert(DataValidation::None, QStringLiteral("none")); + typeMap.insert(DataValidation::Whole, QStringLiteral("whole")); + typeMap.insert(DataValidation::Decimal, QStringLiteral("decimal")); + typeMap.insert(DataValidation::List, QStringLiteral("list")); + typeMap.insert(DataValidation::Date, QStringLiteral("date")); + typeMap.insert(DataValidation::Time, QStringLiteral("time")); + typeMap.insert(DataValidation::TextLength, QStringLiteral("textLength")); + typeMap.insert(DataValidation::Custom, QStringLiteral("custom")); + + opMap.insert(DataValidation::Between, QStringLiteral("between")); + opMap.insert(DataValidation::NotBetween, QStringLiteral("notBetween")); + opMap.insert(DataValidation::Equal, QStringLiteral("equal")); + opMap.insert(DataValidation::NotEqual, QStringLiteral("notEqual")); + opMap.insert(DataValidation::LessThan, QStringLiteral("lessThan")); + opMap.insert(DataValidation::LessThanOrEqual, QStringLiteral("lessThanOrEqual")); + opMap.insert(DataValidation::GreaterThan, QStringLiteral("greaterThan")); + opMap.insert(DataValidation::GreaterThanOrEqual, QStringLiteral("greaterThanOrEqual")); + + esMap.insert(DataValidation::Stop, QStringLiteral("stop")); + esMap.insert(DataValidation::Warning, QStringLiteral("warning")); + esMap.insert(DataValidation::Information, QStringLiteral("information")); + } + + writer.writeStartElement(QStringLiteral("dataValidation")); + if (validationType() != DataValidation::None) + writer.writeAttribute(QStringLiteral("type"), typeMap[validationType()]); + if (errorStyle() != DataValidation::Stop) + writer.writeAttribute(QStringLiteral("errorStyle"), esMap[errorStyle()]); + if (validationOperator() != DataValidation::Between) + writer.writeAttribute(QStringLiteral("operator"), opMap[validationOperator()]); + if (allowBlank()) + writer.writeAttribute(QStringLiteral("allowBlank"), QStringLiteral("1")); + // if (dropDownVisible()) + // writer.writeAttribute(QStringLiteral("showDropDown"), QStringLiteral("1")); + if (isPromptMessageVisible()) + writer.writeAttribute(QStringLiteral("showInputMessage"), QStringLiteral("1")); + if (isErrorMessageVisible()) + writer.writeAttribute(QStringLiteral("showErrorMessage"), QStringLiteral("1")); + if (!errorMessageTitle().isEmpty()) + writer.writeAttribute(QStringLiteral("errorTitle"), errorMessageTitle()); + if (!errorMessage().isEmpty()) + writer.writeAttribute(QStringLiteral("error"), errorMessage()); + if (!promptMessageTitle().isEmpty()) + writer.writeAttribute(QStringLiteral("promptTitle"), promptMessageTitle()); + if (!promptMessage().isEmpty()) + writer.writeAttribute(QStringLiteral("prompt"), promptMessage()); + + QStringList sqref; + foreach (CellRange range, ranges()) + sqref.append(range.toString()); + writer.writeAttribute(QStringLiteral("sqref"), sqref.join(QLatin1Char(' '))); + + if (!formula1().isEmpty()) + writer.writeTextElement(QStringLiteral("formula1"), formula1()); + if (!formula2().isEmpty()) + writer.writeTextElement(QStringLiteral("formula2"), formula2()); + + writer.writeEndElement(); //dataValidation + + return true; +} + +/*! + * \internal + */ +DataValidation DataValidation::loadFromXml(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("dataValidation")); + + static QMap typeMap; + static QMap opMap; + static QMap esMap; + if (typeMap.isEmpty()) { + typeMap.insert(QStringLiteral("none"), DataValidation::None); + typeMap.insert(QStringLiteral("whole"), DataValidation::Whole); + typeMap.insert(QStringLiteral("decimal"), DataValidation::Decimal); + typeMap.insert(QStringLiteral("list"), DataValidation::List); + typeMap.insert(QStringLiteral("date"), DataValidation::Date); + typeMap.insert(QStringLiteral("time"), DataValidation::Time); + typeMap.insert(QStringLiteral("textLength"), DataValidation::TextLength); + typeMap.insert(QStringLiteral("custom"), DataValidation::Custom); + + opMap.insert(QStringLiteral("between"), DataValidation::Between); + opMap.insert(QStringLiteral("notBetween"), DataValidation::NotBetween); + opMap.insert(QStringLiteral("equal"), DataValidation::Equal); + opMap.insert(QStringLiteral("notEqual"), DataValidation::NotEqual); + opMap.insert(QStringLiteral("lessThan"), DataValidation::LessThan); + opMap.insert(QStringLiteral("lessThanOrEqual"), DataValidation::LessThanOrEqual); + opMap.insert(QStringLiteral("greaterThan"), DataValidation::GreaterThan); + opMap.insert(QStringLiteral("greaterThanOrEqual"), DataValidation::GreaterThanOrEqual); + + esMap.insert(QStringLiteral("stop"), DataValidation::Stop); + esMap.insert(QStringLiteral("warning"), DataValidation::Warning); + esMap.insert(QStringLiteral("information"), DataValidation::Information); + } + + DataValidation validation; + QXmlStreamAttributes attrs = reader.attributes(); + + QString sqref = attrs.value(QLatin1String("sqref")).toString(); + foreach (QString range, sqref.split(QLatin1Char(' '))) + validation.addRange(range); + + if (attrs.hasAttribute(QLatin1String("type"))) { + QString t = attrs.value(QLatin1String("type")).toString(); + validation.setValidationType(typeMap.contains(t) ? typeMap[t] : DataValidation::None); + } + if (attrs.hasAttribute(QLatin1String("errorStyle"))) { + QString es = attrs.value(QLatin1String("errorStyle")).toString(); + validation.setErrorStyle(esMap.contains(es) ? esMap[es] : DataValidation::Stop); + } + if (attrs.hasAttribute(QLatin1String("operator"))) { + QString op = attrs.value(QLatin1String("operator")).toString(); + validation.setValidationOperator(opMap.contains(op) ? opMap[op] : DataValidation::Between); + } + if (attrs.hasAttribute(QLatin1String("allowBlank"))) { + validation.setAllowBlank(true); + } else { + validation.setAllowBlank(false); + } + if (attrs.hasAttribute(QLatin1String("showInputMessage"))) { + validation.setPromptMessageVisible(true); + } else { + validation.setPromptMessageVisible(false); + } + if (attrs.hasAttribute(QLatin1String("showErrorMessage"))) { + validation.setErrorMessageVisible(true); + } else { + validation.setErrorMessageVisible(false); + } + + QString et = attrs.value(QLatin1String("errorTitle")).toString(); + QString e = attrs.value(QLatin1String("error")).toString(); + if (!e.isEmpty() || !et.isEmpty()) + validation.setErrorMessage(e, et); + + QString pt = attrs.value(QLatin1String("promptTitle")).toString(); + QString p = attrs.value(QLatin1String("prompt")).toString(); + if (!p.isEmpty() || !pt.isEmpty()) + validation.setPromptMessage(p, pt); + + //find the end + while(!(reader.name() == QLatin1String("dataValidation") && reader.tokenType() == QXmlStreamReader::EndElement)) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("formula1")) { + validation.setFormula1(reader.readElementText()); + } else if (reader.name() == QLatin1String("formula2")) { + validation.setFormula2(reader.readElementText()); + } + } + } + return validation; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation.h new file mode 100644 index 0000000..3a19079 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef QXLSX_XLSXDATAVALIDATION_H +#define QXLSX_XLSXDATAVALIDATION_H + +#include "xlsxglobal.h" +#include +#include +#include + +class QXmlStreamReader; +class QXmlStreamWriter; + +QT_BEGIN_NAMESPACE_XLSX + +class Worksheet; +class CellRange; +class CellReference; + +class DataValidationPrivate; +class Q_XLSX_EXPORT DataValidation +{ +public: + enum ValidationType + { + None, + Whole, + Decimal, + List, + Date, + Time, + TextLength, + Custom + }; + + enum ValidationOperator + { + Between, + NotBetween, + Equal, + NotEqual, + LessThan, + LessThanOrEqual, + GreaterThan, + GreaterThanOrEqual + }; + + enum ErrorStyle + { + Stop, + Warning, + Information + }; + + DataValidation(); + DataValidation(ValidationType type, ValidationOperator op=Between, const QString &formula1=QString() + , const QString &formula2=QString(), bool allowBlank=false); + DataValidation(const DataValidation &other); + ~DataValidation(); + + ValidationType validationType() const; + ValidationOperator validationOperator() const; + ErrorStyle errorStyle() const; + QString formula1() const; + QString formula2() const; + bool allowBlank() const; + QString errorMessage() const; + QString errorMessageTitle() const; + QString promptMessage() const; + QString promptMessageTitle() const; + bool isPromptMessageVisible() const; + bool isErrorMessageVisible() const; + QList ranges() const; + + void setValidationType(ValidationType type); + void setValidationOperator(ValidationOperator op); + void setErrorStyle(ErrorStyle es); + void setFormula1(const QString &formula); + void setFormula2(const QString &formula); + void setErrorMessage(const QString &error, const QString &title=QString()); + void setPromptMessage(const QString &prompt, const QString &title=QString()); + void setAllowBlank(bool enable); + void setPromptMessageVisible(bool visible); + void setErrorMessageVisible(bool visible); + + void addCell(const CellReference &cell); + void addCell(int row, int col); + void addRange(int firstRow, int firstCol, int lastRow, int lastCol); + void addRange(const CellRange &range); + + DataValidation &operator=(const DataValidation &other); + + bool saveToXml(QXmlStreamWriter &writer) const; + static DataValidation loadFromXml(QXmlStreamReader &reader); +private: + QSharedDataPointer d; +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_XLSXDATAVALIDATION_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation_p.h new file mode 100644 index 0000000..236bb3d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdatavalidation_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef XLSXDATAVALIDATION_P_H +#define XLSXDATAVALIDATION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxdatavalidation.h" +#include + +QT_BEGIN_NAMESPACE_XLSX + +class Q_XLSX_EXPORT DataValidationPrivate : public QSharedData +{ +public: + DataValidationPrivate(); + DataValidationPrivate(DataValidation::ValidationType type, DataValidation::ValidationOperator op, const QString &formula1, const QString &formula2, bool allowBlank); + DataValidationPrivate(const DataValidationPrivate &other); + ~DataValidationPrivate(); + + DataValidation::ValidationType validationType; + DataValidation::ValidationOperator validationOperator; + DataValidation::ErrorStyle errorStyle; + bool allowBlank; + bool isPromptMessageVisible; + bool isErrorMessageVisible; + QString formula1; + QString formula2; + QString errorMessage; + QString errorMessageTitle; + QString promptMessage; + QString promptMessageTitle; + QList ranges; +}; + +QT_END_NAMESPACE_XLSX +#endif // XLSXDATAVALIDATION_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropsapp.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropsapp.cpp new file mode 100644 index 0000000..49ad9b2 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropsapp.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxdocpropsapp_p.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace QXlsx { + +DocPropsApp::DocPropsApp(CreateFlag flag) + :AbstractOOXmlFile(flag) +{ +} + +void DocPropsApp::addPartTitle(const QString &title) +{ + m_titlesOfPartsList.append(title); +} + +void DocPropsApp::addHeadingPair(const QString &name, int value) +{ + m_headingPairsList.append(qMakePair(name, value)); +} + +bool DocPropsApp::setProperty(const QString &name, const QString &value) +{ + static QStringList validKeys; + if (validKeys.isEmpty()) { + validKeys << QStringLiteral("manager") << QStringLiteral("company"); + } + + if (!validKeys.contains(name)) + return false; + + if (value.isEmpty()) + m_properties.remove(name); + else + m_properties[name] = value; + + return true; +} + +QString DocPropsApp::property(const QString &name) const +{ + if (m_properties.contains(name)) + return m_properties[name]; + + return QString(); +} + +QStringList DocPropsApp::propertyNames() const +{ + return m_properties.keys(); +} + +void DocPropsApp::saveToXmlFile(QIODevice *device) const +{ + QXmlStreamWriter writer(device); + QString vt = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); + + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("Properties")); + writer.writeDefaultNamespace(QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties")); + writer.writeNamespace(vt, QStringLiteral("vt")); + writer.writeTextElement(QStringLiteral("Application"), QStringLiteral("Microsoft Excel")); + writer.writeTextElement(QStringLiteral("DocSecurity"), QStringLiteral("0")); + writer.writeTextElement(QStringLiteral("ScaleCrop"), QStringLiteral("false")); + + writer.writeStartElement(QStringLiteral("HeadingPairs")); + writer.writeStartElement(vt, QStringLiteral("vector")); + writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size()*2)); + writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("variant")); + typedef QPair PairType; //Make foreach happy + foreach (PairType pair, m_headingPairsList) { + writer.writeStartElement(vt, QStringLiteral("variant")); + writer.writeTextElement(vt, QStringLiteral("lpstr"), pair.first); + writer.writeEndElement(); //vt:variant + writer.writeStartElement(vt, QStringLiteral("variant")); + writer.writeTextElement(vt, QStringLiteral("i4"), QString::number(pair.second)); + writer.writeEndElement(); //vt:variant + } + writer.writeEndElement();//vt:vector + writer.writeEndElement();//HeadingPairs + + writer.writeStartElement(QStringLiteral("TitlesOfParts")); + writer.writeStartElement(vt, QStringLiteral("vector")); + writer.writeAttribute(QStringLiteral("size"), QString::number(m_titlesOfPartsList.size())); + writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("lpstr")); + foreach (QString title, m_titlesOfPartsList) + writer.writeTextElement(vt, QStringLiteral("lpstr"), title); + writer.writeEndElement();//vt:vector + writer.writeEndElement();//TitlesOfParts + + if (m_properties.contains(QStringLiteral("manager"))) + writer.writeTextElement(QStringLiteral("Manager"), m_properties[QStringLiteral("manager")]); + //Not like "manager", "company" always exists for Excel generated file. + writer.writeTextElement(QStringLiteral("Company"), m_properties.contains(QStringLiteral("company")) ? m_properties[QStringLiteral("company")]: QString()); + writer.writeTextElement(QStringLiteral("LinksUpToDate"), QStringLiteral("false")); + writer.writeTextElement(QStringLiteral("SharedDoc"), QStringLiteral("false")); + writer.writeTextElement(QStringLiteral("HyperlinksChanged"), QStringLiteral("false")); + writer.writeTextElement(QStringLiteral("AppVersion"), QStringLiteral("12.0000")); + + writer.writeEndElement(); //Properties + writer.writeEndDocument(); +} + +bool DocPropsApp::loadFromXmlFile(QIODevice *device) +{ + QXmlStreamReader reader(device); + while (!reader.atEnd()) { + QXmlStreamReader::TokenType token = reader.readNext(); + if (token == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("Properties")) + continue; + + if (reader.name() == QStringLiteral("Manager")) { + setProperty(QStringLiteral("manager"), reader.readElementText()); + } else if (reader.name() == QStringLiteral("Company")) { + setProperty(QStringLiteral("company"), reader.readElementText()); + } + } + + if (reader.hasError()) { + qDebug("Error when read doc props app file."); + } + } + return true; +} + +} //namespace diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropsapp_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropsapp_p.h new file mode 100644 index 0000000..433731e --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropsapp_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXDOCPROPSAPP_H +#define XLSXDOCPROPSAPP_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxglobal.h" +#include "xlsxabstractooxmlfile.h" +#include +#include +#include +#include + +class QIODevice; + +namespace QXlsx { + +class XLSX_AUTOTEST_EXPORT DocPropsApp : public AbstractOOXmlFile +{ +public: + DocPropsApp(CreateFlag flag); + + void addPartTitle(const QString &title); + void addHeadingPair(const QString &name, int value); + + bool setProperty(const QString &name, const QString &value); + QString property(const QString &name) const; + QStringList propertyNames() const; + + void saveToXmlFile(QIODevice *device) const; + bool loadFromXmlFile(QIODevice *device); + +private: + QStringList m_titlesOfPartsList; + QList > m_headingPairsList; + QMap m_properties; +}; + +} +#endif // XLSXDOCPROPSAPP_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropscore.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropscore.cpp new file mode 100644 index 0000000..7e955f8 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocpropscore.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxdocpropscore_p.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace QXlsx { + +DocPropsCore::DocPropsCore(CreateFlag flag) + :AbstractOOXmlFile(flag) +{ +} + +bool DocPropsCore::setProperty(const QString &name, const QString &value) +{ + static QStringList validKeys; + if (validKeys.isEmpty()) { + validKeys << QStringLiteral("title") << QStringLiteral("subject") + << QStringLiteral("keywords") << QStringLiteral("description") + << QStringLiteral("category") << QStringLiteral("status") + << QStringLiteral("created") << QStringLiteral("creator"); + } + + if (!validKeys.contains(name)) + return false; + + if (value.isEmpty()) + m_properties.remove(name); + else + m_properties[name] = value; + + return true; +} + +QString DocPropsCore::property(const QString &name) const +{ + if (m_properties.contains(name)) + return m_properties[name]; + + return QString(); +} + +QStringList DocPropsCore::propertyNames() const +{ + return m_properties.keys(); +} + +void DocPropsCore::saveToXmlFile(QIODevice *device) const +{ + QXmlStreamWriter writer(device); + const QString cp = QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); + const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/"); + const QString dcterms = QStringLiteral("http://purl.org/dc/terms/"); + const QString dcmitype = QStringLiteral("http://purl.org/dc/dcmitype/"); + const QString xsi = QStringLiteral("http://www.w3.org/2001/XMLSchema-instance"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("cp:coreProperties")); + writer.writeNamespace(cp, QStringLiteral("cp")); + writer.writeNamespace(dc, QStringLiteral("dc")); + writer.writeNamespace(dcterms, QStringLiteral("dcterms")); + writer.writeNamespace(dcmitype, QStringLiteral("dcmitype")); + writer.writeNamespace(xsi, QStringLiteral("xsi")); + + if (m_properties.contains(QStringLiteral("title"))) + writer.writeTextElement(dc, QStringLiteral("title"), m_properties[QStringLiteral("title")]); + + if (m_properties.contains(QStringLiteral("subject"))) + writer.writeTextElement(dc, QStringLiteral("subject"), m_properties[QStringLiteral("subject")]); + + writer.writeTextElement(dc, QStringLiteral("creator"), m_properties.contains(QStringLiteral("creator")) ? m_properties[QStringLiteral("creator")] : QStringLiteral("Qt Xlsx Library")); + + if (m_properties.contains(QStringLiteral("keywords"))) + writer.writeTextElement(cp, QStringLiteral("keywords"), m_properties[QStringLiteral("keywords")]); + + if (m_properties.contains(QStringLiteral("description"))) + writer.writeTextElement(dc, QStringLiteral("description"), m_properties[QStringLiteral("description")]); + + writer.writeTextElement(cp, QStringLiteral("lastModifiedBy"), m_properties.contains(QStringLiteral("creator")) ? m_properties[QStringLiteral("creator")] : QStringLiteral("Qt Xlsx Library")); + + writer.writeStartElement(dcterms, QStringLiteral("created")); + writer.writeAttribute(xsi, QStringLiteral("type"), QStringLiteral("dcterms:W3CDTF")); + writer.writeCharacters(m_properties.contains(QStringLiteral("created")) ? m_properties[QStringLiteral("created")] : QDateTime::currentDateTime().toString(Qt::ISODate)); + writer.writeEndElement();//dcterms:created + + writer.writeStartElement(dcterms, QStringLiteral("modified")); + writer.writeAttribute(xsi, QStringLiteral("type"), QStringLiteral("dcterms:W3CDTF")); + writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); + writer.writeEndElement();//dcterms:created + + if (m_properties.contains(QStringLiteral("category"))) + writer.writeTextElement(cp, QStringLiteral("category"), m_properties[QStringLiteral("category")]); + + if (m_properties.contains(QStringLiteral("status"))) + writer.writeTextElement(cp, QStringLiteral("contentStatus"), m_properties[QStringLiteral("status")]); + + writer.writeEndElement(); //cp:coreProperties + writer.writeEndDocument(); +} + +bool DocPropsCore::loadFromXmlFile(QIODevice *device) +{ + QXmlStreamReader reader(device); + + const QString cp = QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); + const QString dc = QStringLiteral("http://purl.org/dc/elements/1.1/"); + const QString dcterms = QStringLiteral("http://purl.org/dc/terms/"); + + while (!reader.atEnd()) { + QXmlStreamReader::TokenType token = reader.readNext(); + if (token == QXmlStreamReader::StartElement) { + const QStringRef nsUri = reader.namespaceUri(); + const QStringRef name = reader.name(); + if (name == QStringLiteral("subject") && nsUri == dc) { + setProperty(QStringLiteral("subject"), reader.readElementText()); + } else if (name == QStringLiteral("title") && nsUri == dc) { + setProperty(QStringLiteral("title"), reader.readElementText()); + } else if (name == QStringLiteral("creator") && nsUri == dc) { + setProperty(QStringLiteral("creator"), reader.readElementText()); + } else if (name == QStringLiteral("description") && nsUri == dc) { + setProperty(QStringLiteral("description"), reader.readElementText()); + } else if (name == QStringLiteral("keywords") && nsUri == cp) { + setProperty(QStringLiteral("keywords"), reader.readElementText()); + } else if (name == QStringLiteral("created") && nsUri == dcterms) { + setProperty(QStringLiteral("created"), reader.readElementText()); + } else if (name == QStringLiteral("category") && nsUri == cp) { + setProperty(QStringLiteral("category"), reader.readElementText()); + } else if (name == QStringLiteral("contentStatus") && nsUri == cp) { + setProperty(QStringLiteral("status"), reader.readElementText()); + } + } + + if (reader.hasError()) { + qDebug()<<"Error when read doc props core file."< +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#ifndef XLSXDOCPROPSCORE_H +#define XLSXDOCPROPSCORE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxglobal.h" +#include "xlsxabstractooxmlfile.h" +#include +#include + +class QIODevice; + +namespace QXlsx { + +class XLSX_AUTOTEST_EXPORT DocPropsCore : public AbstractOOXmlFile +{ +public: + explicit DocPropsCore(CreateFlag flag); + + bool setProperty(const QString &name, const QString &value); + QString property(const QString &name) const; + QStringList propertyNames() const; + + void saveToXmlFile(QIODevice *device) const; + bool loadFromXmlFile(QIODevice *device); + +private: + QMap m_properties; +}; + +} +#endif // XLSXDOCPROPSCORE_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument.cpp new file mode 100644 index 0000000..314e789 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument.cpp @@ -0,0 +1,1046 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxdocument.h" +#include "xlsxdocument_p.h" +#include "xlsxworkbook.h" +#include "xlsxworksheet.h" +#include "xlsxcontenttypes_p.h" +#include "xlsxrelationships_p.h" +#include "xlsxstyles_p.h" +#include "xlsxtheme_p.h" +#include "xlsxdocpropsapp_p.h" +#include "xlsxdocpropscore_p.h" +#include "xlsxsharedstrings_p.h" +#include "xlsxutility_p.h" +#include "xlsxworkbook_p.h" +#include "xlsxdrawing_p.h" +#include "xlsxmediafile_p.h" +#include "xlsxchart.h" +#include "xlsxzipreader_p.h" +#include "xlsxzipwriter_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +/* + From Wikipedia: The Open Packaging Conventions (OPC) is a + container-file technology initially created by Microsoft to store + a combination of XML and non-XML files that together form a single + entity such as an Open XML Paper Specification (OpenXPS) + document. http://en.wikipedia.org/wiki/Open_Packaging_Conventions. + + At its simplest an Excel XLSX file contains the following elements: + + ____ [Content_Types].xml + | + |____ docProps + | |____ app.xml + | |____ core.xml + | + |____ xl + | |____ workbook.xml + | |____ worksheets + | | |____ sheet1.xml + | | + | |____ styles.xml + | | + | |____ theme + | | |____ theme1.xml + | | + | |_____rels + | |____ workbook.xml.rels + | + |_____rels + |____ .rels + + The Packager class coordinates the classes that represent the + elements of the package and writes them into the XLSX file. +*/ + +DocumentPrivate::DocumentPrivate(Document *p) : + q_ptr(p), defaultPackageName(QStringLiteral("Book1.xlsx")) +{ +} + +void DocumentPrivate::init() +{ + if (contentTypes.isNull()) + contentTypes = QSharedPointer(new ContentTypes(ContentTypes::F_NewFromScratch)); + + if (workbook.isNull()) + workbook = QSharedPointer(new Workbook(Workbook::F_NewFromScratch)); +} + +bool DocumentPrivate::loadPackage(QIODevice *device) +{ + Q_Q(Document); + ZipReader zipReader(device); + QStringList filePaths = zipReader.filePaths(); + + //Load the Content_Types file + if (!filePaths.contains(QLatin1String("[Content_Types].xml"))) + return false; + contentTypes = QSharedPointer(new ContentTypes(ContentTypes::F_LoadFromExists)); + contentTypes->loadFromXmlData(zipReader.fileData(QStringLiteral("[Content_Types].xml"))); + + //Load root rels file + if (!filePaths.contains(QLatin1String("_rels/.rels"))) + return false; + Relationships rootRels; + rootRels.loadFromXmlData(zipReader.fileData(QStringLiteral("_rels/.rels"))); + + //load core property + QList rels_core = rootRels.packageRelationships(QStringLiteral("/metadata/core-properties")); + if (!rels_core.isEmpty()) { + //Get the core property file name if it exists. + //In normal case, this should be "docProps/core.xml" + QString docPropsCore_Name = rels_core[0].target; + + DocPropsCore props(DocPropsCore::F_LoadFromExists); + props.loadFromXmlData(zipReader.fileData(docPropsCore_Name)); + foreach (QString name, props.propertyNames()) + q->setDocumentProperty(name, props.property(name)); + } + + //load app property + QList rels_app = rootRels.documentRelationships(QStringLiteral("/extended-properties")); + if (!rels_app.isEmpty()) { + //Get the app property file name if it exists. + //In normal case, this should be "docProps/app.xml" + QString docPropsApp_Name = rels_app[0].target; + + DocPropsApp props(DocPropsApp::F_LoadFromExists); + props.loadFromXmlData(zipReader.fileData(docPropsApp_Name)); + foreach (QString name, props.propertyNames()) + q->setDocumentProperty(name, props.property(name)); + } + + //load workbook now, Get the workbook file path from the root rels file + //In normal case, this should be "xl/workbook.xml" + workbook = QSharedPointer(new Workbook(Workbook::F_LoadFromExists)); + QList rels_xl = rootRels.documentRelationships(QStringLiteral("/officeDocument")); + if (rels_xl.isEmpty()) + return false; + QString xlworkbook_Path = rels_xl[0].target; + QString xlworkbook_Dir = splitPath(xlworkbook_Path)[0]; + workbook->relationships()->loadFromXmlData(zipReader.fileData(getRelFilePath(xlworkbook_Path))); + workbook->setFilePath(xlworkbook_Path); + workbook->loadFromXmlData(zipReader.fileData(xlworkbook_Path)); + + //load styles + QList rels_styles = workbook->relationships()->documentRelationships(QStringLiteral("/styles")); + if (!rels_styles.isEmpty()) { + //In normal case this should be styles.xml which in xl + QString name = rels_styles[0].target; + QString path = xlworkbook_Dir + QLatin1String("/") + name; + QSharedPointer styles (new Styles(Styles::F_LoadFromExists)); + styles->loadFromXmlData(zipReader.fileData(path)); + workbook->d_func()->styles = styles; + } + + //load sharedStrings + QList rels_sharedStrings = workbook->relationships()->documentRelationships(QStringLiteral("/sharedStrings")); + if (!rels_sharedStrings.isEmpty()) { + //In normal case this should be sharedStrings.xml which in xl + QString name = rels_sharedStrings[0].target; + QString path = xlworkbook_Dir + QLatin1String("/") + name; + workbook->d_func()->sharedStrings->loadFromXmlData(zipReader.fileData(path)); + } + + //load theme + QList rels_theme = workbook->relationships()->documentRelationships(QStringLiteral("/theme")); + if (!rels_theme.isEmpty()) { + //In normal case this should be theme/theme1.xml which in xl + QString name = rels_theme[0].target; + QString path = xlworkbook_Dir + QLatin1String("/") + name; + workbook->theme()->loadFromXmlData(zipReader.fileData(path)); + } + + //load sheets + for (int i=0; isheetCount(); ++i) { + AbstractSheet *sheet = workbook->sheet(i); + QString rel_path = getRelFilePath(sheet->filePath()); + //If the .rel file exists, load it. + if (zipReader.filePaths().contains(rel_path)) + sheet->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); + sheet->loadFromXmlData(zipReader.fileData(sheet->filePath())); + } + + //load external links + for (int i=0; id_func()->externalLinks.count(); ++i) { + SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); + QString rel_path = getRelFilePath(link->filePath()); + //If the .rel file exists, load it. + if (zipReader.filePaths().contains(rel_path)) + link->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); + link->loadFromXmlData(zipReader.fileData(link->filePath())); + } + + //load drawings + for (int i=0; idrawings().size(); ++i) { + Drawing *drawing = workbook->drawings()[i]; + QString rel_path = getRelFilePath(drawing->filePath()); + if (zipReader.filePaths().contains(rel_path)) + drawing->relationships()->loadFromXmlData(zipReader.fileData(rel_path)); + drawing->loadFromXmlData(zipReader.fileData(drawing->filePath())); + } + + //load charts + QList > chartFileToLoad = workbook->chartFiles(); + for (int i=0; i cf = chartFileToLoad[i]; + cf->loadFromXmlData(zipReader.fileData(cf->filePath())); + } + + //load media files + QList > mediaFileToLoad = workbook->mediaFiles(); + for (int i=0; i mf = mediaFileToLoad[i]; + const QString path = mf->fileName(); + const QString suffix = path.mid(path.lastIndexOf(QLatin1Char('.'))+1); + mf->set(zipReader.fileData(path), suffix); + } + + return true; +} + +bool DocumentPrivate::savePackage(QIODevice *device) const +{ + Q_Q(const Document); + ZipWriter zipWriter(device); + if (zipWriter.error()) + return false; + + contentTypes->clearOverrides(); + + DocPropsApp docPropsApp(DocPropsApp::F_NewFromScratch); + DocPropsCore docPropsCore(DocPropsCore::F_NewFromScratch); + + // save worksheet xml files + QList > worksheets = workbook->getSheetsByTypes(AbstractSheet::ST_WorkSheet); + if (!worksheets.isEmpty()) + docPropsApp.addHeadingPair(QStringLiteral("Worksheets"), worksheets.size()); + for (int i=0; i sheet = worksheets[i]; + contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i+1)); + docPropsApp.addPartTitle(sheet->sheetName()); + + zipWriter.addFile(QStringLiteral("xl/worksheets/sheet%1.xml").arg(i+1), sheet->saveToXmlData()); + Relationships *rel = sheet->relationships(); + if (!rel->isEmpty()) + zipWriter.addFile(QStringLiteral("xl/worksheets/_rels/sheet%1.xml.rels").arg(i+1), rel->saveToXmlData()); + } + + //save chartsheet xml files + QList > chartsheets = workbook->getSheetsByTypes(AbstractSheet::ST_ChartSheet); + if (!chartsheets.isEmpty()) + docPropsApp.addHeadingPair(QStringLiteral("Chartsheets"), chartsheets.size()); + for (int i=0; i sheet = chartsheets[i]; + contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i+1)); + docPropsApp.addPartTitle(sheet->sheetName()); + + zipWriter.addFile(QStringLiteral("xl/chartsheets/sheet%1.xml").arg(i+1), sheet->saveToXmlData()); + Relationships *rel = sheet->relationships(); + if (!rel->isEmpty()) + zipWriter.addFile(QStringLiteral("xl/chartsheets/_rels/sheet%1.xml.rels").arg(i+1), rel->saveToXmlData()); + } + + // save external links xml files + for (int i=0; id_func()->externalLinks.count(); ++i) { + SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); + contentTypes->addExternalLinkName(QStringLiteral("externalLink%1").arg(i+1)); + + zipWriter.addFile(QStringLiteral("xl/externalLinks/externalLink%1.xml").arg(i+1), link->saveToXmlData()); + Relationships *rel = link->relationships(); + if (!rel->isEmpty()) + zipWriter.addFile(QStringLiteral("xl/externalLinks/_rels/externalLink%1.xml.rels").arg(i+1), rel->saveToXmlData()); + } + + // save workbook xml file + contentTypes->addWorkbook(); + zipWriter.addFile(QStringLiteral("xl/workbook.xml"), workbook->saveToXmlData()); + zipWriter.addFile(QStringLiteral("xl/_rels/workbook.xml.rels"), workbook->relationships()->saveToXmlData()); + + // save drawing xml files + for (int i=0; idrawings().size(); ++i) { + contentTypes->addDrawingName(QStringLiteral("drawing%1").arg(i+1)); + + Drawing *drawing = workbook->drawings()[i]; + zipWriter.addFile(QStringLiteral("xl/drawings/drawing%1.xml").arg(i+1), drawing->saveToXmlData()); + if (!drawing->relationships()->isEmpty()) + zipWriter.addFile(QStringLiteral("xl/drawings/_rels/drawing%1.xml.rels").arg(i+1), drawing->relationships()->saveToXmlData()); + } + + // save docProps app/core xml file + foreach (QString name, q->documentPropertyNames()) { + docPropsApp.setProperty(name, q->documentProperty(name)); + docPropsCore.setProperty(name, q->documentProperty(name)); + } + contentTypes->addDocPropApp(); + contentTypes->addDocPropCore(); + zipWriter.addFile(QStringLiteral("docProps/app.xml"), docPropsApp.saveToXmlData()); + zipWriter.addFile(QStringLiteral("docProps/core.xml"), docPropsCore.saveToXmlData()); + + // save sharedStrings xml file + if (!workbook->sharedStrings()->isEmpty()) { + contentTypes->addSharedString(); + zipWriter.addFile(QStringLiteral("xl/sharedStrings.xml"), workbook->sharedStrings()->saveToXmlData()); + } + + // save styles xml file + contentTypes->addStyles(); + zipWriter.addFile(QStringLiteral("xl/styles.xml"), workbook->styles()->saveToXmlData()); + + // save theme xml file + contentTypes->addTheme(); + zipWriter.addFile(QStringLiteral("xl/theme/theme1.xml"), workbook->theme()->saveToXmlData()); + + // save chart xml files + for (int i=0; ichartFiles().size(); ++i) { + contentTypes->addChartName(QStringLiteral("chart%1").arg(i+1)); + QSharedPointer cf = workbook->chartFiles()[i]; + zipWriter.addFile(QStringLiteral("xl/charts/chart%1.xml").arg(i+1), cf->saveToXmlData()); + } + + // save image files + for (int i=0; imediaFiles().size(); ++i) { + QSharedPointer mf = workbook->mediaFiles()[i]; + if (!mf->mimeType().isEmpty()) + contentTypes->addDefault(mf->suffix(), mf->mimeType()); + + zipWriter.addFile(QStringLiteral("xl/media/image%1.%2").arg(i+1).arg(mf->suffix()), mf->contents()); + } + + // save root .rels xml file + Relationships rootrels; + rootrels.addDocumentRelationship(QStringLiteral("/officeDocument"), QStringLiteral("xl/workbook.xml")); + rootrels.addPackageRelationship(QStringLiteral("/metadata/core-properties"), QStringLiteral("docProps/core.xml")); + rootrels.addDocumentRelationship(QStringLiteral("/extended-properties"), QStringLiteral("docProps/app.xml")); + zipWriter.addFile(QStringLiteral("_rels/.rels"), rootrels.saveToXmlData()); + + // save content types xml file + zipWriter.addFile(QStringLiteral("[Content_Types].xml"), contentTypes->saveToXmlData()); + + zipWriter.close(); + return true; +} + + +/*! + \class Document + \inmodule QtXlsx + \brief The Document class provides a API that is used to handle the contents of .xlsx files. + +*/ + +/*! + * Creates a new empty xlsx document. + * The \a parent argument is passed to QObject's constructor. + */ +Document::Document(QObject *parent) : + QObject(parent), d_ptr(new DocumentPrivate(this)) +{ + d_ptr->init(); +} + +/*! + * \overload + * Try to open an existing xlsx document named \a name. + * The \a parent argument is passed to QObject's constructor. + */ +Document::Document(const QString &name, QObject *parent) : + QObject(parent), d_ptr(new DocumentPrivate(this)) +{ + d_ptr->packageName = name; + if (QFile::exists(name)) { + QFile xlsx(name); + if (xlsx.open(QFile::ReadOnly)) + d_ptr->loadPackage(&xlsx); + } + d_ptr->init(); +} + +/*! + * \overload + * Try to open an existing xlsx document from \a device. + * The \a parent argument is passed to QObject's constructor. + */ +Document::Document(QIODevice *device, QObject *parent) : + QObject(parent), d_ptr(new DocumentPrivate(this)) +{ + if (device && device->isReadable()) + d_ptr->loadPackage(device); + d_ptr->init(); +} + +/*! + \overload + + Write \a value to cell \a row_column with the given \a format. + */ +bool Document::write(const CellReference &row_column, const QVariant &value, const Format &format) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->write(row_column, value, format); + return false; +} + +/*! + * Write \a value to cell (\a row, \a col) with the \a format. + * Returns true on success. + */ +bool Document::write(int row, int col, const QVariant &value, const Format &format) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->write(row, col, value, format); + return false; +} + +/*! + \overload + Returns the contents of the cell \a cell. + + \sa cellAt() +*/ +QVariant Document::read(const CellReference &cell) const +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->read(cell); + return QVariant(); +} + +/*! + Returns the contents of the cell (\a row, \a col). + + \sa cellAt() + */ +QVariant Document::read(int row, int col) const +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->read(row, col); + return QVariant(); +} + +/*! + * Insert an \a image to current active worksheet at the position \a row, \a column + * Returns ture if success. + */ +bool Document::insertImage(int row, int column, const QImage &image) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->insertImage(row, column, image); + return false; +} + +/*! + * Creates an chart with the given \a size and insert it to the current + * active worksheet at the position \a row, \a col. + * The chart will be returned. + */ +Chart *Document::insertChart(int row, int col, const QSize &size) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->insertChart(row, col, size); + return 0; +} + +/*! + Merge a \a range of cells. The first cell should contain the data and the others should + be blank. All cells will be applied the same style if a valid \a format is given. + Returns true on success. + + \note All cells except the top-left one will be cleared. + */ +bool Document::mergeCells(const CellRange &range, const Format &format) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->mergeCells(range, format); + return false; +} + +/*! + Unmerge the cells in the \a range. + Returns true on success. +*/ +bool Document::unmergeCells(const CellRange &range) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->unmergeCells(range); + return false; +} + +/*! + Sets width in characters of columns with the given \a range and \a width. + Returns true on success. + */ +bool Document::setColumnWidth(const CellRange &range, double width) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnWidth(range, width); + return false; +} + +/*! + Sets format property of columns with the gien \a range and \a format. + Returns true on success. + */ +bool Document::setColumnFormat(const CellRange &range, const Format &format) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnFormat(range, format); + return false; +} + +/*! + Sets hidden property of columns \a range to \a hidden. Columns are 1-indexed. + Hidden columns are not visible. + Returns true on success. + */ +bool Document::setColumnHidden(const CellRange &range, bool hidden) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnWidth(range, hidden); + return false; +} + +/*! + Sets width in characters \a column to \a width. Columns are 1-indexed. + Returns true on success. + */ +bool Document::setColumnWidth(int column, double width) +{ + return setColumnWidth(column,column,width); +} + +/*! + Sets format property \a column to \a format. Columns are 1-indexed. + Returns true on success. + */ +bool Document::setColumnFormat(int column, const Format &format) +{ + return setColumnFormat(column,column,format); +} + +/*! + Sets hidden property of a \a column. Columns are 1-indexed. + Returns true on success. + */ +bool Document::setColumnHidden(int column, bool hidden) +{ + return setColumnHidden(column,column,hidden); +} + +/*! + Sets width in characters for columns [\a colFirst, \a colLast]. Columns are 1-indexed. + Returns true on success. + */ +bool Document::setColumnWidth(int colFirst, int colLast, double width) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnWidth(colFirst, colLast, width); + return false; +} + +/*! + Sets format property of columns [\a colFirst, \a colLast] to \a format. + Columns are 1-indexed. + Returns true on success. + */ +bool Document::setColumnFormat(int colFirst, int colLast, const Format &format) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnFormat(colFirst, colLast, format); + return false; +} + + +/*! + Sets hidden property of columns [\a colFirst, \a colLast] to \a hidden. + Columns are 1-indexed. + Returns true on success. + */ +bool Document::setColumnHidden(int colFirst, int colLast, bool hidden) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setColumnHidden(colFirst, colLast, hidden); + return false; +} + +/*! + Returns width of the \a column in characters of the normal font. + Columns are 1-indexed. + Returns true on success. + */ +double Document::columnWidth(int column) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->columnWidth(column); + return 0.0; +} + +/*! + Returns formatting of the \a column. Columns are 1-indexed. + */ +Format Document::columnFormat(int column) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->columnFormat(column); + return Format(); +} + +/*! + Returns true if \a column is hidden. Columns are 1-indexed. + */ +bool Document::isColumnHidden(int column) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->isColumnHidden(column); + return false; +} + +/*! + Sets the \a format of the \a row. + Rows are 1-indexed. + + Returns true if success. +*/ +bool Document::setRowFormat(int row, const Format &format) +{ + return setRowFormat(row,row, format); +} + +/*! + Sets the \a format of the rows including and between \a rowFirst and \a rowLast. + Rows are 1-indexed. + + Returns true if success. +*/ +bool Document::setRowFormat(int rowFirst, int rowLast, const Format &format) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setRowFormat(rowFirst, rowLast, format); + return false; +} + +/*! + Sets the \a hidden property of the row \a row. + Rows are 1-indexed. If hidden is true rows will not be visible. + + Returns true if success. +*/ +bool Document::setRowHidden(int row, bool hidden) +{ + return setRowHidden(row,row,hidden); +} + +/*! + Sets the \a hidden property of the rows including and between \a rowFirst and \a rowLast. + Rows are 1-indexed. If hidden is true rows will not be visible. + + Returns true if success. +*/ +bool Document::setRowHidden(int rowFirst, int rowLast, bool hidden) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setRowHidden(rowFirst, rowLast, hidden); + return false; +} + +/*! + Sets the \a height of the row \a row. + Row height measured in point size. + Rows are 1-indexed. + + Returns true if success. +*/ +bool Document::setRowHeight(int row, double height) +{ + return setRowHeight(row,row,height); +} + +/*! + Sets the \a height of the rows including and between \a rowFirst and \a rowLast. + Row height measured in point size. + Rows are 1-indexed. + + Returns true if success. +*/ +bool Document::setRowHeight(int rowFirst, int rowLast, double height) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->setRowHeight(rowFirst, rowLast, height); + return false; +} + +/*! + Returns height of \a row in points. +*/ +double Document::rowHeight(int row) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->rowHeight(row); + return 0.0; +} + +/*! + Returns format of \a row. +*/ +Format Document::rowFormat(int row) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->rowFormat(row); + return Format(); +} + +/*! + Returns true if \a row is hidden. +*/ +bool Document::isRowHidden(int row) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->isRowHidden(row); + return false; +} + +/*! + Groups rows from \a rowFirst to \a rowLast with the given \a collapsed. + Returns false if error occurs. + */ +bool Document::groupRows(int rowFirst, int rowLast, bool collapsed) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->groupRows(rowFirst, rowLast, collapsed); + return false; +} + +/*! + Groups columns from \a colFirst to \a colLast with the given \a collapsed. + Returns false if error occurs. + */ +bool Document::groupColumns(int colFirst, int colLast, bool collapsed) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->groupColumns(colFirst, colLast, collapsed); + return false; +} + +/*! + * Add a data \a validation rule for current worksheet. Returns true if successful. + */ +bool Document::addDataValidation(const DataValidation &validation) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->addDataValidation(validation); + return false; +} + +/*! + * Add a conditional formatting \a cf for current worksheet. Returns true if successful. + */ +bool Document::addConditionalFormatting(const ConditionalFormatting &cf) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->addConditionalFormatting(cf); + return false; +} + +/*! + * \overload + * Returns the cell at the position \a pos. If there is no cell at + * the specified position, the function returns 0. + * + * \sa read() + */ +Cell *Document::cellAt(const CellReference &pos) const +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->cellAt(pos); + return 0; +} + +/*! + * Returns the cell at the given \a row and \a col. If there + * is no cell at the specified position, the function returns 0. + * + * \sa read() + */ +Cell *Document::cellAt(int row, int col) const +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->cellAt(row, col); + return 0; +} + +/*! + * \brief Create a defined name in the workbook with the given \a name, \a formula, \a comment + * and \a scope. + * + * \param name The defined name. + * \param formula The cell or range that the defined name refers to. + * \param scope The name of one worksheet, or empty which means golbal scope. + * \return Return false if the name invalid. + */ +bool Document::defineName(const QString &name, const QString &formula, const QString &comment, const QString &scope) +{ + Q_D(Document); + + return d->workbook->defineName(name, formula, comment, scope); +} + +/*! + Return the range that contains cell data. + */ +CellRange Document::dimension() const +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->dimension(); + return CellRange(); +} + +/*! + * Returns the value of the document's \a key property. + */ +QString Document::documentProperty(const QString &key) const +{ + Q_D(const Document); + if (d->documentProperties.contains(key)) + return d->documentProperties[key]; + else + return QString(); +} + +/*! + Set the document properties such as Title, Author etc. + + The method can be used to set the document properties of the Excel + file created by Qt Xlsx. These properties are visible when you use the + Office Button -> Prepare -> Properties option in Excel and are also + available to external applications that read or index windows files. + + The \a property \a key that can be set are: + + \list + \li title + \li subject + \li creator + \li manager + \li company + \li category + \li keywords + \li description + \li status + \endlist +*/ +void Document::setDocumentProperty(const QString &key, const QString &property) +{ + Q_D(Document); + d->documentProperties[key] = property; +} + +/*! + * Returns the names of all properties that were addedusing setDocumentProperty(). + */ +QStringList Document::documentPropertyNames() const +{ + Q_D(const Document); + return d->documentProperties.keys(); +} + +/*! + * Return the internal Workbook object. + */ +Workbook *Document::workbook() const +{ + Q_D(const Document); + return d->workbook.data(); +} + +/*! + * Returns the sheet object named \a sheetName. + */ +AbstractSheet *Document::sheet(const QString &sheetName) const +{ + Q_D(const Document); + return d->workbook->sheet(sheetNames().indexOf(sheetName)); +} + +/*! + * Creates and append an sheet with the given \a name and \a type. + * Return true if success. + */ +bool Document::addSheet(const QString &name, AbstractSheet::SheetType type) +{ + Q_D(Document); + return d->workbook->addSheet(name, type); +} + +/*! + * Creates and inserts an document with the given \a name and \a type at the \a index. + * Returns false if the \a name already used. + */ +bool Document::insertSheet(int index, const QString &name, AbstractSheet::SheetType type) +{ + Q_D(Document); + return d->workbook->insertSheet(index, name, type); +} + +/*! + Rename the worksheet from \a oldName to \a newName. + Returns true if the success. + */ +bool Document::renameSheet(const QString &oldName, const QString &newName) +{ + Q_D(Document); + if (oldName == newName) + return false; + return d->workbook->renameSheet(sheetNames().indexOf(oldName), newName); +} + +/*! + Make a copy of the worksheet \a srcName with the new name \a distName. + Returns true if the success. + */ +bool Document::copySheet(const QString &srcName, const QString &distName) +{ + Q_D(Document); + if (srcName == distName) + return false; + return d->workbook->copySheet(sheetNames().indexOf(srcName), distName); +} + +/*! + Move the worksheet \a srcName to the new pos \a distIndex. + Returns true if the success. + */ +bool Document::moveSheet(const QString &srcName, int distIndex) +{ + Q_D(Document); + return d->workbook->moveSheet(sheetNames().indexOf(srcName), distIndex); +} + +/*! + Delete the worksheet \a name. + Returns true if current sheet was deleted successfully. + */ +bool Document::deleteSheet(const QString &name) +{ + Q_D(Document); + return d->workbook->deleteSheet(sheetNames().indexOf(name)); +} + +/*! + * \brief Return pointer of current sheet. + */ +AbstractSheet *Document::currentSheet() const +{ + Q_D(const Document); + + return d->workbook->activeSheet(); +} + +/*! + * \brief Return pointer of current worksheet. + * If the type of sheet is not AbstractSheet::ST_WorkSheet, then 0 will be returned. + */ +Worksheet *Document::currentWorksheet() const +{ + AbstractSheet *st = currentSheet(); + if (st && st->sheetType() == AbstractSheet::ST_WorkSheet) + return static_cast(st); + else + return 0; +} + +/*! + * \brief Set worksheet named \a name to be active sheet. + * Returns true if success. + */ +bool Document::selectSheet(const QString &name) +{ + Q_D(Document); + return d->workbook->setActiveSheet(sheetNames().indexOf(name)); +} + +/*! + * Returns the names of worksheets contained in current document. + */ +QStringList Document::sheetNames() const +{ + Q_D(const Document); + return d->workbook->worksheetNames(); +} + +/*! + * Save current document to the filesystem. If no name specified when + * the document constructed, a default name "book1.xlsx" will be used. + * Returns true if saved successfully. + */ +bool Document::save() const +{ + Q_D(const Document); + QString name = d->packageName.isEmpty() ? d->defaultPackageName : d->packageName; + + return saveAs(name); +} + +/*! + * Saves the document to the file with the given \a name. + * Returns true if saved successfully. + */ +bool Document::saveAs(const QString &name) const +{ + QFile file(name); + if (file.open(QIODevice::WriteOnly)) + return saveAs(&file); + return false; +} + +/*! + * \overload + * This function writes a document to the given \a device. + * + * \warning The \a device will be closed when this function returned. + */ +bool Document::saveAs(QIODevice *device) const +{ + Q_D(const Document); + return d->savePackage(device); +} + +/*! + * Destroys the document and cleans up. + */ +Document::~Document() +{ + delete d_ptr; +} + +QT_END_NAMESPACE_XLSX diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument.h new file mode 100644 index 0000000..7f1113d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_XLSXDOCUMENT_H +#define QXLSX_XLSXDOCUMENT_H + +#include "xlsxglobal.h" +#include "xlsxformat.h" +#include "xlsxworksheet.h" +#include +#include +class QIODevice; +class QImage; + +QT_BEGIN_NAMESPACE_XLSX + +class Workbook; +class Cell; +class CellRange; +class DataValidation; +class ConditionalFormatting; +class Chart; +class CellReference; + +class DocumentPrivate; +class Q_XLSX_EXPORT Document : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(Document) + +public: + explicit Document(QObject *parent = 0); + Document(const QString &xlsxName, QObject *parent=0); + Document(QIODevice *device, QObject *parent=0); + ~Document(); + + bool write(const CellReference &cell, const QVariant &value, const Format &format=Format()); + bool write(int row, int col, const QVariant &value, const Format &format=Format()); + QVariant read(const CellReference &cell) const; + QVariant read(int row, int col) const; + bool insertImage(int row, int col, const QImage &image); + Chart *insertChart(int row, int col, const QSize &size); + bool mergeCells(const CellRange &range, const Format &format=Format()); + bool unmergeCells(const CellRange &range); + + bool setColumnWidth(const CellRange &range, double width); + bool setColumnFormat(const CellRange &range, const Format &format); + bool setColumnHidden(const CellRange &range, bool hidden); + bool setColumnWidth(int column, double width); + bool setColumnFormat(int column, const Format &format); + bool setColumnHidden(int column, bool hidden); + bool setColumnWidth(int colFirst, int colLast, double width); + bool setColumnFormat(int colFirst, int colLast, const Format &format); + bool setColumnHidden(int colFirst, int colLast, bool hidden); + double columnWidth(int column); + Format columnFormat(int column); + bool isColumnHidden(int column); + + bool setRowHeight(int row, double height); + bool setRowFormat(int row, const Format &format); + bool setRowHidden(int row, bool hidden); + bool setRowHeight(int rowFirst, int rowLast, double height); + bool setRowFormat(int rowFirst, int rowLast, const Format &format); + bool setRowHidden(int rowFirst, int rowLast, bool hidden); + + double rowHeight(int row); + Format rowFormat(int row); + bool isRowHidden(int row); + + bool groupRows(int rowFirst, int rowLast, bool collapsed = true); + bool groupColumns(int colFirst, int colLast, bool collapsed = true); + bool addDataValidation(const DataValidation &validation); + bool addConditionalFormatting(const ConditionalFormatting &cf); + + Cell *cellAt(const CellReference &cell) const; + Cell *cellAt(int row, int col) const; + + bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString()); + + CellRange dimension() const; + + QString documentProperty(const QString &name) const; + void setDocumentProperty(const QString &name, const QString &property); + QStringList documentPropertyNames() const; + + QStringList sheetNames() const; + bool addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + bool insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); + bool selectSheet(const QString &name); + bool renameSheet(const QString &oldName, const QString &newName); + bool copySheet(const QString &srcName, const QString &distName = QString()); + bool moveSheet(const QString &srcName, int distIndex); + bool deleteSheet(const QString &name); + + Workbook *workbook() const; + AbstractSheet *sheet(const QString &sheetName) const; + AbstractSheet *currentSheet() const; + Worksheet *currentWorksheet() const; + + bool save() const; + bool saveAs(const QString &xlsXname) const; + bool saveAs(QIODevice *device) const; + +private: + Q_DISABLE_COPY(Document) + DocumentPrivate * const d_ptr; +}; + +QT_END_NAMESPACE_XLSX + +#endif // QXLSX_XLSXDOCUMENT_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument_p.h new file mode 100644 index 0000000..736a678 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdocument_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef XLSXDOCUMENT_P_H +#define XLSXDOCUMENT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxdocument.h" +#include "xlsxworkbook.h" +#include "xlsxcontenttypes_p.h" + +#include + +namespace QXlsx { + +class DocumentPrivate +{ + Q_DECLARE_PUBLIC(Document) +public: + DocumentPrivate(Document *p); + void init(); + + bool loadPackage(QIODevice *device); + bool savePackage(QIODevice *device) const; + + Document *q_ptr; + const QString defaultPackageName; //default name when package name not specified + QString packageName; //name of the .xlsx file + + QMap documentProperties; //core, app and custom properties + QSharedPointer workbook; + QSharedPointer contentTypes; +}; + +} + +#endif // XLSXDOCUMENT_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawing.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawing.cpp new file mode 100644 index 0000000..ae7d2d7 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawing.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxdrawing_p.h" +#include "xlsxdrawinganchor_p.h" +#include "xlsxabstractsheet.h" + +#include +#include +#include + +namespace QXlsx { + +Drawing::Drawing(AbstractSheet *sheet, CreateFlag flag) + :AbstractOOXmlFile(flag), sheet(sheet) +{ + workbook = sheet->workbook(); +} + +Drawing::~Drawing() +{ + qDeleteAll(anchors); +} + +void Drawing::saveToXmlFile(QIODevice *device) const +{ + relationships()->clear(); + + QXmlStreamWriter writer(device); + + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("xdr:wsDr")); + writer.writeAttribute(QStringLiteral("xmlns:xdr"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")); + writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); + + foreach (DrawingAnchor *anchor, anchors) + anchor->saveToXml(writer); + + writer.writeEndElement();//xdr:wsDr + writer.writeEndDocument(); +} + +bool Drawing::loadFromXmlFile(QIODevice *device) +{ + QXmlStreamReader reader(device); + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("absoluteAnchor")) { + DrawingAbsoluteAnchor * anchor = new DrawingAbsoluteAnchor(this); + anchor->loadFromXml(reader); + } else if (reader.name() == QLatin1String("oneCellAnchor")) { + DrawingOneCellAnchor * anchor = new DrawingOneCellAnchor(this); + anchor->loadFromXml(reader); + } else if (reader.name() == QLatin1String("twoCellAnchor")) { + DrawingTwoCellAnchor * anchor = new DrawingTwoCellAnchor(this); + anchor->loadFromXml(reader); + } + } + } + + return true; +} + +} // namespace QXlsx diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawing_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawing_p.h new file mode 100644 index 0000000..3afad4d --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawing_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_DRAWING_H +#define QXLSX_DRAWING_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt Xlsx API. It exists for the convenience +// of the Qt Xlsx. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "xlsxrelationships_p.h" +#include "xlsxabstractooxmlfile.h" + +#include +#include +#include + +class QIODevice; +class QXmlStreamWriter; + +namespace QXlsx { + +class DrawingAnchor; +class Workbook; +class AbstractSheet; +class MediaFile; + +class Drawing : public AbstractOOXmlFile +{ +public: + Drawing(AbstractSheet *sheet, CreateFlag flag); + ~Drawing(); + void saveToXmlFile(QIODevice *device) const; + bool loadFromXmlFile(QIODevice *device); + + AbstractSheet *sheet; + Workbook *workbook; + QList anchors; +}; + +} // namespace QXlsx + +#endif // QXLSX_DRAWING_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawinganchor.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawinganchor.cpp new file mode 100644 index 0000000..be12dc0 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawinganchor.cpp @@ -0,0 +1,529 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#include "xlsxdrawinganchor_p.h" +#include "xlsxdrawing_p.h" +#include "xlsxmediafile_p.h" +#include "xlsxchart.h" +#include "xlsxworkbook.h" +#include "xlsxutility_p.h" + +#include +#include +#include +#include + +namespace QXlsx { + +/* + The vertices that define the position of a graphical object + within the worksheet in pixels. + + +------------+------------+ + | A | B | + +-----+------------+------------+ + | |(x1,y1) | | + | 1 |(A1)._______|______ | + | | | | | + | | | | | + +-----+----| OBJECT |-----+ + | | | | | + | 2 | |______________. | + | | | (B2)| + | | | (x2,y2)| + +---- +------------+------------+ + + Example of an object that covers some of the area from cell A1 to B2. + + Based on the width and height of the object we need to calculate 8 vars: + + col_start, row_start, col_end, row_end, x1, y1, x2, y2. + + We also calculate the absolute x and y position of the top left vertex of + the object. This is required for images. + + The width and height of the cells that the object occupies can be + variable and have to be taken into account. +*/ + +//anchor + +DrawingAnchor::DrawingAnchor(Drawing *drawing, ObjectType objectType) + :m_drawing(drawing), m_objectType(objectType) +{ + m_drawing->anchors.append(this); + m_id = m_drawing->anchors.size();//must be unique in one drawing{x}.xml file. +} + +DrawingAnchor::~DrawingAnchor() +{ + +} + +void DrawingAnchor::setObjectPicture(const QImage &img) +{ + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + img.save(&buffer, "PNG"); + + m_pictureFile = QSharedPointer(new MediaFile(ba, QStringLiteral("png"), QStringLiteral("image/png"))); + m_drawing->workbook->addMediaFile(m_pictureFile); + + m_objectType = Picture; +} + +void DrawingAnchor::setObjectGraphicFrame(QSharedPointer chart) +{ + m_chartFile = chart; + m_drawing->workbook->addChartFile(chart); + + m_objectType = GraphicFrame; +} + +QPoint DrawingAnchor::loadXmlPos(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("pos")); + + QPoint pos; + QXmlStreamAttributes attrs = reader.attributes(); + pos.setX(attrs.value(QLatin1String("x")).toString().toInt()); + pos.setY(attrs.value(QLatin1String("y")).toString().toInt()); + return pos; +} + +QSize DrawingAnchor::loadXmlExt(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("ext")); + + QSize size; + QXmlStreamAttributes attrs = reader.attributes(); + size.setWidth(attrs.value(QLatin1String("cx")).toString().toInt()); + size.setHeight(attrs.value(QLatin1String("cy")).toString().toInt()); + return size; +} + +XlsxMarker DrawingAnchor::loadXmlMarker(QXmlStreamReader &reader, const QString &node) +{ + Q_ASSERT(reader.name() == node); + + int col = 0; + int colOffset = 0; + int row = 0; + int rowOffset = 0; + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("col")) { + col = reader.readElementText().toInt(); + } else if (reader.name() == QLatin1String("colOff")) { + colOffset = reader.readElementText().toInt(); + } else if (reader.name() == QLatin1String("row")) { + row = reader.readElementText().toInt(); + } else if (reader.name() == QLatin1String("rowOff")) { + rowOffset = reader.readElementText().toInt(); + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == node) { + break; + } + } + + return XlsxMarker(row, col, rowOffset, colOffset); +} + +void DrawingAnchor::loadXmlObject(QXmlStreamReader &reader) +{ + if (reader.name() == QLatin1String("sp")) { + //Shape + m_objectType = Shape; + loadXmlObjectShape(reader); + } else if (reader.name() == QLatin1String("grpSp")) { + //Group Shape + m_objectType = GroupShape; + loadXmlObjectGroupShape(reader); + } else if (reader.name() == QLatin1String("graphicFrame")) { + //Graphic Frame + m_objectType = GraphicFrame; + loadXmlObjectGraphicFrame(reader); + } else if (reader.name() == QLatin1String("cxnSp")) { + //Connection Shape + m_objectType = ConnectionShape; + loadXmlObjectConnectionShape(reader); + } else if (reader.name() == QLatin1String("pic")) { + //Picture + m_objectType = Picture; + loadXmlObjectPicture(reader); + } +} + +void DrawingAnchor::loadXmlObjectConnectionShape(QXmlStreamReader &reader) +{ + Q_UNUSED(reader) +} + +void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("graphicFrame")); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("chart")) { + QString rId = reader.attributes().value(QLatin1String("r:id")).toString(); + QString name = m_drawing->relationships()->getRelationshipById(rId).target; + QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name); + + bool exist = false; + QList > cfs = m_drawing->workbook->chartFiles(); + for (int i=0; ifilePath() == path) { + //already exist + exist = true; + m_chartFile = cfs[i]; + } + } + if (!exist) { + m_chartFile = QSharedPointer (new Chart(m_drawing->sheet, Chart::F_LoadFromExists)); + m_chartFile->setFilePath(path); + m_drawing->workbook->addChartFile(m_chartFile); + } + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QLatin1String("graphicFrame")) { + break; + } + } + + return; +} + +void DrawingAnchor::loadXmlObjectGroupShape(QXmlStreamReader &reader) +{ + Q_UNUSED(reader) +} + +void DrawingAnchor::loadXmlObjectPicture(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("pic")); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("blip")) { + QString rId = reader.attributes().value(QLatin1String("r:embed")).toString(); + QString name = m_drawing->relationships()->getRelationshipById(rId).target; + QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name); + + bool exist = false; + QList > mfs = m_drawing->workbook->mediaFiles(); + for (int i=0; ifileName() == path) { + //already exist + exist = true; + m_pictureFile = mfs[i]; + } + } + if (!exist) { + m_pictureFile = QSharedPointer (new MediaFile(path)); + m_drawing->workbook->addMediaFile(m_pictureFile, true); + } + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QLatin1String("pic")) { + break; + } + } + + return; +} + +void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) +{ + Q_UNUSED(reader) +} + +void DrawingAnchor::saveXmlPos(QXmlStreamWriter &writer, const QPoint &pos) const +{ + writer.writeEmptyElement(QStringLiteral("xdr:pos")); + writer.writeAttribute(QStringLiteral("x"), QString::number(pos.x())); + writer.writeAttribute(QStringLiteral("y"), QString::number(pos.y())); +} + +void DrawingAnchor::saveXmlExt(QXmlStreamWriter &writer, const QSize &ext) const +{ + writer.writeStartElement(QStringLiteral("xdr:ext")); + writer.writeAttribute(QStringLiteral("cx"), QString::number(ext.width())); + writer.writeAttribute(QStringLiteral("cy"), QString::number(ext.height())); + writer.writeEndElement(); //xdr:ext +} + +void DrawingAnchor::saveXmlMarker(QXmlStreamWriter &writer, const XlsxMarker &marker, const QString &node) const +{ + writer.writeStartElement(node); //xdr:from or xdr:to + writer.writeTextElement(QStringLiteral("xdr:col"), QString::number(marker.col())); + writer.writeTextElement(QStringLiteral("xdr:colOff"), QString::number(marker.colOff())); + writer.writeTextElement(QStringLiteral("xdr:row"), QString::number(marker.row())); + writer.writeTextElement(QStringLiteral("xdr:rowOff"), QString::number(marker.rowOff())); + writer.writeEndElement(); +} + +void DrawingAnchor::saveXmlObject(QXmlStreamWriter &writer) const +{ + if (m_objectType == Picture) + saveXmlObjectPicture(writer); + else if (m_objectType == ConnectionShape) + saveXmlObjectConnectionShape(writer); + else if (m_objectType == GraphicFrame) + saveXmlObjectGraphicFrame(writer); + else if (m_objectType == GroupShape) + saveXmlObjectGroupShape(writer); + else if (m_objectType == Shape) + saveXmlObjectShape(writer); +} + +void DrawingAnchor::saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const +{ + Q_UNUSED(writer) +} + +void DrawingAnchor::saveXmlObjectGraphicFrame(QXmlStreamWriter &writer) const +{ + writer.writeStartElement(QStringLiteral("xdr:graphicFrame")); + writer.writeAttribute(QStringLiteral("macro"), QString()); + + writer.writeStartElement(QStringLiteral("xdr:nvGraphicFramePr")); + writer.writeEmptyElement(QStringLiteral("xdr:cNvPr")); + writer.writeAttribute(QStringLiteral("id"), QString::number(m_id)); + writer.writeAttribute(QStringLiteral("name"),QStringLiteral("Chart %1").arg(m_id)); + writer.writeEmptyElement(QStringLiteral("xdr:cNvGraphicFramePr")); + writer.writeEndElement();//xdr:nvGraphicFramePr + + writer.writeStartElement(QStringLiteral("xdr:xfrm")); + writer.writeEndElement(); //xdr:xfrm + + writer.writeStartElement(QStringLiteral("a:graphic")); + writer.writeStartElement(QStringLiteral("a:graphicData")); + writer.writeAttribute(QStringLiteral("uri"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); + + int idx = m_drawing->workbook->chartFiles().indexOf(m_chartFile); + m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/chart"), QStringLiteral("../charts/chart%1.xml").arg(idx+1)); + + writer.writeEmptyElement(QStringLiteral("c:chart")); + writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); + writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); + + writer.writeEndElement(); //a:graphicData + writer.writeEndElement(); //a:graphic + writer.writeEndElement(); //xdr:graphicFrame +} + +void DrawingAnchor::saveXmlObjectGroupShape(QXmlStreamWriter &writer) const +{ + Q_UNUSED(writer) +} + +void DrawingAnchor::saveXmlObjectPicture(QXmlStreamWriter &writer) const +{ + Q_ASSERT(m_objectType == Picture && !m_pictureFile.isNull()); + + writer.writeStartElement(QStringLiteral("xdr:pic")); + + writer.writeStartElement(QStringLiteral("xdr:nvPicPr")); + writer.writeEmptyElement(QStringLiteral("xdr:cNvPr")); + writer.writeAttribute(QStringLiteral("id"), QString::number(m_id)); + writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Picture %1").arg(m_id)); + + writer.writeStartElement(QStringLiteral("xdr:cNvPicPr")); + writer.writeEmptyElement(QStringLiteral("a:picLocks")); + writer.writeAttribute(QStringLiteral("noChangeAspect"), QStringLiteral("1")); + writer.writeEndElement(); //xdr:cNvPicPr + + writer.writeEndElement(); //xdr:nvPicPr + + m_drawing->relationships()->addDocumentRelationship(QStringLiteral("/image"), QStringLiteral("../media/image%1.%2") + .arg(m_pictureFile->index()+1) + .arg(m_pictureFile->suffix())); + + writer.writeStartElement(QStringLiteral("xdr:blipFill")); + writer.writeEmptyElement(QStringLiteral("a:blip")); + writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + writer.writeAttribute(QStringLiteral("r:embed"), QStringLiteral("rId%1").arg(m_drawing->relationships()->count())); + writer.writeStartElement(QStringLiteral("a:stretch")); + writer.writeEmptyElement(QStringLiteral("a:fillRect")); + writer.writeEndElement(); //a:stretch + writer.writeEndElement();//xdr:blipFill + + writer.writeStartElement(QStringLiteral("xdr:spPr")); + + writer.writeStartElement(QStringLiteral("a:prstGeom")); + writer.writeAttribute(QStringLiteral("prst"), QStringLiteral("rect")); + writer.writeEmptyElement(QStringLiteral("a:avLst")); + writer.writeEndElement(); //a:prstGeom + + writer.writeEndElement(); //xdr:spPr + + writer.writeEndElement(); //xdr:pic +} + +void DrawingAnchor::saveXmlObjectShape(QXmlStreamWriter &writer) const +{ + Q_UNUSED(writer) +} + +//absolute anchor + +DrawingAbsoluteAnchor::DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType) + :DrawingAnchor(drawing, objectType) +{ + +} + +bool DrawingAbsoluteAnchor::loadFromXml(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("absoluteAnchor")); + + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("pos")) { + pos = loadXmlPos(reader); + } else if (reader.name() == QLatin1String("ext")) { + ext = loadXmlExt(reader); + } else { + loadXmlObject(reader); + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QLatin1String("absoluteAnchor")) { + break; + } + } + return true; +} + +void DrawingAbsoluteAnchor::saveToXml(QXmlStreamWriter &writer) const +{ + writer.writeStartElement(QStringLiteral("xdr:absoluteAnchor")); + saveXmlPos(writer, pos); + saveXmlExt(writer, ext); + + saveXmlObject(writer); + + writer.writeEmptyElement(QStringLiteral("xdr:clientData")); + writer.writeEndElement(); //xdr:absoluteAnchor +} + +//one cell anchor + +DrawingOneCellAnchor::DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType) + :DrawingAnchor(drawing, objectType) +{ + +} + +bool DrawingOneCellAnchor::loadFromXml(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("oneCellAnchor")); + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("from")) { + from = loadXmlMarker(reader, QLatin1String("from")); + } else if (reader.name() == QLatin1String("ext")) { + ext = loadXmlExt(reader); + } else { + loadXmlObject(reader); + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QLatin1String("oneCellAnchor")) { + break; + } + } + return true; +} + +void DrawingOneCellAnchor::saveToXml(QXmlStreamWriter &writer) const +{ + writer.writeStartElement(QStringLiteral("xdr:oneCellAnchor")); + + saveXmlMarker(writer, from, QStringLiteral("xdr:from")); + saveXmlExt(writer, ext); + + saveXmlObject(writer); + + writer.writeEmptyElement(QStringLiteral("xdr:clientData")); + writer.writeEndElement(); //xdr:oneCellAnchor +} + +/* + Two cell anchor + + This class specifies a two cell anchor placeholder for a group + , a shape, or a drawing element. It moves with + cells and its extents are in EMU units. +*/ +DrawingTwoCellAnchor::DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType) + :DrawingAnchor(drawing, objectType) +{ + +} + +bool DrawingTwoCellAnchor::loadFromXml(QXmlStreamReader &reader) +{ + Q_ASSERT(reader.name() == QLatin1String("twoCellAnchor")); + while (!reader.atEnd()) { + reader.readNextStartElement(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == QLatin1String("from")) { + from = loadXmlMarker(reader, QLatin1String("from")); + } else if (reader.name() == QLatin1String("to")) { + to = loadXmlMarker(reader, QLatin1String("to")); + } else { + loadXmlObject(reader); + } + } else if (reader.tokenType() == QXmlStreamReader::EndElement + && reader.name() == QLatin1String("twoCellAnchor")) { + break; + } + } + return true; +} + +void DrawingTwoCellAnchor::saveToXml(QXmlStreamWriter &writer) const +{ + writer.writeStartElement(QStringLiteral("xdr:twoCellAnchor")); + writer.writeAttribute(QStringLiteral("editAs"), QStringLiteral("oneCell")); + + saveXmlMarker(writer, from, QStringLiteral("xdr:from")); + saveXmlMarker(writer, to, QStringLiteral("xdr:to")); + + saveXmlObject(writer); + + writer.writeEmptyElement(QStringLiteral("xdr:clientData")); + writer.writeEndElement(); //xdr:twoCellAnchor +} + +} // namespace QXlsx diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawinganchor_p.h b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawinganchor_p.h new file mode 100644 index 0000000..2f38a91 --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxdrawinganchor_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ + +#ifndef QXLSX_XLSXDRAWINGANCHOR_P_H +#define QXLSX_XLSXDRAWINGANCHOR_P_H + +#include "xlsxglobal.h" + +#include +#include +#include +#include + +class QXmlStreamReader; +class QXmlStreamWriter; + +namespace QXlsx { + +class Drawing; +class MediaFile; +class Chart; + +//Helper class +struct XlsxMarker +{ + XlsxMarker(){} + XlsxMarker(int row, int column, int rowOffset, int colOffset) + :cell(QPoint(row, column)), offset(rowOffset, colOffset) + { + + } + + int row() const {return cell.x();} + int col() const {return cell.y();} + int rowOff() const {return offset.width();} + int colOff() const {return offset.height();} + + QPoint cell; + QSize offset; +}; + +class DrawingAnchor +{ +public: + enum ObjectType { + GraphicFrame, + Shape, + GroupShape, + ConnectionShape, + Picture, + Unknown + }; + + DrawingAnchor(Drawing *drawing, ObjectType objectType); + virtual ~DrawingAnchor(); + void setObjectPicture(const QImage &img); + void setObjectGraphicFrame(QSharedPointer chart); + + virtual bool loadFromXml(QXmlStreamReader &reader) = 0; + virtual void saveToXml(QXmlStreamWriter &writer) const = 0; + +protected: + QPoint loadXmlPos(QXmlStreamReader &reader); + QSize loadXmlExt(QXmlStreamReader &reader); + XlsxMarker loadXmlMarker(QXmlStreamReader &reader, const QString &node); + void loadXmlObject(QXmlStreamReader &reader); + void loadXmlObjectShape(QXmlStreamReader &reader); + void loadXmlObjectGroupShape(QXmlStreamReader &reader); + void loadXmlObjectGraphicFrame(QXmlStreamReader &reader); + void loadXmlObjectConnectionShape(QXmlStreamReader &reader); + void loadXmlObjectPicture(QXmlStreamReader &reader); + + void saveXmlPos(QXmlStreamWriter &writer, const QPoint &pos) const; + void saveXmlExt(QXmlStreamWriter &writer, const QSize &ext) const; + void saveXmlMarker(QXmlStreamWriter &writer, const XlsxMarker &marker, const QString &node) const; + void saveXmlObject(QXmlStreamWriter &writer) const; + void saveXmlObjectShape(QXmlStreamWriter &writer) const; + void saveXmlObjectGroupShape(QXmlStreamWriter &writer) const; + void saveXmlObjectGraphicFrame(QXmlStreamWriter &writer) const; + void saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const; + void saveXmlObjectPicture(QXmlStreamWriter &writer) const; + + Drawing *m_drawing; + ObjectType m_objectType; + QSharedPointer m_pictureFile; + QSharedPointer m_chartFile; + + int m_id; +}; + +class DrawingAbsoluteAnchor : public DrawingAnchor +{ +public: + DrawingAbsoluteAnchor(Drawing *drawing, ObjectType objectType=Unknown); + + QPoint pos; + QSize ext; + + bool loadFromXml(QXmlStreamReader &reader); + void saveToXml(QXmlStreamWriter &writer) const; +}; + +class DrawingOneCellAnchor : public DrawingAnchor +{ +public: + DrawingOneCellAnchor(Drawing *drawing, ObjectType objectType=Unknown); + + XlsxMarker from; + QSize ext; + + bool loadFromXml(QXmlStreamReader &reader); + void saveToXml(QXmlStreamWriter &writer) const; +}; + +class DrawingTwoCellAnchor : public DrawingAnchor +{ +public: + DrawingTwoCellAnchor(Drawing *drawing, ObjectType objectType=Unknown); + + XlsxMarker from; + XlsxMarker to; + + bool loadFromXml(QXmlStreamReader &reader); + void saveToXml(QXmlStreamWriter &writer) const; +}; + +} // namespace QXlsx + +#endif // QXLSX_XLSXDRAWINGANCHOR_P_H diff --git a/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxformat.cpp b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxformat.cpp new file mode 100644 index 0000000..074184f --- /dev/null +++ b/src/thirdparty/QtXlsxWriter-0.3.0/src/xlsx/xlsxformat.cpp @@ -0,0 +1,1432 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** All right reserved. +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +****************************************************************************/ +#include "xlsxformat.h" +#include "xlsxformat_p.h" +#include "xlsxcolor_p.h" +#include "xlsxnumformatparser_p.h" +#include +#include + +QT_BEGIN_NAMESPACE_XLSX + +FormatPrivate::FormatPrivate() + : dirty(true) + , font_dirty(true), font_index_valid(false), font_index(0) + , fill_dirty(true), fill_index_valid(false), fill_index(0) + , border_dirty(true), border_index_valid(false), border_index(0) + , xf_index(-1), xf_indexValid(false) + , is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false) + , theme(0) +{ +} + +FormatPrivate::FormatPrivate(const FormatPrivate &other) + : QSharedData(other) + , dirty(other.dirty), formatKey(other.formatKey) + , font_dirty(other.font_dirty), font_index_valid(other.font_index_valid), font_key(other.font_key), font_index(other.font_index) + , fill_dirty(other.fill_dirty), fill_index_valid(other.fill_index_valid), fill_key(other.fill_key), fill_index(other.fill_index) + , border_dirty(other.border_dirty), border_index_valid(other.border_index_valid), border_key(other.border_key), border_index(other.border_index) + , xf_index(other.xf_index), xf_indexValid(other.xf_indexValid) + , is_dxf_fomat(other.is_dxf_fomat), dxf_index(other.dxf_index), dxf_indexValid(other.dxf_indexValid) + , theme(other.theme) + , properties(other.properties) +{ + +} + +FormatPrivate::~FormatPrivate() +{ + +} + +/*! + * \class Format + * \inmodule QtXlsx + * \brief Providing the methods and properties that are available for formatting cells in Excel. + */ + +/*! + * \enum Format::FontScript + * + * The enum type defines the type of font script. + * + * \value FontScriptNormal normal + * \value FontScriptSuper super script + * \value FontScriptSub sub script + */ + + +/*! + * \enum Format::FontUnderline + * + * The enum type defines the type of font underline. + * + * \value FontUnderlineNone + * \value FontUnderlineSingle + * \value FontUnderlineDouble + * \value FontUnderlineSingleAccounting + * \value FontUnderlineDoubleAccounting + */ + +/*! + * \enum Format::HorizontalAlignment + * + * The enum type defines the type of horizontal alignment. + * + * \value AlignHGeneral + * \value AlignLeft + * \value AlignHCenter + * \value AlignRight + * \value AlignHFill + * \value AlignHJustify + * \value AlignHMerge + * \value AlignHDistributed + */ + +/*! + * \enum Format::VerticalAlignment + * + * The enum type defines the type of vertical alignment. + * + * \value AlignTop, + * \value AlignVCenter, + * \value AlignBottom, + * \value AlignVJustify, + * \value AlignVDistributed + */ + +/*! + * \enum Format::BorderStyle + * + * The enum type defines the type of font underline. + * + * \value BorderNone + * \value BorderThin + * \value BorderMedium + * \value BorderDashed + * \value BorderDotted + * \value BorderThick + * \value BorderDouble + * \value BorderHair + * \value BorderMediumDashed + * \value BorderDashDot + * \value BorderMediumDashDot + * \value BorderDashDotDot + * \value BorderMediumDashDotDot + * \value BorderSlantDashDot +*/ + +/*! + * \enum Format::DiagonalBorderType + * + * The enum type defines the type of diagonal border. + * + * \value DiagonalBorderNone + * \value DiagonalBorderDown + * \value DiagonalBorderUp + * \value DiagnoalBorderBoth + */ + +/*! + * \enum Format::FillPattern + * + * The enum type defines the type of fill. + * + * \value PatternNone + * \value PatternSolid + * \value PatternMediumGray + * \value PatternDarkGray + * \value PatternLightGray + * \value PatternDarkHorizontal + * \value PatternDarkVertical + * \value PatternDarkDown + * \value PatternDarkUp + * \value PatternDarkGrid + * \value PatternDarkTrellis + * \value PatternLightHorizontal + * \value PatternLightVertical + * \value PatternLightDown + * \value PatternLightUp + * \value PatternLightTrellis + * \value PatternGray125 + * \value PatternGray0625 + * \value PatternLightGrid + */ + +/*! + * Creates a new invalid format. + */ +Format::Format() +{ + //The d pointer is initialized with a null pointer +} + +/*! + Creates a new format with the same attributes as the \a other format. + */ +Format::Format(const Format &other) + :d(other.d) +{ + +} + +/*! + Assigns the \a other format to this format, and returns a + reference to this format. + */ +Format &Format::operator =(const Format &other) +{ + d = other.d; + return *this; +} + +/*! + * Destroys this format. + */ +Format::~Format() +{ +} + +/*! + * Returns the number format identifier. + */ +int Format::numberFormatIndex() const +{ + return intProperty(FormatPrivate::P_NumFmt_Id, 0); +} + +/*! + * Set the number format identifier. The \a format + * must be a valid built-in number format identifier + * or the identifier of a custom number format. + */ +void Format::setNumberFormatIndex(int format) +{ + setProperty(FormatPrivate::P_NumFmt_Id, format); + clearProperty(FormatPrivate::P_NumFmt_FormatCode); +} + +/*! + * Returns the number format string. + * \note for built-in number formats, this may + * return an empty string. + */ +QString Format::numberFormat() const +{ + return stringProperty(FormatPrivate::P_NumFmt_FormatCode); +} + +/*! + * Set number \a format. + * http://office.microsoft.com/en-001/excel-help/create-a-custom-number-format-HP010342372.aspx + */ +void Format::setNumberFormat(const QString &format) +{ + if (format.isEmpty()) + return; + setProperty(FormatPrivate::P_NumFmt_FormatCode, format); + clearProperty(FormatPrivate::P_NumFmt_Id); //numFmt id must be re-generated. +} + +/*! + * Returns whether the number format is probably a dateTime or not + */ +bool Format::isDateTimeFormat() const +{ + if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) { + //Custom numFmt, so + //Gauss from the number string + return NumFormatParser::isDateTime(numberFormat()); + } else if (hasProperty(FormatPrivate::P_NumFmt_Id)){ + //Non-custom numFmt + int idx = numberFormatIndex(); + + //Is built-in date time number id? + if ((idx >= 14 && idx <= 22) || (idx >= 45 && idx <= 47)) + return true; + + if ((idx >= 27 && idx <= 36) || (idx >= 50 && idx <= 58)) //Used in CHS\CHT\JPN\KOR + return true; + } + + return false; +} + +/*! + \internal + Set a custom num \a format with the given \a id. + */ +void Format::setNumberFormat(int id, const QString &format) +{ + setProperty(FormatPrivate::P_NumFmt_Id, id); + setProperty(FormatPrivate::P_NumFmt_FormatCode, format); +} + +/*! + \internal + Called by styles to fix the numFmt + */ +void Format::fixNumberFormat(int id, const QString &format) +{ + setProperty(FormatPrivate::P_NumFmt_Id, id, 0, false); + setProperty(FormatPrivate::P_NumFmt_FormatCode, format, QString(), false); +} + +/*! + \internal + Return true if the format has number format. + */ +bool Format::hasNumFmtData() const +{ + if (!d) + return false; + + if (hasProperty(FormatPrivate::P_NumFmt_Id) + || hasProperty(FormatPrivate::P_NumFmt_FormatCode)) { + return true; + } + return false; +} + +/*! + * Return the size of the font in points. + */ +int Format::fontSize() const +{ + return intProperty(FormatPrivate::P_Font_Size); +} + +/*! + * Set the \a size of the font in points. + */ +void Format::setFontSize(int size) +{ + setProperty(FormatPrivate::P_Font_Size, size, 0); +} + +/*! + * Return whether the font is italic. + */ +bool Format::fontItalic() const +{ + return boolProperty(FormatPrivate::P_Font_Italic); +} + +/*! + * Turn on/off the italic font based on \a italic. + */ +void Format::setFontItalic(bool italic) +{ + setProperty(FormatPrivate::P_Font_Italic, italic, false); +} + +/*! + * Return whether the font is strikeout. + */ +bool Format::fontStrikeOut() const +{ + return boolProperty(FormatPrivate::P_Font_StrikeOut); +} + +/*! + * Turn on/off the strikeOut font based on \a strikeOut. + */ +void Format::setFontStrikeOut(bool strikeOut) +{ + setProperty(FormatPrivate::P_Font_StrikeOut, strikeOut, false); +} + +/*! + * Return the color of the font. + */ +QColor Format::fontColor() const +{ + if (hasProperty(FormatPrivate::P_Font_Color)) + return colorProperty(FormatPrivate::P_Font_Color); + return QColor(); +} + +/*! + * Set the \a color of the font. + */ +void Format::setFontColor(const QColor &color) +{ + setProperty(FormatPrivate::P_Font_Color, XlsxColor(color), XlsxColor()); +} + +/*! + * Return whether the font is bold. + */ +bool Format::fontBold() const +{ + return boolProperty(FormatPrivate::P_Font_Bold); +} + +/*! + * Turn on/off the bold font based on the given \a bold. + */ +void Format::setFontBold(bool bold) +{ + setProperty(FormatPrivate::P_Font_Bold, bold, false); +} + +/*! + * Return the script style of the font. + */ +Format::FontScript Format::fontScript() const +{ + return static_cast(intProperty(FormatPrivate::P_Font_Script)); +} + +/*! + * Set the script style of the font to \a script. + */ +void Format::setFontScript(FontScript script) +{ + setProperty(FormatPrivate::P_Font_Script, script, FontScriptNormal); +} + +/*! + * Return the underline style of the font. + */ +Format::FontUnderline Format::fontUnderline() const +{ + return static_cast(intProperty(FormatPrivate::P_Font_Underline)); +} + +/*! + * Set the underline style of the font to \a underline. + */ +void Format::setFontUnderline(FontUnderline underline) +{ + setProperty(FormatPrivate::P_Font_Underline, underline, FontUnderlineNone); +} + +/*! + * Return whether the font is outline. + */ +bool Format::fontOutline() const +{ + return boolProperty(FormatPrivate::P_Font_Outline); +} + +/*! + * Turn on/off the outline font based on \a outline. + */ +void Format::setFontOutline(bool outline) +{ + setProperty(FormatPrivate::P_Font_Outline, outline, false); +} + +/*! + * Return the name of the font. + */ +QString Format::fontName() const +{ + return stringProperty(FormatPrivate::P_Font_Name, QStringLiteral("Calibri")); +} + +/*! + * Set the name of the font to \a name. + */ +void Format::setFontName(const QString &name) +{ + setProperty(FormatPrivate::P_Font_Name, name, QStringLiteral("Calibri")); +} + +/*! + * Returns a QFont object based on font data contained in the format. + */ +QFont Format::font() const +{ + QFont font; + font.setFamily(fontName()); + if (fontSize() > 0) + font.setPointSize(fontSize()); + font.setBold(fontBold()); + font.setItalic(fontItalic()); + font.setUnderline(fontUnderline()!=FontUnderlineNone); + font.setStrikeOut(fontStrikeOut()); + return font; +} + +/*! + * Set the format properties from the given \a font. + */ +void Format::setFont(const QFont &font) +{ + setFontName(font.family()); + if (font.pointSize() > 0) + setFontSize(font.pointSize()); + setFontBold(font.bold()); + setFontItalic(font.italic()); + setFontUnderline(font.underline() ? FontUnderlineSingle : FontUnderlineNone); + setFontStrikeOut(font.strikeOut()); +} + +/*! + * \internal + * When the format has font data, when need to assign a valid index for it. + * The index value is depend on the order in styles.xml + */ +bool Format::fontIndexValid() const +{ + if (!hasFontData()) + return false; + return d->font_index_valid; +} + +/*! + * \internal + */ +int Format::fontIndex() const +{ + if (fontIndexValid()) + return d->font_index; + + return 0; +} + +/*! + * \internal + */ +void Format::setFontIndex(int index) +{ + d->font_index = index; + d->font_index_valid = true; +} + +/*! + * \internal + */ +QByteArray Format::fontKey() const +{ + if (isEmpty()) + return QByteArray(); + + if (d->font_dirty) { + QByteArray key; + QDataStream stream(&key, QIODevice::WriteOnly); + for (int i=FormatPrivate::P_Font_STARTID; iproperties.contains(i)) + stream << i << d->properties[i]; + }; + + const_cast(this)->d->font_key = key; + const_cast(this)->d->font_dirty = false; + } + + return d->font_key; +} + +/*! + \internal + Return true if the format has font format, otherwise return false. + */ +bool Format::hasFontData() const +{ + if (!d) + return false; + + for (int i=FormatPrivate::P_Font_STARTID; i(intProperty(FormatPrivate::P_Alignment_AlignH, AlignHGeneral)); +} + +/*! + * Set the horizontal alignment with the given \a align. + */ +void Format::setHorizontalAlignment(HorizontalAlignment align) +{ + if (hasProperty(FormatPrivate::P_Alignment_Indent) + &&(align != AlignHGeneral && align != AlignLeft && align != AlignRight && align != AlignHDistributed)) { + clearProperty(FormatPrivate::P_Alignment_Indent); + } + + if (hasProperty(FormatPrivate::P_Alignment_ShinkToFit) + && (align == AlignHFill || align == AlignHJustify || align == AlignHDistributed)) { + clearProperty(FormatPrivate::P_Alignment_ShinkToFit); + } + + setProperty(FormatPrivate::P_Alignment_AlignH, align, AlignHGeneral); +} + +/*! + * Return the vertical alignment. + */ +Format::VerticalAlignment Format::verticalAlignment() const +{ + return static_cast(intProperty(FormatPrivate::P_Alignment_AlignV, AlignBottom)); +} + +/*! + * Set the vertical alignment with the given \a align. + */ +void Format::setVerticalAlignment(VerticalAlignment align) +{ + setProperty(FormatPrivate::P_Alignment_AlignV, align, AlignBottom); +} + +/*! + * Return whether the cell text is wrapped. + */ +bool Format::textWrap() const +{ + return boolProperty(FormatPrivate::P_Alignment_Wrap); +} + +/*! + * Enable the text wrap if \a wrap is true. + */ +void Format::setTextWarp(bool wrap) +{ + if (wrap && hasProperty(FormatPrivate::P_Alignment_ShinkToFit)) + clearProperty(FormatPrivate::P_Alignment_ShinkToFit); + + setProperty(FormatPrivate::P_Alignment_Wrap, wrap, false); +} + +/*! + * Return the text rotation. + */ +int Format::rotation() const +{ + return intProperty(FormatPrivate::P_Alignment_Rotation); +} + +/*! + * Set the text roation with the given \a rotation. Must be in the range [0, 180] or 255. + */ +void Format::setRotation(int rotation) +{ + setProperty(FormatPrivate::P_Alignment_Rotation, rotation, 0); +} + +/*! + * Return the text indentation level. + */ +int Format::indent() const +{ + return intProperty(FormatPrivate::P_Alignment_Indent); +} + +/*! + * Set the text indentation level with the given \a indent. Must be less than or equal to 15. + */ +void Format::setIndent(int indent) +{ + if (indent && hasProperty(FormatPrivate::P_Alignment_AlignH)) { + HorizontalAlignment hl = horizontalAlignment(); + + if (hl != AlignHGeneral && hl != AlignLeft && hl!= AlignRight && hl!= AlignHJustify) { + setHorizontalAlignment(AlignLeft); + } + } + + setProperty(FormatPrivate::P_Alignment_Indent, indent, 0); +} + +/*! + * Return whether the cell is shrink to fit. + */ +bool Format::shrinkToFit() const +{ + return boolProperty(FormatPrivate::P_Alignment_ShinkToFit); +} + +/*! + * Turn on/off shrink to fit base on \a shink. + */ +void Format::setShrinkToFit(bool shink) +{ + if (shink && hasProperty(FormatPrivate::P_Alignment_Wrap)) + clearProperty(FormatPrivate::P_Alignment_Wrap); + + if (shink && hasProperty(FormatPrivate::P_Alignment_AlignH)) { + HorizontalAlignment hl = horizontalAlignment(); + if (hl == AlignHFill || hl == AlignHJustify || hl == AlignHDistributed) + setHorizontalAlignment(AlignLeft); + } + + setProperty(FormatPrivate::P_Alignment_ShinkToFit, shink, false); +} + +/*! + * \internal + */ +bool Format::hasAlignmentData() const +{ + if (!d) + return false; + + for (int i=FormatPrivate::P_Alignment_STARTID; i(intProperty(FormatPrivate::P_Border_LeftStyle)); +} + +/*! + * Sets the left border style to \a style + */ +void Format::setLeftBorderStyle(BorderStyle style) +{ + setProperty(FormatPrivate::P_Border_LeftStyle, style, BorderNone); +} + +/*! + * Returns the left border color + */ +QColor Format::leftBorderColor() const +{ + return colorProperty(FormatPrivate::P_Border_LeftColor); +} + +/*! + Sets the left border color to the given \a color +*/ +void Format::setLeftBorderColor(const QColor &color) +{ + setProperty(FormatPrivate::P_Border_LeftColor, XlsxColor(color), XlsxColor()); +} + +/*! + Returns the right border style. +*/ +Format::BorderStyle Format::rightBorderStyle() const +{ + return static_cast(intProperty(FormatPrivate::P_Border_RightStyle)); +} + +/*! + Sets the right border style to the given \a style. +*/ +void Format::setRightBorderStyle(BorderStyle style) +{ + setProperty(FormatPrivate::P_Border_RightStyle, style, BorderNone); +} + +/*! + Returns the right border color. +*/ +QColor Format::rightBorderColor() const +{ + return colorProperty(FormatPrivate::P_Border_RightColor); +} + +/*! + Sets the right border color to the given \a color +*/ +void Format::setRightBorderColor(const QColor &color) +{ + setProperty(FormatPrivate::P_Border_RightColor, XlsxColor(color), XlsxColor()); +} + +/*! + Returns the top border style. +*/ +Format::BorderStyle Format::topBorderStyle() const +{ + return static_cast(intProperty(FormatPrivate::P_Border_TopStyle)); +} + +/*! + Sets the top border style to the given \a style. +*/ +void Format::setTopBorderStyle(BorderStyle style) +{ + setProperty(FormatPrivate::P_Border_TopStyle, style, BorderNone); +} + +/*! + Returns the top border color. +*/ +QColor Format::topBorderColor() const +{ + return colorProperty(FormatPrivate::P_Border_TopColor); +} + +/*! + Sets the top border color to the given \a color. +*/ +void Format::setTopBorderColor(const QColor &color) +{ + setProperty(FormatPrivate::P_Border_TopColor, XlsxColor(color), XlsxColor()); +} + +/*! + Returns the bottom border style. +*/ +Format::BorderStyle Format::bottomBorderStyle() const +{ + return static_cast(intProperty(FormatPrivate::P_Border_BottomStyle)); +} + +/*! + Sets the bottom border style to the given \a style. +*/ +void Format::setBottomBorderStyle(BorderStyle style) +{ + setProperty(FormatPrivate::P_Border_BottomStyle, style, BorderNone); +} + +/*! + Returns the bottom border color. +*/ +QColor Format::bottomBorderColor() const +{ + return colorProperty(FormatPrivate::P_Border_BottomColor); +} + +/*! + Sets the bottom border color to the given \a color. +*/ +void Format::setBottomBorderColor(const QColor &color) +{ + setProperty(FormatPrivate::P_Border_BottomColor, XlsxColor(color), XlsxColor()); +} + +/*! + Return the diagonla border style. +*/ +Format::BorderStyle Format::diagonalBorderStyle() const +{ + return static_cast(intProperty(FormatPrivate::P_Border_DiagonalStyle)); +} + +/*! + Sets the diagonal border style to the given \a style. +*/ +void Format::setDiagonalBorderStyle(BorderStyle style) +{ + setProperty(FormatPrivate::P_Border_DiagonalStyle, style, BorderNone); +} + +/*! + Returns the diagonal border type. +*/ +Format::DiagonalBorderType Format::diagonalBorderType() const +{ + return static_cast(intProperty(FormatPrivate::P_Border_DiagonalType)); +} + +/*! + Sets the diagonal border type to the given \a style +*/ +void Format::setDiagonalBorderType(DiagonalBorderType style) +{ + setProperty(FormatPrivate::P_Border_DiagonalType, style, DiagonalBorderNone); +} + +/*! + Returns the diagonal border color. +*/ +QColor Format::diagonalBorderColor() const +{ + return colorProperty(FormatPrivate::P_Border_DiagonalColor); +} + +/*! + Sets the diagonal border color to the given \a color +*/ +void Format::setDiagonalBorderColor(const QColor &color) +{ + setProperty(FormatPrivate::P_Border_DiagonalColor, XlsxColor(color), XlsxColor()); +} + +/*! + \internal + Returns whether this format has been set valid border index. +*/ +bool Format::borderIndexValid() const +{ + if (!hasBorderData()) + return false; + return d->border_index_valid; +} + +/*! + \internal + Returns the border index. +*/ +int Format::borderIndex() const +{ + if (borderIndexValid()) + return d->border_index; + return 0; +} + +/*! + * \internal + */ +void Format::setBorderIndex(int index) +{ + d->border_index = index; + d->border_index_valid = true; +} + +/*! \internal + */ +QByteArray Format::borderKey() const +{ + if (isEmpty()) + return QByteArray(); + + if (d->border_dirty) { + QByteArray key; + QDataStream stream(&key, QIODevice::WriteOnly); + for (int i=FormatPrivate::P_Border_STARTID; iproperties.contains(i)) + stream << i << d->properties[i]; + }; + + const_cast(this)->d->border_key = key; + const_cast(this)->d->border_dirty = false; + } + + return d->border_key; +} + +/*! + \internal + Return true if the format has border format, otherwise return false. + */ +bool Format::hasBorderData() const +{ + if (!d) + return false; + + for (int i=FormatPrivate::P_Border_STARTID; i(intProperty(FormatPrivate::P_Fill_Pattern, PatternNone)); +} + +/*! + Sets the fill pattern to the given \a pattern. +*/ +void Format::setFillPattern(FillPattern pattern) +{ + setProperty(FormatPrivate::P_Fill_Pattern, pattern, PatternNone); +} + +/*! + Returns the foreground color of the pattern. +*/ +QColor Format::patternForegroundColor() const +{ + return colorProperty(FormatPrivate::P_Fill_FgColor); +} + +/*! + Sets the foreground color of the pattern with the given \a color. +*/ +void Format::setPatternForegroundColor(const QColor &color) +{ + if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) + setFillPattern(PatternSolid); + setProperty(FormatPrivate::P_Fill_FgColor, XlsxColor(color), XlsxColor()); +} + +/*! + Returns the background color of the pattern. +*/ +QColor Format::patternBackgroundColor() const +{ + return colorProperty(FormatPrivate::P_Fill_BgColor); +} + +/*! + Sets the background color of the pattern with the given \a color. +*/ +void Format::setPatternBackgroundColor(const QColor &color) +{ + if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) + setFillPattern(PatternSolid); + setProperty(FormatPrivate::P_Fill_BgColor, XlsxColor(color), XlsxColor()); +} + +/*! + * \internal + */ +bool Format::fillIndexValid() const +{ + if (!hasFillData()) + return false; + return d->fill_index_valid; +} + +/*! + * \internal + */ +int Format::fillIndex() const +{ + if (fillIndexValid()) + return d->fill_index; + return 0; +} + +/*! + * \internal + */ +void Format::setFillIndex(int index) +{ + d->fill_index = index; + d->fill_index_valid = true; +} + +/*! + * \internal + */ +QByteArray Format::fillKey() const +{ + if (isEmpty()) + return QByteArray(); + + if (d->fill_dirty) { + QByteArray key; + QDataStream stream(&key, QIODevice::WriteOnly); + for (int i=FormatPrivate::P_Fill_STARTID; iproperties.contains(i)) + stream << i << d->properties[i]; + }; + + const_cast(this)->d->fill_key = key; + const_cast(this)->d->fill_dirty = false; + } + + return d->fill_key; +} + +/*! + \internal + Return true if the format has fill format, otherwise return false. + */ +bool Format::hasFillData() const +{ + if (!d) + return false; + + for (int i=FormatPrivate::P_Fill_STARTID; i