Browse Source

Add support for rows group

master
Debao Zhang 11 years ago
parent
commit
3978885252
  1. 61
      src/xlsx/xlsxworksheet.cpp
  2. 2
      src/xlsx/xlsxworksheet.h
  3. 8
      src/xlsx/xlsxworksheet_p.h

61
src/xlsx/xlsxworksheet.cpp

@ -903,12 +903,16 @@ void WorksheetPrivate::writeSheetData(XmlStreamWriter &writer)
writer.writeAttribute(QStringLiteral("s"), QString::number(rowInfo->format->xfIndex())); writer.writeAttribute(QStringLiteral("s"), QString::number(rowInfo->format->xfIndex()));
writer.writeAttribute(QStringLiteral("customFormat"), QStringLiteral("1")); writer.writeAttribute(QStringLiteral("customFormat"), QStringLiteral("1"));
} }
if (rowInfo->height != 15) { if (rowInfo->height != 15 && rowInfo->height != 0) {
writer.writeAttribute(QStringLiteral("ht"), QString::number(rowInfo->height)); writer.writeAttribute(QStringLiteral("ht"), QString::number(rowInfo->height));
writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1")); writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1"));
} }
if (rowInfo->hidden) if (rowInfo->hidden)
writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1")); writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1"));
if (rowInfo->outlineLevel > 0)
writer.writeAttribute(QStringLiteral("outlineLevel"), QString::number(rowInfo->outlineLevel));
if (rowInfo->collapsed)
writer.writeAttribute(QStringLiteral("collapsed"), QStringLiteral("1"));
} }
for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn(); col_num++) { for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn(); col_num++) {
@ -1196,6 +1200,42 @@ bool Worksheet::setColumn(const QString &colFirst, const QString &colLast, doubl
return setColumn(col1, col2, width, format, hidden); return setColumn(col1, col2, width, format, hidden);
} }
/*!
Groups rows from rowFirst to rowLast. Returns false if error occurs.
*/
bool Worksheet::groupRows(int rowFirst, int rowLast, bool collapsed)
{
Q_D(Worksheet);
for (int row=rowFirst; row<=rowLast; ++row) {
if (d->rowsInfo.contains(row)) {
d->rowsInfo[row]->outlineLevel += 1;
} else {
QSharedPointer<XlsxRowInfo> info(new XlsxRowInfo);
info->outlineLevel += 1;
d->rowsInfo.insert(row, info);
}
if (collapsed)
d->rowsInfo[row]->hidden = true;
}
if (collapsed) {
if (!d->rowsInfo.contains(rowLast+1))
d->rowsInfo.insert(rowLast+1, QSharedPointer<XlsxRowInfo>(new XlsxRowInfo));
d->rowsInfo[rowLast+1]->collapsed = true;
}
return true;
}
/*!
Groups columns from colFirst to colLast. Returns false if error occurs.
*/
bool Worksheet::groupColumns(int colFirst, int colLast, bool collapsed)
{
Q_D(Worksheet);
return false;
}
/*! /*!
Return the range that contains cell data. Return the range that contains cell data.
*/ */
@ -1447,7 +1487,9 @@ void WorksheetPrivate::readSheetData(XmlStreamReader &reader)
if (attributes.hasAttribute(QLatin1String("customFormat")) if (attributes.hasAttribute(QLatin1String("customFormat"))
|| attributes.hasAttribute(QLatin1String("customHeight")) || attributes.hasAttribute(QLatin1String("customHeight"))
|| attributes.hasAttribute(QLatin1String("hidden"))) { || attributes.hasAttribute(QLatin1String("hidden"))
|| attributes.hasAttribute(QLatin1String("outlineLevel"))
|| attributes.hasAttribute(QLatin1String("collapsed"))) {
QSharedPointer<XlsxRowInfo> info(new XlsxRowInfo); QSharedPointer<XlsxRowInfo> info(new XlsxRowInfo);
if (attributes.hasAttribute(QLatin1String("customFormat")) && attributes.hasAttribute(QLatin1String("s"))) { if (attributes.hasAttribute(QLatin1String("customFormat")) && attributes.hasAttribute(QLatin1String("s"))) {
@ -1457,11 +1499,18 @@ void WorksheetPrivate::readSheetData(XmlStreamReader &reader)
if (attributes.hasAttribute(QLatin1String("customHeight")) && attributes.hasAttribute(QLatin1String("ht"))) { if (attributes.hasAttribute(QLatin1String("customHeight")) && attributes.hasAttribute(QLatin1String("ht"))) {
info->height = attributes.value(QLatin1String("ht")).toDouble(); info->height = attributes.value(QLatin1String("ht")).toDouble();
} }
if (attributes.hasAttribute(QLatin1String("hidden"))) //both "hidden" and "collapsed" default are false
info->hidden = true; info->hidden = attributes.value(QLatin1String("hidden")) == QLatin1String("1");
info->collapsed = attributes.value(QLatin1String("collapsed")) == QLatin1String("1");
int row = attributes.value(QLatin1String("r")).toInt(); if (attributes.hasAttribute(QLatin1String("outlineLevel")))
rowsInfo[row] = info; info->outlineLevel = attributes.value(QLatin1String("outlineLevel")).toInt();
//"r" is optional too.
if (attributes.hasAttribute(QLatin1String("r"))) {
int row = attributes.value(QLatin1String("r")).toInt()-1;
rowsInfo[row] = info;
}
} }
} else if (reader.name() == QLatin1String("c")) { } else if (reader.name() == QLatin1String("c")) {

2
src/xlsx/xlsxworksheet.h

@ -80,6 +80,8 @@ public:
bool setRow(const QString &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(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 setColumn(const QString &colFirst, const QString &colLast, double width, Format* format=0, bool hidden=false);
bool groupRows(int rowFirst, int rowLast, bool collapsed = true);
bool groupColumns(int colFirst, int colLast, bool collapsed = true);
CellRange dimension() const; CellRange dimension() const;
bool isWindowProtected() const; bool isWindowProtected() const;

8
src/xlsx/xlsxworksheet_p.h

@ -123,7 +123,8 @@ struct XlsxObjectPositionData
struct XlsxRowInfo struct XlsxRowInfo
{ {
XlsxRowInfo(double height=0, Format *format=0, bool hidden=false) : XlsxRowInfo(double height=0, Format *format=0, bool hidden=false) :
height(height), format(format), hidden(hidden) height(height), format(format), hidden(hidden), outlineLevel(0)
, collapsed(false)
{ {
} }
@ -131,12 +132,15 @@ struct XlsxRowInfo
double height; double height;
Format *format; Format *format;
bool hidden; bool hidden;
int outlineLevel;
bool collapsed;
}; };
struct XlsxColumnInfo struct XlsxColumnInfo
{ {
XlsxColumnInfo(int firstColumn=0, int lastColumn=1, double width=0, Format *format=0, bool hidden=false) : XlsxColumnInfo(int firstColumn=0, int lastColumn=1, double width=0, Format *format=0, bool hidden=false) :
firstColumn(firstColumn), lastColumn(lastColumn), width(width), format(format), hidden(hidden) firstColumn(firstColumn), lastColumn(lastColumn), width(width), format(format), hidden(hidden)
, outlineLevel(0), collapsed(false)
{ {
} }
@ -145,6 +149,8 @@ struct XlsxColumnInfo
double width; double width;
Format *format; Format *format;
bool hidden; bool hidden;
int outlineLevel;
bool collapsed;
}; };
class XLSX_AUTOTEST_EXPORT WorksheetPrivate class XLSX_AUTOTEST_EXPORT WorksheetPrivate

Loading…
Cancel
Save