diff --git a/examples/xlsx/rowcolumn/main.cpp b/examples/xlsx/rowcolumn/main.cpp new file mode 100644 index 0000000..ad12f27 --- /dev/null +++ b/examples/xlsx/rowcolumn/main.cpp @@ -0,0 +1,42 @@ +#include +#include "xlsxdocument.h" +#include "xlsxformat.h" + +#ifdef Q_OS_MAC +# define DATA_PATH "../../../" +#else +# define DATA_PATH "./" +#endif + +int main() +{ + QXlsx::Document xlsx; + xlsx.write(0, 2, "Row:0, Col:2 ==> (C1)"); + + //Set the height of the first row to 50.0(points) + xlsx.setRow(0, 50.0); + + //Set the width of the third column to 40.0(chars) + xlsx.setColumn(2, 3, 40.0); + + //Set style for the row 11th. + QXlsx::Format *format1 = xlsx.createFormat(); + format1->setFontBold(true); + format1->setFontColor(QColor(Qt::blue)); + format1->setFontSize(20); + xlsx.write(10, 0, "Hello Row Style"); + xlsx.write(10, 5, "Blue Color"); + xlsx.setRow(10, 40, format1); + + //Set style for the col [9th, 16th) + QXlsx::Format *format2 = xlsx.createFormat(); + format2->setFontBold(true); + format2->setFontColor(QColor(Qt::magenta)); + for (int row=11; row<30; row++) + for (int col=8; col<15; col++) + xlsx.write(row, col, row+col); + xlsx.setColumn(8, 15, 5.0, format2); + + xlsx.saveAs(DATA_PATH"Test.xlsx"); + return 0; +} diff --git a/examples/xlsx/rowcolumn/rowcolumn.pro b/examples/xlsx/rowcolumn/rowcolumn.pro new file mode 100644 index 0000000..5086d54 --- /dev/null +++ b/examples/xlsx/rowcolumn/rowcolumn.pro @@ -0,0 +1,6 @@ +TARGET = image + +#include(../../../src/xlsx/qtxlsx.pri) +QT += xlsx + +SOURCES += main.cpp diff --git a/examples/xlsx/xlsx.pro b/examples/xlsx/xlsx.pro index a558313..05c328b 100644 --- a/examples/xlsx/xlsx.pro +++ b/examples/xlsx/xlsx.pro @@ -2,5 +2,6 @@ TEMPLATE = subdirs SUBDIRS = hello style \ documentproperty \ image \ - mergecells + mergecells \ + rowcolumn diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 741d79e..33b9e6a 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -617,7 +617,7 @@ void Worksheet::saveToXmlFile(QIODevice *device) writer.writeStartElement(QStringLiteral("cols")); foreach (XlsxColumnInfo *col_info, d->colsInfo) { writer.writeStartElement(QStringLiteral("col")); - writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->column_min)); + writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->column_min + 1)); writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->column_max)); writer.writeAttribute(QStringLiteral("width"), QString::number(col_info->width, 'g', 15)); if (col_info->format) @@ -853,6 +853,9 @@ bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *forma bool ignore_row = true; bool ignore_col = (format || (width && hidden)) ? false : true; + if (colFirst >= colLast) + return false; + if (d->checkDimensions(0, colLast, ignore_row, ignore_col)) return false; if (d->checkDimensions(0, colFirst, ignore_row, ignore_col))