2025-04-12T21:02:36

This commit is contained in:
123 2025-04-12 21:02:37 +08:00
parent ff4030fe5f
commit d82003e707
199 changed files with 22191 additions and 135 deletions

Binary file not shown.

View File

@ -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

View File

@ -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<ExperimentData> &dataVtr)
void readExperimentFile(const QString fileName, QVector<Global::ExperimentData> &dataVtr)
{
if(fileName.isEmpty()){
return;
@ -90,7 +90,7 @@ void readExperimentFile(const QString fileName, QVector<ExperimentData> &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);

View File

@ -3,9 +3,11 @@
#include <QString>
#include <QFile>
#include <qdir.h>
#include <QVector>
#include <QDir>
#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<ExperimentData>&);
void readExperimentFile(const QString fileName,QVector<Global::ExperimentData>&);
void test();
};

View File

@ -3,11 +3,11 @@
#include "pointcalculate.h"
#include "logger.h"
QVector<FileManager::ExperimentData>PointCalculate:: _dataVtr;
QVector<Global::ExperimentData>PointCalculate:: _dataVtr;
QPointF PointCalculate::_peakPoint;
QPointF PointCalculate::_leftSelectedPoint,PointCalculate::_rightSelectedPoint;
void PointCalculate::setExperimentData(const QVector<FileManager::ExperimentData> &dataVtr)
void PointCalculate::setExperimentData(const QVector<Global::ExperimentData> &dataVtr)
{
_dataVtr = dataVtr;
@ -15,8 +15,8 @@ void PointCalculate::setExperimentData(const QVector<FileManager::ExperimentData
return;
}
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);
_leftSelectedPoint = QPointF(startPoint.sampleTemp,startPoint.dsc);
_rightSelectedPoint = QPointF(endPoint.sampleTemp,endPoint.dsc);
@ -197,7 +197,7 @@ void PointCalculate::setRegionPointX(const float left, const float right)
QVector<QPointF> PointCalculate::getPeakPointGroup()
{
QVector<QPointF> 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<float,float> PointCalculate::getCurveInflectionPointTangent(const float x1,const float x2)
{
std::vector<float> 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<float>::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<QPointF, QPointF> 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,QPointF>(
QPointF(startPoint.sampleTemp,startPoint.dsc),
@ -457,7 +457,7 @@ QPointF PointCalculate::getClosestPointByY(const float left,const float right,co
float minValue = std::numeric_limits<float>::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) {

View File

@ -6,7 +6,7 @@
#include "filemanager.h"
namespace PointCalculate{
void setExperimentData(const QVector<FileManager::ExperimentData>&);
void setExperimentData(const QVector<Global::ExperimentData>&);
QPair<QPointF,QPointF> getStartAndEndPoint();
@ -51,7 +51,7 @@ QPointF calculateIntersection(const QPointF p1,const QPointF p2,
QVector<QPointF> getPeakPointGroup();
std::vector<float> movingAverage(const std::vector<float>& data, int windowSize);
extern QVector<FileManager::ExperimentData> _dataVtr;
extern QVector<Global::ExperimentData> _dataVtr;
extern QPointF _peakPoint;
extern QPointF _leftSelectedPoint,_rightSelectedPoint;
}

71
src/data/xlsxhandler.cpp Normal file
View File

@ -0,0 +1,71 @@
#include "xlsxhandler.h"
#include "global.h"
#include "logger.h"
void XlsxHandler::test()
{
QString sourceFilePath = QDir::currentPath() + "/sample.xlsx";
qDebug()<<"fileName:"<<sourceFilePath;
readFile(sourceFilePath);
}
void XlsxHandler::readFile(const QString sourceFilePath)
{
// 检查文件是否存在
if (!QFile::exists(sourceFilePath)) {
qDebug() << "文件不存在:" << sourceFilePath;
return ;
}
// 尝试打开文件
QXlsx::Document xlsx(sourceFilePath);
#if 0
// 获取所有工作表名称
QStringList sheetNames = xlsx.sheetNames();
qDebug() << "工作表名称:" << sheetNames;
#endif
QXlsx::Worksheet *workSheet = xlsx.currentWorksheet();
if (!workSheet) {
qDebug() << "当前工作表为空。";
return;
}
// 获取工作表的行数和列数
int rowCount = workSheet->dimension().rowCount();
int colCount = workSheet->dimension().columnCount();
qDebug() << "row:" << rowCount << "col:" << colCount;
logde<<"0:"<<workSheet->cellAt(1, 1)->value().toString().toStdString();
qDebug()<<workSheet->cellAt(1, 1)->value().toString();
int index = 2;
Global::ExperimentInfo ei;
ei.sampleName = workSheet->cellAt(index++, 2)->value().toString();
logde<<"sample name:"<<ei.sampleName.toStdString();
// return;
ei.sampleWeight = workSheet->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<Phase> 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
}

15
src/data/xlsxhandler.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef XLSXHANDLER_H
#define XLSXHANDLER_H
#include <QtCore>
#include "xlsxdocument.h"
#include "protocol.h"
namespace XlsxHandler {
void test();
void readFile(const QString filePath);
void readPhaseData(QXlsx::Worksheet*,Phase&);
}
#endif // XLSX_H

View File

@ -1,11 +1,11 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#ifndef __GLOBAL_H
#define __GLOBAL_H
#include <qobject.h>
#include <qfile.h>
#include <qcustomplot.h>
#include "filemanager.h"
//#include "filemanager.h"
class Global:public QObject
{
@ -34,7 +34,27 @@ public:
DeviceConnectionStatus getDeviceConnectionStatus(){return _deviceConnectStatus;}
#endif
QVector<QPair<QCPCurve*,QVector<FileManager::ExperimentData>>> _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<QPair<QCPCurve*,QVector<Global::ExperimentData>>> _curveDataVtr;
signals:
void sigModeModify(const Mode);

View File

@ -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();

View File

@ -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

View File

@ -0,0 +1,6 @@
#Workaround for Issue #60
CONFIG += git_build
load(qt_build_config)
MODULE_VERSION = 0.3.0

View File

@ -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 <QtXlsx>
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

View File

@ -0,0 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = xlsx

View File

@ -0,0 +1,9 @@
TARGET = calendar
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,145 @@
#include <QtCore>
#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<dow; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
}
} else if (day == date.daysInMonth() && dow != 7) {//Last day
for (int i=dow+1; i<=7; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
}
}
if (dow == 7)
rownum++;
}
}
xlsx.saveAs("Book1.xlsx");
//Make sure that read/write works well.
Document xlsx2("Book1.xlsx");
xlsx2.saveAs("Book2.xlsx");
return 0;
}

View File

@ -0,0 +1,9 @@
TARGET = chart
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,78 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = chartsheet
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,32 @@
#include <QtCore>
#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<Chartsheet*>(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;
}

View File

@ -0,0 +1,9 @@
TARGET = hello
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -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.
*/

View File

@ -0,0 +1,76 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = datavalidation
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,22 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = definename
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,33 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = demo
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

View File

@ -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
*/

View File

@ -0,0 +1,296 @@
#include <QtCore>
#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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -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.
*/

View File

@ -0,0 +1,10 @@
TARGET = ducumentproperty
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,20 @@
#include <QtCore>
#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;
}

View File

@ -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
*/

View File

@ -0,0 +1,9 @@
TARGET = extractdata
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,41 @@
#include <QtCore>
#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()<<xlsx.read("A1");
qDebug()<<xlsx.read("A2");
qDebug()<<xlsx.read("A3");
qDebug()<<xlsx.read("A4");
qDebug()<<xlsx.read("A5");
qDebug()<<xlsx.read("A6");
qDebug()<<xlsx.read("A7");
//![1]
//![2]
for (int row=1; row<10; ++row) {
if (QXlsx::Cell *cell=xlsx.cellAt(row, 1))
qDebug()<<cell->value();
}
//![2]
return 0;
}

View File

@ -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
*/

View File

@ -0,0 +1,9 @@
TARGET = hello
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,92 @@
#include <QtCore>
#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<Worksheet*>(xlsx2.sheet("SharedFormula"));
for (int row=2; row<20; ++row) {
qDebug()<<sharedFormulaSheet->read(row, 4);
}
xlsx2.saveAs("Book2.xlsx");
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -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
*/

View File

@ -0,0 +1,9 @@
TARGET = hello
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,25 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = hyperlinks
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,25 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = image
#include(../../../src/xlsx/qtxlsx.pri)
QT += xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,19 @@
#include <QtGui>
#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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -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
*/

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
TARGET = mergecells
#include(../../../src/xlsx/qtxlsx.pri)
QT += xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,52 @@
#include <QtGui>
#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<numFormats.size(); ++i) {
int row = i+2;
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFormats[i]);
QXlsx::Format format;
format.setNumberFormat(numFormats[i]);
xlsx.write(row, 3, 100.0, format);
}
//Builtin number formats
xlsx.addSheet();
xlsx.setColumnWidth(1, 4, 20.0);
xlsx.write(1, 1, "Raw data", header);
xlsx.write(1, 2, "Builtin Format", header);
xlsx.write(1, 3, "Shown value", header);
for (int i=0; i<50; ++i) {
int row = i+2;
int numFmt = i;
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFmt);
QXlsx::Format format;
format.setNumberFormatIndex(numFmt);
xlsx.write(row, 3, 100.0, format);
}
xlsx.save();
return 0;
}

View File

@ -0,0 +1,12 @@
TARGET = mergecells
#include(../../../src/xlsx/qtxlsx.pri)
QT += xlsx
TARGET = numberformat
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -0,0 +1,11 @@
/*!
\example richtext
\title Rich Text 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 richtext.png
*/

View File

@ -0,0 +1,43 @@
#include <QtCore>
#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", "<b>Hello</b> <font color=\"red\">Qt</font> <i>Xlsx</i>");
xlsx.write("B6", "<font color=\"red\"><b><u><i>Qt Xlsx</i></u></b></font>");
//![1]
//![2]
xlsx.saveAs("Test1.xlsx");
//![2]
QXlsx::Document("Test1.xlsx");
xlsx.saveAs("Test2.xlsx");
return 0;
}

View File

@ -0,0 +1,9 @@
TARGET = hello
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -0,0 +1,38 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = image
#include(../../../src/xlsx/qtxlsx.pri)
QT += xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -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.
*/

View File

@ -0,0 +1,48 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = style
#include(../../../src/xlsx/qtxlsx.pri)
QT += xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -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.
*/

View File

@ -0,0 +1,53 @@
#include <QtCore>
#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;
}

View File

@ -0,0 +1,9 @@
TARGET = worksheetoperations
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp

View File

@ -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

View File

@ -0,0 +1,41 @@
#include <QtWidgets>
#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<Worksheet *>(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();
}

View File

@ -0,0 +1,205 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QBrush>
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

View File

@ -0,0 +1,63 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QAbstractTableModel>
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

View File

@ -0,0 +1,56 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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

View File

@ -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

View File

@ -0,0 +1 @@
load(qt_parts)

View File

@ -0,0 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = xlsx

View File

@ -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 = \
" </div>\n" \
" </div>\n" \
" </div>\n" \
" </div>\n" \
"</div>\n" \
"<div class=\"footer\">\n" \
" <div class=\"qt13a-copyright\" id=\"copyright\">\n" \
" <div class=\"qt13a-container\">\n" \
" <p>\n" \
" <acronym title=\"Copyright\">&copy;</acronym> 2013-2014 Debao Zhang. \n" \
" Documentation contributions included herein are the copyrights of\n" \
" their respective owners.</p>\n" \
" <p>\n" \
" The documentation provided herein is licensed under the terms of the\n" \
" <a href=\"http://www.gnu.org/licenses/fdl.html\">GNU Free Documentation\n" \
" License version 1.3</a> as published by the Free Software Foundation.</p>\n" \
" <p>\n" \
" Documentation sources may be obtained from <a href=\"https://github.com/dbzhang800/QtXlsxWriter\">\n" \
" github.com/dbzhang800</a>.</p>\n" \
" <p>\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. <a title=\"Privacy Policy\"\n" \
" href=\"http://en.gitorious.org/privacy_policy/\">Privacy Policy</a></p>\n" \
" </div>\n" \
" </div>\n" \
"</div>\n" \

View File

@ -0,0 +1,8 @@
//! [0]
#include <QtXlsx>
//! [0]
//! [1]
#include <QtXlsx>
//! [1]

View File

@ -0,0 +1,3 @@
#! [1]
QT += xlsx
#! [1]

View File

@ -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:
*/

View File

@ -0,0 +1,72 @@
/****************************************************************************
** Copyright (c) 2013 Debao Zhang <hello@debao.me>
** 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 <QtXlsx>
\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
*/

View File

@ -0,0 +1,36 @@
/****************************************************************************
** Copyright (c) 2013 Debao Zhang <hello@debao.me>
** 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.
*/

View File

@ -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
*/

View File

@ -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

View File

@ -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 <hello@debao.me>"
QMAKE_TARGET_DESCRIPTION = ".Xlsx file wirter for Qt5"

View File

@ -0,0 +1,119 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QBuffer>
#include <QByteArray>
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

View File

@ -0,0 +1,70 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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

View File

@ -0,0 +1,64 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QString>
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

View File

@ -0,0 +1,206 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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

View File

@ -0,0 +1,76 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QStringList>
#include <QSharedPointer>
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

View File

@ -0,0 +1,64 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QSharedPointer>
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> drawing;
QString name;
int id;
AbstractSheet::SheetState sheetState;
AbstractSheet::SheetType type;
};
}
#endif // XLSXABSTRACTSHEET_P_H

View File

@ -0,0 +1,178 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QDateTime>
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

View File

@ -0,0 +1,77 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QVariant>
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

View File

@ -0,0 +1,69 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QList>
#include <QSharedPointer>
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

View File

@ -0,0 +1,259 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QXmlStreamReader>
#include <QXmlStreamWriter>
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

View File

@ -0,0 +1,78 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QExplicitlySharedDataPointer>
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<CellFormulaPrivate> d;
};
QT_END_NAMESPACE_XLSX
#endif // QXLSX_XLSXCELLFORMULA_H

View File

@ -0,0 +1,64 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QSharedData>
#include <QString>
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

View File

@ -0,0 +1,147 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QString>
#include <QPoint>
#include <QStringList>
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

View File

@ -0,0 +1,79 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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

View File

@ -0,0 +1,174 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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 <QStringList>
#include <QMap>
#include <QRegularExpression>
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<int, QString> 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

View File

@ -0,0 +1,66 @@
/****************************************************************************
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
** 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

Some files were not shown because too many files have changed in this diff Show More