From 3fefbb223500e7e9f05a75d939ff3f2550ecd821 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Mon, 28 Oct 2013 10:08:09 +0800 Subject: [PATCH] Add worksheet dimenstion access API first/last Row/Column --- src/xlsx/xlsxworksheet.cpp | 62 +++++++++++++++++++++ src/xlsx/xlsxworksheet.h | 5 ++ tests/auto/worksheet/tst_worksheet.cpp | 77 ++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 063e5fe..a11c5f3 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -892,6 +892,68 @@ bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *forma return true; } +/*! + * Returns the first row in the sheet that contains a used cell. + */ +int Worksheet::firstRow() const +{ + Q_D(const Worksheet); + + if (d->dim_rowmax == INT32_MIN) { + //Row dimenstion isn't set. + return 0; + } else { + return d->dim_rowmin; + } +} + +/*! + * Returns the zero-based index of the row after the last row in + * the sheet that contains a used cell. + */ +int Worksheet::lastRow() const +{ + Q_D(const Worksheet); + + if (d->dim_rowmax == INT32_MIN) { + //Row dimenstion isn't set. + return 0; + } else { + return d->dim_rowmax + 1; + } +} + +/*! + * Returns the first column in the sheet that contains a used cell. + */ +int Worksheet::firstColumn() const +{ + Q_D(const Worksheet); + + if (d->dim_colmax == INT32_MIN) { + //Col dimenstion isn't set. + return 0; + } else { + return d->dim_colmin; + } +} + +/*! + * Returns the zero-based index of the column after the last column + * in the sheet that contains a used cell. + */ +int Worksheet::lastColumn() const +{ + Q_D(const Worksheet); + + if (d->dim_colmax == INT32_MIN) { + //Col dimenstion isn't set. + return 0; + } else { + return d->dim_colmax + 1; + } +} + Drawing *Worksheet::drawing() const { Q_D(const Worksheet); diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index 5fac3c9..8be1a19 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -74,6 +74,11 @@ public: bool setRow(int row, double height, Format* format=0, bool hidden=false); bool setColumn(int colFirst, int colLast, double width, Format* format=0, bool hidden=false); + int firstRow() const; + int lastRow() const; + int firstColumn() const; + int lastColumn() const; + void setRightToLeft(bool enable); void setZeroValuesHidden(bool enable); diff --git a/tests/auto/worksheet/tst_worksheet.cpp b/tests/auto/worksheet/tst_worksheet.cpp index 3d7e927..58b78c1 100644 --- a/tests/auto/worksheet/tst_worksheet.cpp +++ b/tests/auto/worksheet/tst_worksheet.cpp @@ -17,6 +17,11 @@ public: private Q_SLOTS: void testEmptySheet(); + void testFirstRow(); + void testLastRow(); + void testFirstColumn(); + void testLastColumn(); + void testWriteCells(); void testWriteHyperlinks(); void testMerge(); @@ -41,6 +46,78 @@ void WorksheetTest::testEmptySheet() QVERIFY2(!xmldata.contains("