xlsxworksheet_p.h 7.0 KB

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