|
@ -71,16 +71,11 @@ void Workbook::save(const QString &name) |
|
|
addWorksheet(); |
|
|
addWorksheet(); |
|
|
|
|
|
|
|
|
//Ensure that at least one worksheet has been selected.
|
|
|
//Ensure that at least one worksheet has been selected.
|
|
|
if (d->activesheet == 0) { |
|
|
int actIndex = d->activesheet; |
|
|
d->worksheets[0]->setHidden(false); |
|
|
if (actIndex < 0 || actIndex >= d->worksheets.size()) |
|
|
d->worksheets[0]->setSelected(true); |
|
|
actIndex = 0; |
|
|
} |
|
|
d->worksheets[actIndex]->setHidden(false); |
|
|
|
|
|
d->worksheets[actIndex]->setSelected(true); |
|
|
//Set the active sheet
|
|
|
|
|
|
foreach (Worksheet *sheet, d->worksheets) { |
|
|
|
|
|
if (sheet->index() == d->activesheet) |
|
|
|
|
|
sheet->setActived(true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Create the package based on current workbook
|
|
|
//Create the package based on current workbook
|
|
|
Package package(this); |
|
|
Package package(this); |
|
@ -133,17 +128,50 @@ void Workbook::defineName(const QString &name, const QString &formula) |
|
|
Worksheet *Workbook::addWorksheet(const QString &name) |
|
|
Worksheet *Workbook::addWorksheet(const QString &name) |
|
|
{ |
|
|
{ |
|
|
Q_D(Workbook); |
|
|
Q_D(Workbook); |
|
|
|
|
|
return insertWorkSheet(d->worksheets.size(), name); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Worksheet *Workbook::insertWorkSheet(int index, const QString &name) |
|
|
|
|
|
{ |
|
|
|
|
|
Q_D(Workbook); |
|
|
|
|
|
static int lastIndex = -1; |
|
|
QString worksheetName = name; |
|
|
QString worksheetName = name; |
|
|
int index = d->worksheets.size()+1; |
|
|
if (!name.isEmpty()) { |
|
|
if (name.isEmpty()) |
|
|
//If user given an already in-use name, we should not continue any more!
|
|
|
worksheetName = QStringLiteral("Sheet%1").arg(index); |
|
|
foreach (Worksheet *sheet, d->worksheets) { |
|
|
|
|
|
if (sheet->name() == name) |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
bool exists; |
|
|
|
|
|
do { |
|
|
|
|
|
++lastIndex; |
|
|
|
|
|
exists = false; |
|
|
|
|
|
worksheetName = QStringLiteral("Sheet%1").arg(lastIndex+1); |
|
|
|
|
|
foreach (Worksheet *sheet, d->worksheets) { |
|
|
|
|
|
if (sheet->name() == worksheetName) |
|
|
|
|
|
exists = true; |
|
|
|
|
|
} |
|
|
|
|
|
} while (exists); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Worksheet *sheet = new Worksheet(worksheetName, index, this); |
|
|
Worksheet *sheet = new Worksheet(worksheetName, this); |
|
|
d->worksheets.append(sheet); |
|
|
d->worksheets.insert(index, sheet); |
|
|
return sheet; |
|
|
return sheet; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int Workbook::activedWorksheet() const |
|
|
|
|
|
{ |
|
|
|
|
|
Q_D(const Workbook); |
|
|
|
|
|
return d->activesheet; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Workbook::setActivedWorksheet(int index) |
|
|
|
|
|
{ |
|
|
|
|
|
Q_D(Workbook); |
|
|
|
|
|
d->activesheet = index; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Format *Workbook::addFormat() |
|
|
Format *Workbook::addFormat() |
|
|
{ |
|
|
{ |
|
|
Q_D(Workbook); |
|
|
Q_D(Workbook); |
|
@ -205,13 +233,14 @@ void Workbook::saveToXmlFile(QIODevice *device) |
|
|
writer.writeEndElement();//bookviews
|
|
|
writer.writeEndElement();//bookviews
|
|
|
|
|
|
|
|
|
writer.writeStartElement(QStringLiteral("sheets")); |
|
|
writer.writeStartElement(QStringLiteral("sheets")); |
|
|
foreach (Worksheet *sheet, d->worksheets) { |
|
|
for (int i=0; i<d->worksheets.size(); ++i) { |
|
|
|
|
|
Worksheet *sheet = d->worksheets[i]; |
|
|
writer.writeEmptyElement(QStringLiteral("sheet")); |
|
|
writer.writeEmptyElement(QStringLiteral("sheet")); |
|
|
writer.writeAttribute(QStringLiteral("name"), sheet->name()); |
|
|
writer.writeAttribute(QStringLiteral("name"), sheet->name()); |
|
|
writer.writeAttribute(QStringLiteral("sheetId"), QString::number(sheet->index())); |
|
|
writer.writeAttribute(QStringLiteral("sheetId"), QString::number(i+1)); |
|
|
if (sheet->isHidden()) |
|
|
if (sheet->isHidden()) |
|
|
writer.writeAttribute(QStringLiteral("state"), QStringLiteral("hidden")); |
|
|
writer.writeAttribute(QStringLiteral("state"), QStringLiteral("hidden")); |
|
|
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(sheet->index())); |
|
|
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(i+1)); |
|
|
} |
|
|
} |
|
|
writer.writeEndElement();//sheets
|
|
|
writer.writeEndElement();//sheets
|
|
|
|
|
|
|
|
|