File indexing completed on 2024-06-23 03:45:57
0001 // xlsxworksheet_p.h 0002 0003 #ifndef XLSXWORKSHEET_P_H 0004 #define XLSXWORKSHEET_P_H 0005 0006 #include <QtGlobal> 0007 #include <QObject> 0008 #include <QString> 0009 #include <QVector> 0010 #include <QImage> 0011 #include <QSharedPointer> 0012 0013 #include <QRegularExpression> 0014 0015 #include "xlsxworksheet.h" 0016 #include "xlsxabstractsheet_p.h" 0017 #include "xlsxcell.h" 0018 #include "xlsxdatavalidation.h" 0019 #include "xlsxconditionalformatting.h" 0020 #include "xlsxcellformula.h" 0021 0022 class QXmlStreamWriter; 0023 class QXmlStreamReader; 0024 0025 QT_BEGIN_NAMESPACE_XLSX 0026 0027 const int XLSX_ROW_MAX = 1048576; 0028 const int XLSX_COLUMN_MAX = 16384; 0029 const int XLSX_STRING_MAX = 32767; 0030 0031 class SharedStrings; 0032 0033 struct XlsxHyperlinkData 0034 { 0035 enum LinkType 0036 { 0037 External, 0038 Internal 0039 }; 0040 0041 XlsxHyperlinkData(LinkType linkType=External, const QString &target=QString(), const QString &location=QString() 0042 , const QString &display=QString(), const QString &tip=QString()) 0043 :linkType(linkType), target(target), location(location), display(display), tooltip(tip) 0044 { 0045 0046 } 0047 0048 LinkType linkType; 0049 QString target; //For External link 0050 QString location; 0051 QString display; 0052 QString tooltip; 0053 }; 0054 0055 // ECMA-376 Part1 18.3.1.81 0056 struct XlsxSheetFormatProps 0057 { 0058 XlsxSheetFormatProps(int baseColWidth = 8, 0059 bool customHeight = false, 0060 double defaultColWidth = 8.430f, // https://learn.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths 0061 double defaultRowHeight = 15, 0062 quint8 outlineLevelCol = 0, 0063 quint8 outlineLevelRow = 0, 0064 bool thickBottom = false, 0065 bool thickTop = false, 0066 bool zeroHeight = false) : 0067 baseColWidth(baseColWidth), 0068 customHeight(customHeight), 0069 defaultColWidth(defaultColWidth), 0070 defaultRowHeight(defaultRowHeight), 0071 outlineLevelCol(outlineLevelCol), 0072 outlineLevelRow(outlineLevelRow), 0073 thickBottom(thickBottom), 0074 thickTop(thickTop), 0075 zeroHeight(zeroHeight) { 0076 } 0077 0078 int baseColWidth; 0079 bool customHeight; 0080 double defaultColWidth; 0081 double defaultRowHeight; 0082 quint8 outlineLevelCol; 0083 quint8 outlineLevelRow; 0084 bool thickBottom; 0085 bool thickTop; 0086 bool zeroHeight; 0087 }; 0088 0089 struct XlsxRowInfo 0090 { 0091 XlsxRowInfo(double height=0, const Format &format=Format(), bool hidden=false) : 0092 customHeight(false), height(height), format(format), hidden(hidden), outlineLevel(0) 0093 , collapsed(false) 0094 { 0095 0096 } 0097 0098 bool customHeight; 0099 double height; 0100 Format format; 0101 bool hidden; 0102 int outlineLevel; 0103 bool collapsed; 0104 }; 0105 0106 struct XlsxColumnInfo 0107 { 0108 XlsxColumnInfo( int firstColumn, // = 0, 0109 int lastColumn, // = 1, 0110 bool isSetWidth, 0111 double width = 0, 0112 const Format &format = Format(), 0113 bool hidden = false) 0114 : width(width), 0115 format(format), 0116 firstColumn(firstColumn), 0117 lastColumn(lastColumn), 0118 outlineLevel(0), 0119 isSetWidth(isSetWidth), 0120 customWidth(false), 0121 hidden(hidden), 0122 collapsed(false) 0123 { 0124 0125 } 0126 0127 double width; 0128 Format format; 0129 int firstColumn; 0130 int lastColumn; 0131 int outlineLevel; 0132 bool isSetWidth; 0133 bool customWidth; 0134 bool hidden; 0135 bool collapsed; 0136 }; 0137 0138 class WorksheetPrivate : public AbstractSheetPrivate 0139 { 0140 Q_DECLARE_PUBLIC(Worksheet) 0141 0142 public: 0143 WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag); 0144 ~WorksheetPrivate(); 0145 0146 public: 0147 int checkDimensions(int row, int col, bool ignore_row=false, bool ignore_col=false); 0148 Format cellFormat(int row, int col) const; 0149 QString generateDimensionString() const; 0150 void calculateSpans() const; 0151 void splitColsInfo(int colFirst, int colLast); 0152 void validateDimension(); 0153 0154 void saveXmlSheetData(QXmlStreamWriter &writer) const; 0155 void saveXmlCellData(QXmlStreamWriter &writer, int row, int col, std::shared_ptr<Cell> cell) const; 0156 void saveXmlMergeCells(QXmlStreamWriter &writer) const; 0157 void saveXmlHyperlinks(QXmlStreamWriter &writer) const; 0158 void saveXmlDrawings(QXmlStreamWriter &writer) const; 0159 void saveXmlDataValidations(QXmlStreamWriter &writer) const; 0160 0161 int rowPixelsSize(int row) const; 0162 int colPixelsSize(int col) const; 0163 0164 void loadXmlSheetData(QXmlStreamReader &reader); 0165 void loadXmlColumnsInfo(QXmlStreamReader &reader); 0166 void loadXmlMergeCells(QXmlStreamReader &reader); 0167 void loadXmlDataValidations(QXmlStreamReader &reader); 0168 void loadXmlSheetFormatProps(QXmlStreamReader &reader); 0169 void loadXmlSheetViews(QXmlStreamReader &reader); 0170 void loadXmlHyperlinks(QXmlStreamReader &reader); 0171 0172 QList<QSharedPointer<XlsxRowInfo> > getRowInfoList(int rowFirst, int rowLast); 0173 QList<QSharedPointer<XlsxColumnInfo> > getColumnInfoList(int colFirst, int colLast); 0174 QList<int> getColumnIndexes(int colFirst, int colLast); 0175 bool isColumnRangeValid(int colFirst, int colLast); 0176 0177 SharedStrings *sharedStrings() const; 0178 0179 public: 0180 QMap<int, QMap<int, std::shared_ptr<Cell> > > cellTable; 0181 0182 QMap<int, QMap<int, QString> > comments; 0183 QMap<int, QMap<int, QSharedPointer<XlsxHyperlinkData> > > urlTable; 0184 QList<CellRange> merges; 0185 QMap<int, QSharedPointer<XlsxRowInfo> > rowsInfo; 0186 QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfo; 0187 QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfoHelper; 0188 0189 QList<DataValidation> dataValidationsList; 0190 QList<ConditionalFormatting> conditionalFormattingList; 0191 0192 QMap<int, CellFormula> sharedFormulaMap; // shared formula map 0193 0194 CellRange dimension; 0195 int previous_row; 0196 0197 mutable QMap<int, QString> row_spans; 0198 QMap<int, double> row_sizes; 0199 QMap<int, double> col_sizes; 0200 0201 int outline_row_level; 0202 int outline_col_level; 0203 0204 int default_row_height; 0205 bool default_row_zeroed; 0206 0207 // pagesetup and print settings add by liufeijin 20181028, liufeijin 0208 QString PpaperSize; 0209 QString Pscale; 0210 QString PfirstPageNumber; 0211 QString Porientation; 0212 QString PuseFirstPageNumber; 0213 QString PhorizontalDpi; 0214 QString PverticalDpi; 0215 QString Prid; 0216 QString Pcopies; 0217 0218 // pageMargins, liufeijin 0219 QString PMheader; 0220 QString PMfooter; 0221 QString PMtop; 0222 QString PMbotton; 0223 QString PMleft; 0224 QString PMright; 0225 0226 // header footer, liufeijin 0227 QString MoodFooter; 0228 QString ModdHeader; 0229 QString MoodalignWithMargins; // add align 20190619 0230 0231 XlsxSheetFormatProps sheetFormatProps; 0232 0233 bool windowProtection; 0234 bool showFormulas; 0235 bool showGridLines; 0236 bool showRowColHeaders; 0237 bool showZeros; 0238 bool rightToLeft; 0239 bool tabSelected; 0240 bool showRuler; 0241 bool showOutlineSymbols; 0242 bool showWhiteSpace; 0243 0244 QRegularExpression urlPattern; 0245 0246 private: 0247 0248 static double calculateColWidth(int characters); 0249 }; 0250 0251 QT_END_NAMESPACE_XLSX 0252 #endif // XLSXWORKSHEET_P_H