File indexing completed on 2024-06-23 03:45:56
0001 // xlsxdocument.h 0002 0003 #ifndef QXLSX_XLSXDOCUMENT_H 0004 #define QXLSX_XLSXDOCUMENT_H 0005 0006 #include <QtGlobal> 0007 #include <QObject> 0008 #include <QVariant> 0009 #include <QIODevice> 0010 #include <QImage> 0011 0012 #include "xlsxglobal.h" 0013 #include "xlsxformat.h" 0014 #include "xlsxworksheet.h" 0015 0016 QT_BEGIN_NAMESPACE_XLSX 0017 0018 class Workbook; 0019 class Cell; 0020 class CellRange; 0021 class DataValidation; 0022 class ConditionalFormatting; 0023 class Chart; 0024 class CellReference; 0025 class DocumentPrivate; 0026 0027 class QXLSX_EXPORT Document : public QObject 0028 { 0029 Q_OBJECT 0030 Q_DECLARE_PRIVATE(Document) // D-Pointer. Qt classes have a Q_DECLARE_PRIVATE 0031 // macro in the public class. The macro reads: qglobal.h 0032 public: 0033 explicit Document(QObject *parent = nullptr); 0034 Document(const QString& xlsxName, QObject* parent = nullptr); 0035 Document(QIODevice* device, QObject* parent = nullptr); 0036 ~Document(); 0037 0038 bool write(const CellReference &cell, const QVariant &value, const Format &format=Format()); 0039 bool write(int row, int col, const QVariant &value, const Format &format=Format()); 0040 0041 QVariant read(const CellReference &cell) const; 0042 QVariant read(int row, int col) const; 0043 0044 int insertImage(int row, int col, const QImage &image); 0045 bool getImage(int imageIndex, QImage& img); 0046 bool getImage(int row, int col, QImage& img); 0047 uint getImageCount(); 0048 0049 Chart *insertChart(int row, int col, const QSize &size); 0050 0051 bool mergeCells(const CellRange &range, const Format &format=Format()); 0052 bool unmergeCells(const CellRange &range); 0053 0054 bool setColumnWidth(const CellRange &range, double width); 0055 bool setColumnFormat(const CellRange &range, const Format &format); 0056 bool setColumnHidden(const CellRange &range, bool hidden); 0057 bool setColumnWidth(int column, double width); 0058 bool setColumnFormat(int column, const Format &format); 0059 bool setColumnHidden(int column, bool hidden); 0060 bool setColumnWidth(int colFirst, int colLast, double width); 0061 bool setColumnFormat(int colFirst, int colLast, const Format &format); 0062 bool setColumnHidden(int colFirst, int colLast, bool hidden); 0063 0064 double columnWidth(int column); 0065 Format columnFormat(int column); 0066 bool isColumnHidden(int column); 0067 0068 bool setRowHeight(int row, double height); 0069 bool setRowFormat(int row, const Format &format); 0070 bool setRowHidden(int row, bool hidden); 0071 bool setRowHeight(int rowFirst, int rowLast, double height); 0072 bool setRowFormat(int rowFirst, int rowLast, const Format &format); 0073 bool setRowHidden(int rowFirst, int rowLast, bool hidden); 0074 0075 double rowHeight(int row); 0076 Format rowFormat(int row); 0077 bool isRowHidden(int row); 0078 0079 bool groupRows(int rowFirst, int rowLast, bool collapsed = true); 0080 bool groupColumns(int colFirst, int colLast, bool collapsed = true); 0081 0082 bool addDataValidation(const DataValidation &validation); 0083 bool addConditionalFormatting(const ConditionalFormatting &cf); 0084 0085 Cell *cellAt(const CellReference &cell) const; 0086 Cell *cellAt(int row, int col) const; 0087 0088 bool defineName(const QString &name, const QString &formula, 0089 const QString &comment=QString(), const QString &scope=QString()); 0090 0091 CellRange dimension() const; 0092 0093 QString documentProperty(const QString &name) const; 0094 void setDocumentProperty(const QString &name, const QString &property); 0095 QStringList documentPropertyNames() const; 0096 0097 QStringList sheetNames() const; 0098 bool addSheet(const QString &name = QString(), 0099 AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); 0100 bool insertSheet(int index, const QString &name = QString(), 0101 AbstractSheet::SheetType type = AbstractSheet::ST_WorkSheet); 0102 bool selectSheet(const QString &name); 0103 bool selectSheet(int index); 0104 bool renameSheet(const QString &oldName, const QString &newName); 0105 bool copySheet(const QString &srcName, const QString &distName = QString()); 0106 bool moveSheet(const QString &srcName, int distIndex); 0107 bool deleteSheet(const QString &name); 0108 0109 Workbook *workbook() const; 0110 AbstractSheet *sheet(const QString &sheetName) const; 0111 AbstractSheet *currentSheet() const; 0112 Worksheet *currentWorksheet() const; 0113 0114 bool save() const; 0115 bool saveAs(const QString &xlsXname) const; 0116 bool saveAs(QIODevice *device) const; 0117 0118 // copy style from one xlsx file to other 0119 static bool copyStyle(const QString &from, const QString &to); 0120 0121 bool isLoadPackage() const; 0122 bool load() const; // equals to isLoadPackage() 0123 0124 bool changeimage(int filenoinmidea,QString newfile); // add by liufeijin20181025 0125 0126 bool autosizeColumnWidth(const CellRange &range); 0127 bool autosizeColumnWidth(int column); 0128 bool autosizeColumnWidth(int colFirst, int colLast); 0129 bool autosizeColumnWidth(void); 0130 0131 private: 0132 QMap<int, int> getMaximalColumnWidth(int firstRow=1, int lastRow=INT_MAX); 0133 0134 0135 private: 0136 Q_DISABLE_COPY(Document) // Disables the use of copy constructors and 0137 // assignment operators for the given Class. 0138 DocumentPrivate* const d_ptr; 0139 }; 0140 0141 QT_END_NAMESPACE_XLSX 0142 0143 #endif // QXLSX_XLSXDOCUMENT_H