Browse Source

Make sure that at least one worksheet exist in the workbook

master
Debao Zhang 11 years ago
parent
commit
5866e1342c
  1. 2
      src/xlsx/xlsxworkbook.cpp
  2. 6
      tests/auto/document/tst_documenttest.cpp

2
src/xlsx/xlsxworkbook.cpp

@ -251,6 +251,8 @@ bool Workbook::renameWorksheet(int index, const QString &name)
bool Workbook::deleteWorksheet(int index)
{
Q_D(Workbook);
if (d->worksheets.size() <= 1)
return false;
if (index < 0 || index >= d->worksheets.size())
return false;
d->worksheets.removeAt(index);

6
tests/auto/document/tst_documenttest.cpp

@ -343,8 +343,10 @@ void DocumentTest::testDeleteWorksheet()
QCOMPARE(xlsx1.worksheetNames(), QStringList()<<"Sheet1"<<"Sheet3");
xlsx1.deleteWorksheet("Sheet1");
QCOMPARE(xlsx1.worksheetNames(), QStringList()<<"Sheet3");
// xlsx1.deleteWorksheet("Sheet3");
// QCOMPARE(xlsx1.worksheetNames(), QStringList()<<"Sheet4");
//Cann't delete the last worksheet
xlsx1.deleteWorksheet("Sheet3");
QCOMPARE(xlsx1.worksheetNames(), QStringList()<<"Sheet3");
}
QTEST_APPLESS_MAIN(DocumentTest)

Loading…
Cancel
Save