Browse Source

Fix issue 6: row & column No. starts from 1 instead of 0 now

master
Debao Zhang 11 years ago
parent
commit
470abc6453
  1. 20
      examples/xlsx/definename/main.cpp
  2. 55
      examples/xlsx/demo/main.cpp
  3. 32
      examples/xlsx/numberformat/main.cpp
  4. 18
      examples/xlsx/rowcolumn/main.cpp
  5. 12
      examples/xlsx/style/main.cpp
  6. 19
      src/xlsx/xlsxdocument.cpp
  7. 1
      src/xlsx/xlsxdocument.h
  8. 10
      src/xlsx/xlsxutility.cpp
  9. 50
      src/xlsx/xlsxworksheet.cpp
  10. 34
      tests/auto/utility/tst_utilitytest.cpp
  11. 22
      tests/auto/worksheet/tst_worksheet.cpp

20
examples/xlsx/definename/main.cpp

@ -7,10 +7,10 @@ int main()
{
//![0]
Document xlsx;
for (int i=0; i<10; ++i) {
xlsx.write(i, 0, i);
xlsx.write(i, 1, i*i);
xlsx.write(i, 2, i*i*i);
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]
@ -20,12 +20,12 @@ int main()
xlsx.defineName("Factor", "=0.5");
//![1]
//![2]
xlsx.write(10, 0, "=SUM(MyCol_1)");
xlsx.write(10, 1, "=SUM(MyCol_2)");
xlsx.write(10, 2, "=SUM(MyCol_3)");
xlsx.write(11, 0, "=SUM(MyCol_1)*Factor");
xlsx.write(11, 1, "=SUM(MyCol_2)*Factor");
xlsx.write(11, 2, "=SUM(MyCol_3)*Factor");
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();

55
examples/xlsx/demo/main.cpp

@ -74,18 +74,18 @@ void writeInternalNumFormatsCell(Document &xlsx, int row, double value, int numF
{
Format *format = xlsx.createFormat();
format->setNumberFormatIndex(numFmt);
xlsx.write(row, 0, value);
xlsx.write(row, 1, QString("Builtin NumFmt %1").arg(numFmt));
xlsx.write(row, 2, value, format);
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 = xlsx.createFormat();
format->setNumberFormat(numFmt);
xlsx.write(row, 0, value);
xlsx.write(row, 1, numFmt);
xlsx.write(row, 2, value, format);
xlsx.write(row, 1, value);
xlsx.write(row, 2, numFmt);
xlsx.write(row, 3, value, format);
}
int main()
@ -243,19 +243,19 @@ int main()
//Create the fourth sheet.
xlsx.addWorksheet("NumFormats");
xlsx.setColumn("B", "B", 40);
writeInternalNumFormatsCell(xlsx, 3, 2.5681, 2);
writeInternalNumFormatsCell(xlsx, 4, 2500000, 3);
writeInternalNumFormatsCell(xlsx, 5, -500, 5);
writeInternalNumFormatsCell(xlsx, 6, -0.25, 9);
writeInternalNumFormatsCell(xlsx, 7, 890, 11);
writeInternalNumFormatsCell(xlsx, 8, 0.75, 12);
writeInternalNumFormatsCell(xlsx, 9, 41499, 14);
writeInternalNumFormatsCell(xlsx, 10, 41499, 17);
writeCustomNumFormatsCell(xlsx, 12, 20.5627, "#.###");
writeCustomNumFormatsCell(xlsx, 13, 4.8, "#.00");
writeCustomNumFormatsCell(xlsx, 14, 1.23, "0.00 \"RMB\"");
writeCustomNumFormatsCell(xlsx, 15, 60, "[Red][<=100];[Green][>100]");
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.
@ -274,16 +274,17 @@ int main()
//Create the fifth sheet.
xlsx.addWorksheet("Grouping");
qsrand(QDateTime::currentMSecsSinceEpoch());
for (int row=1; row<31; ++row) {
for (int col=0; col<10; ++col)
for (int row=2; row<31; ++row) {
for (int col=1; col<=10; ++col)
xlsx.write(row, col, qrand() % 100);
}
xlsx.groupRows(3, 6);
xlsx.groupRows(10, 25, false);
xlsx.groupRows(14, 16, false);
xlsx.groupRows(19, 21, false);
xlsx.groupColumns(0, 1);
xlsx.groupColumns(4, 7, false);
xlsx.groupRows(4, 7);
xlsx.groupRows(11, 26, false);
xlsx.groupRows(15, 17, false);
xlsx.groupRows(20, 22, false);
xlsx.setColumn(1, 10, 10.0);
xlsx.groupColumns(1, 2);
xlsx.groupColumns(5, 8, false);
xlsx.saveAs("Book1.xlsx");

32
examples/xlsx/numberformat/main.cpp

@ -7,7 +7,7 @@ int main(int argc, char** argv)
QGuiApplication(argc, argv);
QXlsx::Document xlsx;
xlsx.setColumn(0, 4, 20.0);
xlsx.setColumn(1, 4, 20.0);
QXlsx::Format *header = xlsx.createFormat();
header->setFontBold(true);
@ -19,32 +19,32 @@ int main(int argc, char** argv)
<<"yyyy-mmm-dd"
<<"$ #,##0.00"
<<"[red]0.00";
xlsx.write(0, 0, "Raw data", header);
xlsx.write(0, 1, "Format", header);
xlsx.write(0, 2, "Shown value", header);
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+1;
xlsx.write(row, 0, 100.0);
xlsx.write(row, 1, numFormats[i]);
int row = i+2;
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFormats[i]);
QXlsx::Format *format = xlsx.createFormat();
format->setNumberFormat(numFormats[i]);
xlsx.write(row, 2, 100.0, format);
xlsx.write(row, 3, 100.0, format);
}
//Builtin number formats
xlsx.addWorksheet();
xlsx.setColumn(0, 4, 20.0);
xlsx.write(0, 0, "Raw data", header);
xlsx.write(0, 1, "Builtin Format", header);
xlsx.write(0, 2, "Shown value", header);
xlsx.setColumn(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+1;
int row = i+2;
int numFmt = i;
xlsx.write(row, 0, 100.0);
xlsx.write(row, 1, numFmt);
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFmt);
QXlsx::Format *format = xlsx.createFormat();
format->setNumberFormatIndex(numFmt);
xlsx.write(row, 2, 100.0, format);
xlsx.write(row, 3, 100.0, format);
}
xlsx.save();

18
examples/xlsx/rowcolumn/main.cpp

@ -5,31 +5,31 @@
int main()
{
QXlsx::Document xlsx;
xlsx.write(0, 2, "Row:0, Col:2 ==> (C1)");
xlsx.write(1, 2, "Row:0, Col:2 ==> (C1)");
//Set the height of the first row to 50.0(points)
xlsx.setRow(0, 50.0);
xlsx.setRow(1, 50.0);
//Set the width of the third column to 40.0(chars)
xlsx.setColumn(2, 3, 40.0);
xlsx.setColumn(3, 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);
xlsx.write(11, 1, "Hello Row Style");
xlsx.write(11, 6, "Blue Color");
xlsx.setRow(11, 41, 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++)
for (int row=12; row<=30; row++)
for (int col=9; col<=15; col++)
xlsx.write(row, col, row+col);
xlsx.setColumn(8, 15, 5.0, format2);
xlsx.setColumn(9, 16, 5.0, format2);
xlsx.save();
return 0;

12
examples/xlsx/style/main.cpp

@ -24,17 +24,17 @@ int main()
format3->setFontBold(true);
format3->setFontColor(QColor(Qt::blue));
format3->setFontSize(20);
xlsx.write(10, 0, "Hello Row Style");
xlsx.write(10, 5, "Blue Color");
xlsx.setRow(10, 40, format3);
xlsx.write(11, 1, "Hello Row Style");
xlsx.write(11, 6, "Blue Color");
xlsx.setRow(11, 41, format3);
QXlsx::Format *format4 = xlsx.createFormat();
format4->setFontBold(true);
format4->setFontColor(QColor(Qt::magenta));
for (int row=20; row<40; row++)
for (int col=8; col<15; col++)
for (int row=21; row<=40; row++)
for (int col=9; col<16; col++)
xlsx.write(row, col, row+col);
xlsx.setColumn(8, 15, 5.0, format4);
xlsx.setColumn(9, 16, 5.0, format4);
xlsx.write("A5", QDate(2013, 8, 29));

19
src/xlsx/xlsxdocument.cpp

@ -181,32 +181,19 @@ int Document::unmergeCells(const CellRange &range)
}
/*!
* \brief Set properties for a row of cells.
* \param row The worksheet row (zero indexed).
* \param height The row height.
* \param format Optional Format object.
* \param hidden
Sets row \a height and \a format. Row height measured in point size. If format
equals 0 then format is ignored. \a row is 1-indexed.
*/
bool Document::setRow(int row, double height, Format *format, bool hidden)
{
return currentWorksheet()->setRow(row, height, format, hidden);
}
/*!
\overload
Sets row height and format. Row height measured in point size. If format
equals 0 then format is ignored. \a row should be "1", "2", "3", ...
*/
bool Document::setRow(const QString &row, double height, Format *format, bool hidden)
{
return currentWorksheet()->setRow(row, height, format, hidden);
}
/*!
Sets column width and format for all columns from colFirst to colLast. Column
width measured as the number of characters of the maximum digit width of the
numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. If format
equals 0 then format is ignored. \a colFirst and \a colLast are all zero-indexed.
equals 0 then format is ignored. \a colFirst and \a colLast are all 1-indexed.
*/
bool Document::setColumn(int colFirst, int colLast, double width, Format *format, bool hidden)
{

1
src/xlsx/xlsxdocument.h

@ -63,7 +63,6 @@ public:
int unmergeCells(const CellRange &range);
int unmergeCells(const QString &range);
bool setRow(int row, double height, Format* format=0, bool hidden=false);
bool setRow(const QString &row, double height, Format* format=0, bool hidden=false);
bool setColumn(int colFirst, int colLast, double width, Format* format=0, bool hidden=false);
bool setColumn(const QString &colFirst, const QString &colLast, double width, Format* format=0, bool hidden=false);
bool groupRows(int rowFirst, int rowLast, bool collapsed = true);

10
src/xlsx/xlsxutility.cpp

@ -91,7 +91,7 @@ QDateTime datetimeFromNumber(double num, bool is1904)
QPoint xl_cell_to_rowcol(const QString &cell_str)
{
if (cell_str.isEmpty())
return QPoint(0, 0);
return QPoint(-1, -1);
QRegularExpression re(QStringLiteral("^([A-Z]{1,3})(\\d+)$"));
QRegularExpressionMatch match = re.match(cell_str);
if (match.hasMatch()) {
@ -104,8 +104,7 @@ QPoint xl_cell_to_rowcol(const QString &cell_str)
expn++;
}
col--;
int row = row_str.toInt() - 1;
int row = row_str.toInt();
return QPoint(row, col);
} else {
return QPoint(-1, -1); //...
@ -114,7 +113,6 @@ QPoint xl_cell_to_rowcol(const QString &cell_str)
QString xl_col_to_name(int col_num)
{
col_num += 1; //Change to 1-index
QString col_str;
int remainder;
@ -141,7 +139,6 @@ int xl_col_name_to_value(const QString &col_str)
expn++;
}
col--;
return col;
}
return -1;
@ -149,7 +146,6 @@ int xl_col_name_to_value(const QString &col_str)
QString xl_rowcol_to_cell(int row, int col, bool row_abs, bool col_abs)
{
row += 1; //Change to 1-index
QString cell_str;
if (col_abs)
cell_str.append(QLatin1Char('$'));
@ -170,7 +166,7 @@ QString xl_rowcol_to_cell_fast(int row, int col)
col_str = xl_col_to_name(col);
col_cache[col] = col_str;
}
return col_str + QString::number(row+1);
return col_str + QString::number(row);
}
} //namespace QXlsx

50
src/xlsx/xlsxworksheet.cpp

@ -122,7 +122,7 @@ void WorksheetPrivate::calculateSpans()
}
}
if ((row_num + 1)%16 == 0 || row_num == dimension.lastRow()) {
if ((row_num)%16 == 0 || row_num == dimension.lastRow()) {
int span_index = row_num / 16;
if (span_max != INT32_MIN) {
span_min += 1;
@ -426,6 +426,10 @@ QList<QPair<QString, QString> > Worksheet::drawingLinks() const
return d->drawingLinks;
}
/*!
* Write \a value to cell (\a row, \a column) with the \a format.
* Both \a row and \a column are all 1-indexed value.
*/
int Worksheet::write(int row, int column, const QVariant &value, Format *format)
{
Q_D(Worksheet);
@ -850,9 +854,10 @@ void Worksheet::saveToXmlFile(QIODevice *device)
it.next();
QSharedPointer<XlsxColumnInfo> col_info = it.value();
writer.writeStartElement(QStringLiteral("col"));
writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->firstColumn + 1));
writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->lastColumn + 1));
writer.writeAttribute(QStringLiteral("width"), QString::number(col_info->width, 'g', 15));
writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->firstColumn));
writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->lastColumn));
if (col_info->width)
writer.writeAttribute(QStringLiteral("width"), QString::number(col_info->width, 'g', 15));
if (col_info->format)
writer.writeAttribute(QStringLiteral("style"), QString::number(col_info->format->xfIndex()));
if (col_info->hidden)
@ -891,14 +896,14 @@ void WorksheetPrivate::writeSheetData(XmlStreamWriter &writer)
continue;
}
int span_index = row_num / 16;
int span_index = (row_num-1) / 16;
QString span;
if (row_spans.contains(span_index))
span = row_spans[span_index];
if (cellTable.contains(row_num)) {
writer.writeStartElement(QStringLiteral("row"));
writer.writeAttribute(QStringLiteral("r"), QString::number(row_num + 1));
writer.writeAttribute(QStringLiteral("r"), QString::number(row_num));
if (!span.isEmpty())
writer.writeAttribute(QStringLiteral("spans"), span);
@ -938,10 +943,10 @@ void WorksheetPrivate::writeSheetData(XmlStreamWriter &writer)
void WorksheetPrivate::writeCellData(XmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell)
{
//This is the innermost loop so efficiency is important.
QString cell_range = xl_rowcol_to_cell_fast(row, col);
QString cell_pos = xl_rowcol_to_cell_fast(row, col);
writer.writeStartElement(QStringLiteral("c"));
writer.writeAttribute(QStringLiteral("r"), cell_range);
writer.writeAttribute(QStringLiteral("r"), cell_pos);
//Style used by the cell, row or col
if (cell->format())
@ -1127,8 +1132,8 @@ void WorksheetPrivate::writeDrawings(XmlStreamWriter &writer)
}
/*!
Sets row height and format. Row height measured in point size. If format
equals 0 then format is ignored. \a row is zero-indexed.
Sets row \a height and \a format. Row height measured in point size. If format
equals 0 then format is ignored. \a row is 1-indexed.
*/
bool Worksheet::setRow(int row, double height, Format *format, bool hidden)
{
@ -1143,21 +1148,6 @@ bool Worksheet::setRow(int row, double height, Format *format, bool hidden)
return true;
}
/*!
\overload
Sets row height and format. Row height measured in point size. If format
equals 0 then format is ignored. \a row should be "1", "2", "3", ...
*/
bool Worksheet::setRow(const QString &row, double height, Format *format, bool hidden)
{
bool ok=true;
int r = row.toInt(&ok);
if (ok)
return setRow(r-1, height, format, hidden);
return false;
}
void WorksheetPrivate::splitColsInfo(int colFirst, int colLast)
{
// Split current columnInfo, for example, if "A:H" has been set,
@ -1201,10 +1191,10 @@ void WorksheetPrivate::splitColsInfo(int colFirst, int colLast)
}
/*!
Sets column width and format for all columns from colFirst to colLast. Column
Sets column \a width and \a format for all columns from \a colFirst to \a colLast. Column
width measured as the number of characters of the maximum digit width of the
numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. If format
equals 0 then format is ignored.
equals 0 then format is ignored. Both \a colFirst and \a colLast are all 1-indexed.
*/
bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *format, bool hidden)
{
@ -1625,7 +1615,7 @@ void WorksheetPrivate::readSheetData(XmlStreamReader &reader)
//"r" is optional too.
if (attributes.hasAttribute(QLatin1String("r"))) {
int row = attributes.value(QLatin1String("r")).toInt()-1;
int row = attributes.value(QLatin1String("r")).toInt();
rowsInfo[row] = info;
}
}
@ -1731,8 +1721,8 @@ void WorksheetPrivate::readColumnsInfo(XmlStreamReader &reader)
QXmlStreamAttributes colAttrs = reader.attributes();
int min = colAttrs.value(QLatin1String("min")).toInt();
int max = colAttrs.value(QLatin1String("max")).toInt();
info->firstColumn = min - 1;
info->lastColumn = max - 1;
info->firstColumn = min;
info->lastColumn = max;
//!Todo, customWidth support.
//Note, node may have "width" without "customWidth"

34
tests/auto/utility/tst_utilitytest.cpp

@ -68,18 +68,18 @@ void UtilityTest::test_cell_to_rowcol_data()
QTest::addColumn<int>("row");
QTest::addColumn<int>("col");
QTest::newRow("A1") << "A1" << 0 << 0;
QTest::newRow("B1") << "B1" << 0 << 1;
QTest::newRow("C1") << "C1" << 0 << 2;
QTest::newRow("J1") << "J1" << 0 << 9;
QTest::newRow("A2") << "A2" << 1 << 0;
QTest::newRow("A3") << "A3" << 2 << 0;
QTest::newRow("A10") << "A10" << 9 << 0;
QTest::newRow("Z8") << "Z8" << 7 << 25;
QTest::newRow("AA10") << "AA10" << 9 << 26;
QTest::newRow("IU2") << "IU2" << 1 << 254;
QTest::newRow("XFD1") << "XFD1" << 0 << 16383;
QTest::newRow("XFE1048577") << "XFE1048577" << 1048576 << 16384;
QTest::newRow("A1") << "A1" << 1 << 1;
QTest::newRow("B1") << "B1" << 1 << 2;
QTest::newRow("C1") << "C1" << 1 << 3;
QTest::newRow("J1") << "J1" << 1 << 10;
QTest::newRow("A2") << "A2" << 2 << 1;
QTest::newRow("A3") << "A3" << 3 << 1;
QTest::newRow("A10") << "A10" << 10 << 1;
QTest::newRow("Z8") << "Z8" << 8 << 26;
QTest::newRow("AA10") << "AA10" << 10 << 27;
QTest::newRow("IU2") << "IU2" << 2 << 255;
QTest::newRow("XFD1") << "XFD1" << 1 << 16384;
QTest::newRow("XFE1048577") << "XFE1048577" << 1048577 << 16385;
}
void UtilityTest::test_rowcol_to_cell()
@ -101,11 +101,11 @@ void UtilityTest::test_rowcol_to_cell_data()
QTest::addColumn<bool>("col_abs");
QTest::addColumn<QString>("cell");
QTest::newRow("simple") << 0 << 0 << false << false << "A1";
QTest::newRow("rowabs") << 0 << 0 << true << false << "A$1";
QTest::newRow("colabs") << 0 << 0 << false << true << "$A1";
QTest::newRow("bothabs") << 0 << 0 << true << true << "$A$1";
QTest::newRow("...") << 1048576 << 16384 << false << false << "XFE1048577";
QTest::newRow("simple") << 1 << 1 << false << false << "A1";
QTest::newRow("rowabs") << 1 << 1 << true << false << "A$1";
QTest::newRow("colabs") << 1 << 1 << false << true << "$A1";
QTest::newRow("bothabs") << 1 << 1 << true << true << "$A$1";
QTest::newRow("...") << 1048577 << 16385 << false << false << "XFE1048577";
}
void UtilityTest::test_datetimeToNumber_data()

22
tests/auto/worksheet/tst_worksheet.cpp

@ -55,16 +55,16 @@ void WorksheetTest::testDimension()
sheet.write("C3", "Test");
qDebug()<<sheet.dimension().toString();
QCOMPARE(sheet.dimension(), QXlsx::CellRange(2, 2, 2, 2)); //Single Cell
QCOMPARE(sheet.dimension(), QXlsx::CellRange(3, 3, 3, 3)); //Single Cell
sheet.write("B2", "Second");
QCOMPARE(sheet.dimension(), QXlsx::CellRange(1, 1, 2, 2));
QCOMPARE(sheet.dimension(), QXlsx::CellRange(2, 2, 3, 3));
sheet.write("D4", "Test");
QCOMPARE(sheet.dimension(), QXlsx::CellRange("B2:D4"));
sheet.write(10000, 10000, "For test");
QCOMPARE(sheet.dimension(), QXlsx::CellRange(1, 1, 10000, 10000));
QCOMPARE(sheet.dimension(), QXlsx::CellRange(2, 2, 10000, 10000));
}
void WorksheetTest::testSheetView()
@ -81,9 +81,10 @@ void WorksheetTest::testSheetView()
void WorksheetTest::testSetColumn()
{
QXlsx::Worksheet sheet("", 1, 0);
sheet.setColumn(0, 10, 20.0); //"A:K"
sheet.setColumn(3, 7, 10.0); //"D:H"
sheet.setColumn(5, 5, 15.0); //"F:F"
sheet.setColumn(1, 11, 20.0); //"A:K"
sheet.setColumn(4, 8, 10.0); //"D:H"
sheet.setColumn(6, 6, 15.0); //"F:F"
sheet.setColumn(1, 9, 8.8); //"A:H"
QByteArray xmldata = sheet.saveToXmlData();
@ -92,7 +93,8 @@ void WorksheetTest::testSetColumn()
QVERIFY(xmldata.contains("<col min=\"4\" max=\"5\"")); //"D:E"
QVERIFY(xmldata.contains("<col min=\"6\" max=\"6\"")); //"F:F"
QVERIFY(xmldata.contains("<col min=\"7\" max=\"8\"")); //"G:H"
QVERIFY(xmldata.contains("<col min=\"9\" max=\"11\""));//"I:K"
QVERIFY(xmldata.contains("<col min=\"9\" max=\"9\""));//"I:I"
QVERIFY(xmldata.contains("<col min=\"10\" max=\"11\""));//"J:K"
}
void WorksheetTest::testWriteCells()
@ -100,10 +102,10 @@ void WorksheetTest::testWriteCells()
QXlsx::Worksheet sheet("", 1, 0);
sheet.write("A1", 123);
sheet.write("A2", "Hello");
sheet.writeInlineString(2, 0, "Hello inline"); //A3
sheet.writeInlineString(3, 1, "Hello inline"); //A3
sheet.write("A4", true);
sheet.write("A5", "=44+33");
sheet.writeFormula(4, 1, "44+33", 0, 77);
sheet.writeFormula(5, 2, "44+33", 0, 77);
QByteArray xmldata = sheet.saveToXmlData();
@ -259,7 +261,7 @@ void WorksheetTest::testReadRowsInfo()
sheet.d_ptr->readSheetData(reader);
QCOMPARE(sheet.d_ptr->rowsInfo.size(), 1);
QCOMPARE(sheet.d_ptr->rowsInfo[2]->height, 40.0);
QCOMPARE(sheet.d_ptr->rowsInfo[3]->height, 40.0);
}
void WorksheetTest::testReadMergeCells()

Loading…
Cancel
Save