Add worksheet dimenstion access API
first/last Row/Column
This commit is contained in:
@@ -892,6 +892,68 @@ bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *forma
|
|||||||
return true;
|
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
|
Drawing *Worksheet::drawing() const
|
||||||
{
|
{
|
||||||
Q_D(const Worksheet);
|
Q_D(const Worksheet);
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ public:
|
|||||||
bool setRow(int row, double height, Format* format=0, bool hidden=false);
|
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);
|
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 setRightToLeft(bool enable);
|
||||||
void setZeroValuesHidden(bool enable);
|
void setZeroValuesHidden(bool enable);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ public:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testEmptySheet();
|
void testEmptySheet();
|
||||||
|
|
||||||
|
void testFirstRow();
|
||||||
|
void testLastRow();
|
||||||
|
void testFirstColumn();
|
||||||
|
void testLastColumn();
|
||||||
|
|
||||||
void testWriteCells();
|
void testWriteCells();
|
||||||
void testWriteHyperlinks();
|
void testWriteHyperlinks();
|
||||||
void testMerge();
|
void testMerge();
|
||||||
@@ -41,6 +46,78 @@ void WorksheetTest::testEmptySheet()
|
|||||||
QVERIFY2(!xmldata.contains("<mergeCell"), "");
|
QVERIFY2(!xmldata.contains("<mergeCell"), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorksheetTest::testFirstRow()
|
||||||
|
{
|
||||||
|
QXlsx::Worksheet sheet("", 1, 0);
|
||||||
|
QCOMPARE(sheet.firstRow(), 0); //Default
|
||||||
|
|
||||||
|
sheet.write(10000, 10000, "For test");
|
||||||
|
QCOMPARE(sheet.firstRow(), 10000);
|
||||||
|
|
||||||
|
sheet.write("C3", "Test");
|
||||||
|
QCOMPARE(sheet.firstRow(), 2); //Single Cell
|
||||||
|
|
||||||
|
sheet.write("B2", "Second");
|
||||||
|
QCOMPARE(sheet.firstRow(), 1);
|
||||||
|
|
||||||
|
sheet.write("D4", "Test");
|
||||||
|
QCOMPARE(sheet.firstRow(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorksheetTest::testLastRow()
|
||||||
|
{
|
||||||
|
QXlsx::Worksheet sheet("", 1, 0);
|
||||||
|
QCOMPARE(sheet.lastRow(), 0); //Default
|
||||||
|
|
||||||
|
sheet.write("C3", "Test");
|
||||||
|
QCOMPARE(sheet.lastRow(), 3); //Single Cell
|
||||||
|
|
||||||
|
sheet.write("B2", "Second");
|
||||||
|
QCOMPARE(sheet.lastRow(), 3);
|
||||||
|
|
||||||
|
sheet.write("D4", "Test");
|
||||||
|
QCOMPARE(sheet.lastRow(), 4);
|
||||||
|
|
||||||
|
sheet.write(10000, 10000, "For test");
|
||||||
|
QCOMPARE(sheet.lastRow(), 10001);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorksheetTest::testFirstColumn()
|
||||||
|
{
|
||||||
|
QXlsx::Worksheet sheet("", 1, 0);
|
||||||
|
QCOMPARE(sheet.firstColumn(), 0); //Default
|
||||||
|
|
||||||
|
sheet.write(10000, 10000, "For test");
|
||||||
|
QCOMPARE(sheet.firstColumn(), 10000);
|
||||||
|
|
||||||
|
sheet.write("C3", "Test");
|
||||||
|
QCOMPARE(sheet.firstColumn(), 2); //Single Cell
|
||||||
|
|
||||||
|
sheet.write("B2", "Second");
|
||||||
|
QCOMPARE(sheet.firstColumn(), 1);
|
||||||
|
|
||||||
|
sheet.write("D4", "Test");
|
||||||
|
QCOMPARE(sheet.firstColumn(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorksheetTest::testLastColumn()
|
||||||
|
{
|
||||||
|
QXlsx::Worksheet sheet("", 1, 0);
|
||||||
|
QCOMPARE(sheet.lastColumn(), 0); //Default
|
||||||
|
|
||||||
|
sheet.write("C3", "Test");
|
||||||
|
QCOMPARE(sheet.lastColumn(), 3); //Single Cell
|
||||||
|
|
||||||
|
sheet.write("B2", "Second");
|
||||||
|
QCOMPARE(sheet.lastColumn(), 3);
|
||||||
|
|
||||||
|
sheet.write("D4", "Test");
|
||||||
|
QCOMPARE(sheet.lastColumn(), 4);
|
||||||
|
|
||||||
|
sheet.write(10000, 10000, "For test");
|
||||||
|
QCOMPARE(sheet.lastColumn(), 10001);
|
||||||
|
}
|
||||||
|
|
||||||
void WorksheetTest::testWriteCells()
|
void WorksheetTest::testWriteCells()
|
||||||
{
|
{
|
||||||
QXlsx::Worksheet sheet("", 1, 0);
|
QXlsx::Worksheet sheet("", 1, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user