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

70 lines
1.5 KiB
C++
Raw Normal View History

2020-02-07 20:55:00 +09:00
// main.cpp
#include <iostream>
2020-02-07 20:55:00 +09:00
#include <QColor>
#include <QCoreApplication>
2020-02-07 20:55:00 +09:00
#include <QDebug>
#include <QDir>
#include <QVariant>
#include <QtCore>
#include <QtGlobal>
2020-02-07 20:55:00 +09:00
using namespace std;
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxchartsheet.h"
#include "xlsxdocument.h"
2020-02-07 20:55:00 +09:00
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
void printColor(Cell *cell);
void saveColor(Cell *cell);
2020-02-07 20:55:00 +09:00
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Document xlsxR(":/color.xlsx");
if (!xlsxR.load()) {
2020-02-07 20:55:00 +09:00
return (-1);
}
printColor(xlsxR.cellAt(1, 1));
printColor(xlsxR.cellAt(1, 2));
printColor(xlsxR.cellAt(2, 1));
printColor(xlsxR.cellAt(2, 2));
2020-02-07 20:55:00 +09:00
xlsxR.write(3, 3, QVariant("HELLO"));
saveColor(xlsxR.cellAt(3, 3));
2020-10-11 15:52:21 +09:00
xlsxR.saveAs("color2.xlsx");
2020-02-07 20:55:00 +09:00
return 0;
}
void printColor(Cell *cell)
2020-02-07 20:55:00 +09:00
{
if (NULL == cell)
2020-02-07 20:55:00 +09:00
return;
QColor clrForeGround = cell->format().patternForegroundColor();
QColor clrBackGround = cell->format().patternBackgroundColor();
2020-02-07 20:55:00 +09:00
if (clrForeGround.isValid() && clrBackGround.isValid()) {
qDebug() << "[debug] color : " << clrForeGround << clrBackGround;
}
2020-10-11 15:52:21 +09:00
}
void saveColor(Cell *cell)
2020-10-11 15:52:21 +09:00
{
cell->format().setVerticalAlignment(QXlsx::Format::AlignVCenter);
cell->format().setHorizontalAlignment(QXlsx::Format::AlignHCenter);
cell->format().setFont(QFont("Calibri"));
// fmt->setTextWarp(false);
cell->format().setPatternBackgroundColor(Qt::blue);
cell->format().setPatternForegroundColor(Qt::white);
2020-02-07 20:55:00 +09:00
}