1 // xlsxworksheet_p.h 2 3 #ifndef XLSXWORKSHEET_P_H 4 #define XLSXWORKSHEET_P_H 5 6 #include <QtGlobal> 7 #include <QObject> 8 #include <QString> 9 #include <QVector> 10 #include <QImage> 11 #include <QSharedPointer> 12 13 #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) 14 #include <QRegularExpression> 15 #else 16 #include <QRegExp> 17 #endif 18 19 #include "xlsxworksheet.h" 20 #include "xlsxabstractsheet_p.h" 21 #include "xlsxcell.h" 22 #include "xlsxdatavalidation.h" 23 #include "xlsxconditionalformatting.h" 24 #include "xlsxcellformula.h" 25 26 class QXmlStreamWriter; 27 class QXmlStreamReader; 28 29 QT_BEGIN_NAMESPACE_XLSX 30 31 const int XLSX_ROW_MAX = 1048576; 32 const int XLSX_COLUMN_MAX = 16384; 33 const int XLSX_STRING_MAX = 32767; 34 35 class SharedStrings; 36 37 struct XlsxHyperlinkData 38 { 39 enum LinkType 40 { 41 External, 42 Internal 43 }; 44 45 XlsxHyperlinkData(LinkType linkType=External, const QString &target=QString(), const QString &location=QString() 46 , const QString &display=QString(), const QString &tip=QString()) linkTypeXlsxHyperlinkData47 :linkType(linkType), target(target), location(location), display(display), tooltip(tip) 48 { 49 50 } 51 52 LinkType linkType; 53 QString target; //For External link 54 QString location; 55 QString display; 56 QString tooltip; 57 }; 58 59 // ECMA-376 Part1 18.3.1.81 60 struct XlsxSheetFormatProps 61 { 62 XlsxSheetFormatProps(int baseColWidth = 8, 63 bool customHeight = false, 64 double defaultColWidth = 0.0, 65 double defaultRowHeight = 15, 66 quint8 outlineLevelCol = 0, 67 quint8 outlineLevelRow = 0, 68 bool thickBottom = false, 69 bool thickTop = false, 70 bool zeroHeight = false) : baseColWidthXlsxSheetFormatProps71 baseColWidth(baseColWidth), 72 customHeight(customHeight), 73 defaultColWidth(defaultColWidth), 74 defaultRowHeight(defaultRowHeight), 75 outlineLevelCol(outlineLevelCol), 76 outlineLevelRow(outlineLevelRow), 77 thickBottom(thickBottom), 78 thickTop(thickTop), 79 zeroHeight(zeroHeight) { 80 } 81 82 int baseColWidth; 83 bool customHeight; 84 double defaultColWidth; 85 double defaultRowHeight; 86 quint8 outlineLevelCol; 87 quint8 outlineLevelRow; 88 bool thickBottom; 89 bool thickTop; 90 bool zeroHeight; 91 }; 92 93 struct XlsxRowInfo 94 { 95 XlsxRowInfo(double height=0, const Format &format=Format(), bool hidden=false) : customHeightXlsxRowInfo96 customHeight(false), height(height), format(format), hidden(hidden), outlineLevel(0) 97 , collapsed(false) 98 { 99 100 } 101 102 bool customHeight; 103 double height; 104 Format format; 105 bool hidden; 106 int outlineLevel; 107 bool collapsed; 108 }; 109 110 struct XlsxColumnInfo 111 { 112 XlsxColumnInfo( int firstColumn, // = 0, 113 int lastColumn, // = 1, 114 bool isSetWidth, 115 double width = 0, 116 const Format &format = Format(), 117 bool hidden = false) firstColumnXlsxColumnInfo118 : firstColumn(firstColumn), 119 lastColumn(lastColumn), 120 customWidth(false), 121 width(width), 122 isSetWidth(isSetWidth), 123 format(format), 124 hidden(hidden), 125 outlineLevel(0), 126 collapsed(false) 127 { 128 129 } 130 131 int firstColumn; 132 int lastColumn; 133 bool customWidth; 134 double width; 135 bool isSetWidth; 136 Format format; 137 bool hidden; 138 int outlineLevel; 139 bool collapsed; 140 }; 141 142 // #ifndef QMapIntSharedPointerCell 143 // typedef QMap<int, QSharedPointer<Cell> > QMapIntSharedPointerCell; 144 // #endif 145 146 class WorksheetPrivate : public AbstractSheetPrivate 147 { 148 Q_DECLARE_PUBLIC(Worksheet) 149 150 public: 151 WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag); 152 ~WorksheetPrivate(); 153 154 public: 155 int checkDimensions(int row, int col, bool ignore_row=false, bool ignore_col=false); 156 Format cellFormat(int row, int col) const; 157 QString generateDimensionString() const; 158 void calculateSpans() const; 159 void splitColsInfo(int colFirst, int colLast); 160 void validateDimension(); 161 162 void saveXmlSheetData(QXmlStreamWriter &writer) const; 163 void saveXmlCellData(QXmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell) const; 164 void saveXmlMergeCells(QXmlStreamWriter &writer) const; 165 void saveXmlHyperlinks(QXmlStreamWriter &writer) const; 166 void saveXmlDrawings(QXmlStreamWriter &writer) const; 167 void saveXmlDataValidations(QXmlStreamWriter &writer) const; 168 169 int rowPixelsSize(int row) const; 170 int colPixelsSize(int col) const; 171 172 void loadXmlSheetData(QXmlStreamReader &reader); 173 void loadXmlColumnsInfo(QXmlStreamReader &reader); 174 void loadXmlMergeCells(QXmlStreamReader &reader); 175 void loadXmlDataValidations(QXmlStreamReader &reader); 176 void loadXmlSheetFormatProps(QXmlStreamReader &reader); 177 void loadXmlSheetViews(QXmlStreamReader &reader); 178 void loadXmlHyperlinks(QXmlStreamReader &reader); 179 180 QList<QSharedPointer<XlsxRowInfo> > getRowInfoList(int rowFirst, int rowLast); 181 QList<QSharedPointer<XlsxColumnInfo> > getColumnInfoList(int colFirst, int colLast); 182 QList<int> getColumnIndexes(int colFirst, int colLast); 183 bool isColumnRangeValid(int colFirst, int colLast); 184 185 SharedStrings *sharedStrings() const; 186 187 public: 188 QMap<int, QMap<int, QSharedPointer<Cell> > > cellTable; 189 190 QMap<int, QMap<int, QString> > comments; 191 QMap<int, QMap<int, QSharedPointer<XlsxHyperlinkData> > > urlTable; 192 QList<CellRange> merges; 193 QMap<int, QSharedPointer<XlsxRowInfo> > rowsInfo; 194 QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfo; 195 QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfoHelper; 196 197 QList<DataValidation> dataValidationsList; 198 QList<ConditionalFormatting> conditionalFormattingList; 199 200 QMap<int, CellFormula> sharedFormulaMap; // shared formula map 201 202 CellRange dimension; 203 int previous_row; 204 205 mutable QMap<int, QString> row_spans; 206 QMap<int, double> row_sizes; 207 QMap<int, double> col_sizes; 208 209 int outline_row_level; 210 int outline_col_level; 211 212 int default_row_height; 213 bool default_row_zeroed; 214 215 // pagesetup and print settings add by liufeijin 20181028, liufeijin 216 QString PpaperSize; 217 QString Pscale; 218 QString PfirstPageNumber; 219 QString Porientation; 220 QString PuseFirstPageNumber; 221 QString PhorizontalDpi; 222 QString PverticalDpi; 223 QString Prid; 224 QString Pcopies; 225 226 // pageMargins, liufeijin 227 QString PMheader; 228 QString PMfooter; 229 QString PMtop; 230 QString PMbotton; 231 QString PMleft; 232 QString PMright; 233 234 // header footer, liufeijin 235 QString MoodFooter; 236 QString ModdHeader; 237 QString MoodalignWithMargins; // add align 20190619 238 239 XlsxSheetFormatProps sheetFormatProps; 240 241 bool windowProtection; 242 bool showFormulas; 243 bool showGridLines; 244 bool showRowColHeaders; 245 bool showZeros; 246 bool rightToLeft; 247 bool tabSelected; 248 bool showRuler; 249 bool showOutlineSymbols; 250 bool showWhiteSpace; 251 252 #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) 253 QRegularExpression urlPattern; 254 #else 255 QRegExp urlPattern; 256 #endif 257 258 private: 259 260 static double calculateColWidth(int characters); 261 }; 262 263 QT_END_NAMESPACE_XLSX 264 #endif // XLSXWORKSHEET_P_H 265