xlsxdocument.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /****************************************************************************
  2. ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
  3. ** All right reserved.
  4. **
  5. ** Permission is hereby granted, free of charge, to any person obtaining
  6. ** a copy of this software and associated documentation files (the
  7. ** "Software"), to deal in the Software without restriction, including
  8. ** without limitation the rights to use, copy, modify, merge, publish,
  9. ** distribute, sublicense, and/or sell copies of the Software, and to
  10. ** permit persons to whom the Software is furnished to do so, subject to
  11. ** the following conditions:
  12. **
  13. ** The above copyright notice and this permission notice shall be
  14. ** included in all copies or substantial portions of the Software.
  15. **
  16. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. **
  24. ****************************************************************************/
  25. #ifndef QXLSX_XLSXDOCUMENT_H
  26. #define QXLSX_XLSXDOCUMENT_H
  27. #include "xlsxglobal.h"
  28. #include "xlsxformat.h"
  29. #include "xlsxworksheet.h"
  30. #include <QObject>
  31. #include <QVariant>
  32. class QIODevice;
  33. class QImage;
  34. QT_BEGIN_NAMESPACE_XLSX
  35. class Workbook;
  36. class Cell;
  37. class CellRange;
  38. class DataValidation;
  39. class ConditionalFormatting;
  40. class Chart;
  41. class CellReference;
  42. class DocumentPrivate;
  43. class Q_XLSX_EXPORT Document : public QObject
  44. {
  45. Q_OBJECT
  46. Q_DECLARE_PRIVATE(Document)
  47. public:
  48. explicit Document(QObject *parent = 0);
  49. Document(const QString &xlsxName, QObject *parent=0);
  50. Document(QIODevice *device, QObject *parent=0);
  51. ~Document();
  52. bool write(const CellReference &cell, const QVariant &value, const Format &format=Format());
  53. bool write(int row, int col, const QVariant &value, const Format &format=Format());
  54. QVariant read(const CellReference &cell) const;
  55. QVariant read(int row, int col) const;
  56. bool insertImage(int row, int col, const QImage &image);
  57. Chart *insertChart(int row, int col, const QSize &size);
  58. bool mergeCells(const CellRange &range, const Format &format=Format());
  59. bool unmergeCells(const CellRange &range);
  60. bool setColumnWidth(const CellRange &range, double width);
  61. bool setColumnFormat(const CellRange &range, const Format &format);
  62. bool setColumnHidden(const CellRange &range, bool hidden);
  63. bool setColumnWidth(int column, double width);
  64. bool setColumnFormat(int column, const Format &format);
  65. bool setColumnHidden(int column, bool hidden);
  66. bool setColumnWidth(int colFirst, int colLast, double width);
  67. bool setColumnFormat(int colFirst, int colLast, const Format &format);
  68. bool setColumnHidden(int colFirst, int colLast, bool hidden);
  69. double columnWidth(int column);
  70. Format columnFormat(int column);
  71. bool isColumnHidden(int column);
  72. bool setRowHeight(int row, double height);
  73. bool setRowFormat(int row, const Format &format);
  74. bool setRowHidden(int row, bool hidden);
  75. bool setRowHeight(int rowFirst, int rowLast, double height);
  76. bool setRowFormat(int rowFirst, int rowLast, const Format &format);
  77. bool setRowHidden(int rowFirst, int rowLast, bool hidden);
  78. double rowHeight(int row);
  79. Format rowFormat(int row);
  80. bool isRowHidden(int row);
  81. bool groupRows(int rowFirst, int rowLast, bool collapsed = true);
  82. bool groupColumns(int colFirst, int colLast, bool collapsed = true);
  83. bool addDataValidation(const DataValidation &validation);
  84. bool addConditionalFormatting(const ConditionalFormatting &cf);
  85. Cell *cellAt(const CellReference &cell) const;
  86. Cell *cellAt(int row, int col) const;
  87. bool defineName(const QString &name, const QString &formula, const QString &comment=QString(), const QString &scope=QString());
  88. CellRange dimension() const;
  89. QString documentProperty(const QString &name) const;
  90. void setDocumentProperty(const QString &name, const QString &property);
  91. QStringList documentPropertyNames() const;
  92. QStringList sheetNames() const;
  93. bool addSheet(const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
  94. bool insertSheet(int index, const QString &name = QString(), AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
  95. bool selectSheet(const QString &name);
  96. bool renameSheet(const QString &oldName, const QString &newName);
  97. bool copySheet(const QString &srcName, const QString &distName = QString());
  98. bool moveSheet(const QString &srcName, int distIndex);
  99. bool deleteSheet(const QString &name);
  100. Workbook *workbook() const;
  101. AbstractSheet *sheet(const QString &sheetName) const;
  102. AbstractSheet *currentSheet() const;
  103. Worksheet *currentWorksheet() const;
  104. bool save() const;
  105. bool saveAs(const QString &xlsXname) const;
  106. bool saveAs(QIODevice *device) const;
  107. private:
  108. Q_DISABLE_COPY(Document)
  109. DocumentPrivate * const d_ptr;
  110. };
  111. QT_END_NAMESPACE_XLSX
  112. #endif // QXLSX_XLSXDOCUMENT_H