2020-02-07 20:55:00 +09:00
|
|
|
// main.cpp
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
#include <iostream>
|
|
|
|
|
2020-02-07 20:55:00 +09:00
|
|
|
#include <QColor>
|
2023-09-04 00:46:33 -03:00
|
|
|
#include <QCoreApplication>
|
2020-02-07 20:55:00 +09:00
|
|
|
#include <QDebug>
|
2023-09-04 00:46:33 -03:00
|
|
|
#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"
|
2023-09-04 00:46:33 -03:00
|
|
|
#include "xlsxchartsheet.h"
|
|
|
|
#include "xlsxdocument.h"
|
2020-02-07 20:55:00 +09:00
|
|
|
#include "xlsxrichstring.h"
|
|
|
|
#include "xlsxworkbook.h"
|
|
|
|
using namespace QXlsx;
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
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");
|
2023-09-04 00:46:33 -03:00
|
|
|
if (!xlsxR.load()) {
|
2020-02-07 20:55:00 +09:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
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
|
|
|
|
2023-09-04 00:46:33 -03: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;
|
|
|
|
}
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
void printColor(Cell *cell)
|
2020-02-07 20:55:00 +09:00
|
|
|
{
|
2023-09-04 00:46:33 -03:00
|
|
|
if (NULL == cell)
|
2020-02-07 20:55:00 +09:00
|
|
|
return;
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
QColor clrForeGround = cell->format().patternForegroundColor();
|
|
|
|
QColor clrBackGround = cell->format().patternBackgroundColor();
|
2020-02-07 20:55:00 +09:00
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
if (clrForeGround.isValid() && clrBackGround.isValid()) {
|
|
|
|
qDebug() << "[debug] color : " << clrForeGround << clrBackGround;
|
|
|
|
}
|
2020-10-11 15:52:21 +09:00
|
|
|
}
|
|
|
|
|
2023-09-04 00:46:33 -03: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
|
|
|
}
|