1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// main.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVariant>
#include <QDir>
#include <QColor>
#include <QDebug>
#include <iostream>
using namespace std;
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;
void printColor(Cell* cell);
void saveColor(Cell* cell);
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Document xlsxR(":/color.xlsx");
if ( !xlsxR.load() )
{
return (-1);
}
printColor( xlsxR.cellAt(1, 1) );
printColor( xlsxR.cellAt(1, 2) );
printColor( xlsxR.cellAt(2, 1) );
printColor( xlsxR.cellAt(2, 2) );
xlsxR.write( 3, 3, QVariant("HELLO") );
saveColor( xlsxR.cellAt(3, 3) );
xlsxR.saveAs("color2.xlsx");
return 0;
}
void printColor(Cell* cell)
{
if ( NULL == cell )
return;
QColor clrForeGround = cell->format().patternForegroundColor();
QColor clrBackGround = cell->format().patternBackgroundColor();
if ( clrForeGround.isValid() &&
clrBackGround.isValid() )
{
qDebug() << "[debug] color : " << clrForeGround << clrBackGround;
}
}
void saveColor(Cell* cell)
{
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);
}
|