diff --git a/src/xlsx/xlsxcell.cpp b/src/xlsx/xlsxcell.cpp index d0e1d70..1f6a188 100644 --- a/src/xlsx/xlsxcell.cpp +++ b/src/xlsx/xlsxcell.cpp @@ -52,24 +52,36 @@ Cell::Cell(const QVariant &data, DataType type, Format *format) : d_ptr->format = format; } +/*! + * Return the dataType of this Cell + */ Cell::DataType Cell::dataType() const { Q_D(const Cell); return d->dataType; } +/*! + * Return the data content of this Cell + */ QVariant Cell::value() const { Q_D(const Cell); return d->value; } +/*! + * Return the style used by this Cell. If no style used, 0 will be returned. + */ Format *Cell::format() const { Q_D(const Cell); return d->format; } +/*! + * Return the formula contents if the dataType is Formula + */ QString Cell::formula() const { Q_D(const Cell); diff --git a/src/xlsx/xlsxdocument.cpp b/src/xlsx/xlsxdocument.cpp index 74da579..b320e1c 100644 --- a/src/xlsx/xlsxdocument.cpp +++ b/src/xlsx/xlsxdocument.cpp @@ -182,6 +182,22 @@ bool Document::setColumn(int colFirst, int colLast, double width, Format *format return currentWorksheet()->setColumn(colFirst, colLast, width, format, hidden); } +/*! + * Returns a Cell object based on the given \a pos. + */ +Cell *Document::cellAt(const QString &pos) const +{ + return currentWorksheet()->cellAt(pos); +} + +/*! + * Returns a Cell object based on the given \a row and \a col. + */ +Cell *Document::cellAt(int row, int col) const +{ + return currentWorksheet()->cellAt(row, col); +} + /*! * Returns the value of the document's \a key property. */ diff --git a/src/xlsx/xlsxdocument.h b/src/xlsx/xlsxdocument.h index 6994307..4c787ca 100644 --- a/src/xlsx/xlsxdocument.h +++ b/src/xlsx/xlsxdocument.h @@ -38,6 +38,7 @@ class Workbook; class Worksheet; class Package; class Format; +class Cell; class DocumentPrivate; class Q_XLSX_EXPORT Document : public QObject @@ -60,6 +61,9 @@ public: 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); + Cell *cellAt(const QString &cell) const; + Cell *cellAt(int row, int col) const; + QString documentProperty(const QString &name) const; void setDocumentProperty(const QString &name, const QString &property); QStringList documentPropertyNames() const; diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 03e4de5..aa442dd 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -337,6 +337,26 @@ int Worksheet::write(const QString row_column, const QVariant &value, Format *fo return write(pos.x(), pos.y(), value, format); } +Cell *Worksheet::cellAt(const QString &row_column) const +{ + QPoint pos = xl_cell_to_rowcol(row_column); + if (pos == QPoint(-1, -1)) + return 0; + + return cellAt(pos.x(), pos.y()); +} + +Cell *Worksheet::cellAt(int row, int column) const +{ + Q_D(const Worksheet); + if (!d->cellTable.contains(row)) + return 0; + if (!d->cellTable[row].contains(column)) + return 0; + + return d->cellTable[row][column].data(); +} + int Worksheet::writeString(int row, int column, const QString &value, Format *format) { Q_D(Worksheet); diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index bb81770..de20cec 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -26,6 +26,7 @@ #define XLSXWORKSHEET_H #include "xlsxglobal.h" +#include "xlsxcell.h" #include #include #include @@ -59,6 +60,9 @@ public: int writeDateTime(int row, int column, const QDateTime& dt, Format *format=0); int writeUrl(int row, int column, const QUrl &url, Format *format=0, const QString &display=QString(), const QString &tip=QString()); + Cell *cellAt(const QString &row_column) const; + Cell *cellAt(int row, int column) const; + int insertImage(int row, int column, const QImage &image, const QPointF &offset=QPointF(), double xScale=1, double yScale=1); int mergeCells(int row_begin, int column_begin, int row_end, int column_end);