From fa83c2d005752ecb4ba156c83c05e179992528d6 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Tue, 5 Nov 2013 12:47:00 +0800 Subject: [PATCH] Add some overload members --- src/xlsx/xlsxdocument.cpp | 20 +++- src/xlsx/xlsxdocument.h | 2 + src/xlsx/xlsxworksheet.cpp | 185 +++++++++++++++++++++++++++++++++++-- src/xlsx/xlsxworksheet.h | 12 ++- 4 files changed, 209 insertions(+), 10 deletions(-) diff --git a/src/xlsx/xlsxdocument.cpp b/src/xlsx/xlsxdocument.cpp index 47dfcb6..55cee33 100644 --- a/src/xlsx/xlsxdocument.cpp +++ b/src/xlsx/xlsxdocument.cpp @@ -111,7 +111,9 @@ Format *Document::createFormat() } /*! - * Write \a value to cell \a row_column with the \a format. + \overload + + Write \a value to cell \a row_column with the \a format. */ int Document::write(const QString &row_column, const QVariant &value, Format *format) { @@ -126,6 +128,22 @@ int Document::write(int row, int col, const QVariant &value, Format *format) return currentWorksheet()->write(row, col, value, format); } +/*! + \overload +*/ +QVariant Document::read(const QString &cell) const +{ + return currentWorksheet()->read(cell); +} + +/*! + Return the contents of the cell (\a row, \a column). + */ +QVariant Document::read(int row, int col) const +{ + return currentWorksheet()->read(row, col); +} + /*! * \brief Insert an image to current active worksheet. * \param row diff --git a/src/xlsx/xlsxdocument.h b/src/xlsx/xlsxdocument.h index 3a8053e..6d3c66e 100644 --- a/src/xlsx/xlsxdocument.h +++ b/src/xlsx/xlsxdocument.h @@ -57,6 +57,8 @@ public: Format *createFormat(); int write(const QString &cell, const QVariant &value, Format *format=0); int write(int row, int col, const QVariant &value, Format *format=0); + QVariant read(const QString &cell) const; + QVariant read(int row, int col) const; int insertImage(int row, int column, const QImage &image, double xOffset=0, double yOffset=0, double xScale=1, double yScale=1); int mergeCells(const CellRange &range, Format *format=0); int mergeCells(const QString &range, Format *format=0); diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index ba2c0b7..202d310 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -472,16 +472,45 @@ int Worksheet::write(int row, int column, const QVariant &value, Format *format) return ret; } -//convert the "A1" notation to row/column notation +/*! + \overload + */ int Worksheet::write(const QString &row_column, const QVariant &value, Format *format) { + //convert the "A1" notation to row/column notation QPoint pos = xl_cell_to_rowcol(row_column); - if (pos == QPoint(-1, -1)) { + if (pos == QPoint(-1, -1)) return -1; - } + return write(pos.x(), pos.y(), value, format); } +/*! + \overload + */ +QVariant Worksheet::read(const QString &row_column) const +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return QVariant(); + + return read(pos.x(), pos.y()); +} + +/*! + Return the contents of the cell (\a row, \a column). + */ +QVariant Worksheet::read(int row, int column) const +{ + Cell *cell = cellAt(row, column); + if (!cell) + return QVariant(); + if (!cell->formula().isEmpty()) + return QLatin1String("=")+cell->formula(); + return cell->value(); +} + Cell *Worksheet::cellAt(const QString &row_column) const { QPoint pos = xl_cell_to_rowcol(row_column); @@ -511,6 +540,22 @@ Format *WorksheetPrivate::cellFormat(int row, int col) const return cellTable[row][col]->format(); } +/*! + \overload + */ +int Worksheet::writeString(const QString &row_column, const QString &value, Format *format) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeString(pos.x(), pos.y(), value, format); +} + +/*! + Write string \a value to the cell (\a row, \a column) with the \a format +*/ int Worksheet::writeString(int row, int column, const QString &value, Format *format) { Q_D(Worksheet); @@ -531,6 +576,22 @@ int Worksheet::writeString(int row, int column, const QString &value, Format *fo return error; } +/*! + \overload + */ +int Worksheet::writeInlineString(const QString &row_column, const QString &value, Format *format) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeInlineString(pos.x(), pos.y(), value, format); +} + +/*! + Write string \a value to the cell (\a row, \a column) with the \a format +*/ int Worksheet::writeInlineString(int row, int column, const QString &value, Format *format) { Q_D(Worksheet); @@ -550,6 +611,22 @@ int Worksheet::writeInlineString(int row, int column, const QString &value, Form return error; } +/*! + \overload + */ +int Worksheet::writeNumeric(const QString &row_column, double value, Format *format) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeNumeric(pos.x(), pos.y(), value, format); +} + +/*! + Write numeric \a value to the cell (\a row, \a column) with the \a format +*/ int Worksheet::writeNumeric(int row, int column, double value, Format *format) { Q_D(Worksheet); @@ -562,27 +639,59 @@ int Worksheet::writeNumeric(int row, int column, double value, Format *format) return 0; } -int Worksheet::writeFormula(int row, int column, const QString &content, Format *format, double result) +/*! + \overload + */ +int Worksheet::writeFormula(const QString &row_column, const QString &formula, Format *format, double result) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeFormula(pos.x(), pos.y(), formula, format, result); +} + +/*! + Write \a formula to the cell (\a row, \a column) with the \a format +*/ +int Worksheet::writeFormula(int row, int column, const QString &formula, Format *format, double result) { Q_D(Worksheet); int error = 0; - QString formula = content; + QString _formula = formula; if (d->checkDimensions(row, column)) return -1; //Remove the formula '=' sign if exists - if (formula.startsWith(QLatin1String("="))) - formula.remove(0,1); + if (_formula.startsWith(QLatin1String("="))) + _formula.remove(0,1); format = format ? format : d->cellFormat(row, column); Cell *data = new Cell(result, Cell::Formula, format, this); - data->d_ptr->formula = formula; + data->d_ptr->formula = _formula; d->cellTable[row][column] = QSharedPointer(data); d->workbook->styles()->addFormat(format); return error; } +/*! + \overload + */ +int Worksheet::writeBlank(const QString &row_column, Format *format) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeBlank(pos.x(), pos.y(), format); +} + +/*! + Write a empty cell (\a row, \a column) with the \a format + */ int Worksheet::writeBlank(int row, int column, Format *format) { Q_D(Worksheet); @@ -595,7 +704,22 @@ int Worksheet::writeBlank(int row, int column, Format *format) return 0; } +/*! + \overload + */ +int Worksheet::writeBool(const QString &row_column, bool value, Format *format) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeBool(pos.x(), pos.y(), value, format); +} +/*! + Write a bool \a value to the cell (\a row, \a column) with the \a format + */ int Worksheet::writeBool(int row, int column, bool value, Format *format) { Q_D(Worksheet); @@ -608,7 +732,22 @@ int Worksheet::writeBool(int row, int column, bool value, Format *format) return 0; } +/*! + \overload + */ +int Worksheet::writeDateTime(const QString &row_column, const QDateTime &dt, Format *format) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeDateTime(pos.x(), pos.y(), dt, format); +} +/*! + Write a QDateTime \a value to the cell (\a row, \a column) with the \a format + */ int Worksheet::writeDateTime(int row, int column, const QDateTime &dt, Format *format) { Q_D(Worksheet); @@ -628,6 +767,22 @@ int Worksheet::writeDateTime(int row, int column, const QDateTime &dt, Format *f return 0; } +/*! + \overload + */ +int Worksheet::writeHyperlink(const QString &row_column, const QUrl &url, Format *format, const QString &display, const QString &tip) +{ + //convert the "A1" notation to row/column notation + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return -1; + + return writeHyperlink(pos.x(), pos.y(), url, format, display, tip); +} + +/*! + Write a QUrl \a value to the cell (\a row, \a column) with the \a format + */ int Worksheet::writeHyperlink(int row, int column, const QUrl &url, Format *format, const QString &display, const QString &tip) { Q_D(Worksheet); @@ -1287,6 +1442,20 @@ bool Worksheet::groupRows(int rowFirst, int rowLast, bool collapsed) return true; } +/*! + \overload + */ +bool Worksheet::groupColumns(const QString &colFirst, const QString &colLast, bool collapsed) +{ + int col1 = xl_col_name_to_value(colFirst); + int col2 = xl_col_name_to_value(colLast); + + if (col1 == -1 || col2 == -1) + return false; + + return groupColumns(col1, col2, collapsed); +} + /*! Groups columns from colFirst to colLast. Returns false if error occurs. */ diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index 5560891..905beda 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -55,13 +55,23 @@ class Q_XLSX_EXPORT Worksheet public: int write(const QString &row_column, const QVariant &value, Format *format=0); int write(int row, int column, const QVariant &value, Format *format=0); + QVariant read(const QString &row_column) const; + QVariant read(int row, int column) const; + int writeString(const QString &row_column, const QString &value, Format *format=0); int writeString(int row, int column, const QString &value, Format *format=0); + int writeInlineString(const QString &row_column, const QString &value, Format *format=0); int writeInlineString(int row, int column, const QString &value, Format *format=0); + int writeNumeric(const QString &row_column, double value, Format *format=0); int writeNumeric(int row, int column, double value, Format *format=0); + int writeFormula(const QString &row_column, const QString &formula, Format *format=0, double result=0); int writeFormula(int row, int column, const QString &formula, Format *format=0, double result=0); + int writeBlank(const QString &row_column, Format *format=0); int writeBlank(int row, int column, Format *format=0); + int writeBool(const QString &row_column, bool value, Format *format=0); int writeBool(int row, int column, bool value, Format *format=0); + int writeDateTime(const QString &row_column, const QDateTime& dt, Format *format=0); int writeDateTime(int row, int column, const QDateTime& dt, Format *format=0); + int writeHyperlink(const QString &row_column, const QUrl &url, Format *format=0, const QString &display=QString(), const QString &tip=QString()); int writeHyperlink(int row, int column, const QUrl &url, Format *format=0, const QString &display=QString(), const QString &tip=QString()); bool addDataValidation(const DataValidation &validation); @@ -77,11 +87,11 @@ public: int unmergeCells(const CellRange &range); bool setRow(int 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(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); + bool groupColumns(const QString &colFirst, const QString &colLast, bool collapsed = true); CellRange dimension() const; bool isWindowProtected() const;