xlsxdocument.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // xlsxdocument.h
  2. #ifndef QXLSX_XLSXDOCUMENT_H
  3. #define QXLSX_XLSXDOCUMENT_H
  4. #include <QtGlobal>
  5. #include <QObject>
  6. #include <QVariant>
  7. #include <QIODevice>
  8. #include <QImage>
  9. #include "xlsxglobal.h"
  10. #include "xlsxformat.h"
  11. #include "xlsxworksheet.h"
  12. QT_BEGIN_NAMESPACE_XLSX
  13. class Workbook;
  14. class Cell;
  15. class CellRange;
  16. class DataValidation;
  17. class ConditionalFormatting;
  18. class Chart;
  19. class CellReference;
  20. class DocumentPrivate;
  21. class Document : public QObject
  22. {
  23. Q_OBJECT
  24. Q_DECLARE_PRIVATE(Document) // D-Pointer. Qt classes have a Q_DECLARE_PRIVATE
  25. // macro in the public class. The macro reads: qglobal.h
  26. public:
  27. explicit Document(QObject *parent = NULL);
  28. Document(const QString& xlsxName, QObject* parent = NULL);
  29. Document(QIODevice* device, QObject* parent = NULL);
  30. ~Document();
  31. bool write(const CellReference &cell, const QVariant &value, const Format &format=Format());
  32. bool write(int row, int col, const QVariant &value, const Format &format=Format());
  33. QVariant read(const CellReference &cell) const;
  34. QVariant read(int row, int col) const;
  35. int insertImage(int row, int col, const QImage &image);
  36. bool getImage(int imageIndex, QImage& img);
  37. bool getImage(int row, int col, QImage& img);
  38. uint getImageCount();
  39. Chart *insertChart(int row, int col, const QSize &size);
  40. bool mergeCells(const CellRange &range, const Format &format=Format());
  41. bool unmergeCells(const CellRange &range);
  42. bool setColumnWidth(const CellRange &range, double width);
  43. bool setColumnFormat(const CellRange &range, const Format &format);
  44. bool setColumnHidden(const CellRange &range, bool hidden);
  45. bool setColumnWidth(int column, double width);
  46. bool setColumnFormat(int column, const Format &format);
  47. bool setColumnHidden(int column, bool hidden);
  48. bool setColumnWidth(int colFirst, int colLast, double width);
  49. bool setColumnFormat(int colFirst, int colLast, const Format &format);
  50. bool setColumnHidden(int colFirst, int colLast, bool hidden);
  51. double columnWidth(int column);
  52. Format columnFormat(int column);
  53. bool isColumnHidden(int column);
  54. bool setRowHeight(int row, double height);
  55. bool setRowFormat(int row, const Format &format);
  56. bool setRowHidden(int row, bool hidden);
  57. bool setRowHeight(int rowFirst, int rowLast, double height);
  58. bool setRowFormat(int rowFirst, int rowLast, const Format &format);
  59. bool setRowHidden(int rowFirst, int rowLast, bool hidden);
  60. double rowHeight(int row);
  61. Format rowFormat(int row);
  62. bool isRowHidden(int row);
  63. bool groupRows(int rowFirst, int rowLast, bool collapsed = true);
  64. bool groupColumns(int colFirst, int colLast, bool collapsed = true);
  65. bool addDataValidation(const DataValidation &validation);
  66. bool addConditionalFormatting(const ConditionalFormatting &cf);
  67. Cell *cellAt(const CellReference &cell) const;
  68. Cell *cellAt(int row, int col) const;
  69. bool defineName(const QString &name, const QString &formula,
  70. const QString &comment=QString(), const QString &scope=QString());
  71. CellRange dimension() const;
  72. QString documentProperty(const QString &name) const;
  73. void setDocumentProperty(const QString &name, const QString &property);
  74. QStringList documentPropertyNames() const;
  75. QStringList sheetNames() const;
  76. bool addSheet(const QString &name = QString(),
  77. AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
  78. bool insertSheet(int index, const QString &name = QString(),
  79. AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet);
  80. bool selectSheet(const QString &name);
  81. bool renameSheet(const QString &oldName, const QString &newName);
  82. bool copySheet(const QString &srcName, const QString &distName = QString());
  83. bool moveSheet(const QString &srcName, int distIndex);
  84. bool deleteSheet(const QString &name);
  85. Workbook *workbook() const;
  86. AbstractSheet *sheet(const QString &sheetName) const;
  87. AbstractSheet *currentSheet() const;
  88. Worksheet *currentWorksheet() const;
  89. bool save() const;
  90. bool saveAs(const QString &xlsXname) const;
  91. bool saveAs(QIODevice *device) const;
  92. // copy style from one xlsx file to other
  93. static bool copyStyle(const QString &from, const QString &to);
  94. bool isLoadPackage() const;
  95. bool load() const; // equals to isLoadPackage()
  96. bool changeimage(int filenoinmidea,QString newfile); // add by liufeijin20181025
  97. bool autosizeColumnWidth(const CellRange &range);
  98. bool autosizeColumnWidth(int column);
  99. bool autosizeColumnWidth(int colFirst, int colLast);
  100. bool autosizeColumnWidth(void);
  101. private:
  102. QMap<int, int> getMaximalColumnWidth(int firstRow=1, int lastRow=INT_MAX);
  103. private:
  104. Q_DISABLE_COPY(Document) // Disables the use of copy constructors and
  105. // assignment operators for the given Class.
  106. DocumentPrivate* const d_ptr;
  107. };
  108. QT_END_NAMESPACE_XLSX
  109. #endif // QXLSX_XLSXDOCUMENT_H