xlsxworksheet_p.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /****************************************************************************
  2. ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
  3. ** All right reserved.
  4. **
  5. ** Permission is hereby granted, free of charge, to any person obtaining
  6. ** a copy of this software and associated documentation files (the
  7. ** "Software"), to deal in the Software without restriction, including
  8. ** without limitation the rights to use, copy, modify, merge, publish,
  9. ** distribute, sublicense, and/or sell copies of the Software, and to
  10. ** permit persons to whom the Software is furnished to do so, subject to
  11. ** the following conditions:
  12. **
  13. ** The above copyright notice and this permission notice shall be
  14. ** included in all copies or substantial portions of the Software.
  15. **
  16. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. **
  24. ****************************************************************************/
  25. #ifndef XLSXWORKSHEET_P_H
  26. #define XLSXWORKSHEET_P_H
  27. //
  28. // W A R N I N G
  29. // -------------
  30. //
  31. // This file is not part of the Qt Xlsx API. It exists for the convenience
  32. // of the Qt Xlsx. This header file may change from
  33. // version to version without notice, or even be removed.
  34. //
  35. // We mean it.
  36. //
  37. #include "xlsxworksheet.h"
  38. #include "xlsxabstractsheet_p.h"
  39. #include "xlsxcell.h"
  40. #include "xlsxdatavalidation.h"
  41. #include "xlsxconditionalformatting.h"
  42. #include "xlsxcellformula.h"
  43. #include <QImage>
  44. #include <QSharedPointer>
  45. #include <QRegularExpression>
  46. class QXmlStreamWriter;
  47. class QXmlStreamReader;
  48. namespace QXlsx {
  49. const int XLSX_ROW_MAX = 1048576;
  50. const int XLSX_COLUMN_MAX = 16384;
  51. const int XLSX_STRING_MAX = 32767;
  52. class SharedStrings;
  53. struct XlsxHyperlinkData
  54. {
  55. enum LinkType
  56. {
  57. External,
  58. Internal
  59. };
  60. XlsxHyperlinkData(LinkType linkType=External, const QString &target=QString(), const QString &location=QString()
  61. , const QString &display=QString(), const QString &tip=QString())
  62. :linkType(linkType), target(target), location(location), display(display), tooltip(tip)
  63. {
  64. }
  65. LinkType linkType;
  66. QString target; //For External link
  67. QString location;
  68. QString display;
  69. QString tooltip;
  70. };
  71. // ECMA-376 Part1 18.3.1.81
  72. struct XlsxSheetFormatProps
  73. {
  74. XlsxSheetFormatProps(int baseColWidth = 8,
  75. bool customHeight = false,
  76. double defaultColWidth = 0.0,
  77. double defaultRowHeight = 15,
  78. quint8 outlineLevelCol = 0,
  79. quint8 outlineLevelRow = 0,
  80. bool thickBottom = false,
  81. bool thickTop = false,
  82. bool zeroHeight = false) :
  83. baseColWidth(baseColWidth),
  84. customHeight(customHeight),
  85. defaultColWidth(defaultColWidth),
  86. defaultRowHeight(defaultRowHeight),
  87. outlineLevelCol(outlineLevelCol),
  88. outlineLevelRow(outlineLevelRow),
  89. thickBottom(thickBottom),
  90. thickTop(thickTop),
  91. zeroHeight(zeroHeight) {
  92. }
  93. int baseColWidth;
  94. bool customHeight;
  95. double defaultColWidth;
  96. double defaultRowHeight;
  97. quint8 outlineLevelCol;
  98. quint8 outlineLevelRow;
  99. bool thickBottom;
  100. bool thickTop;
  101. bool zeroHeight;
  102. };
  103. struct XlsxRowInfo
  104. {
  105. XlsxRowInfo(double height=0, const Format &format=Format(), bool hidden=false) :
  106. customHeight(false), height(height), format(format), hidden(hidden), outlineLevel(0)
  107. , collapsed(false)
  108. {
  109. }
  110. bool customHeight;
  111. double height;
  112. Format format;
  113. bool hidden;
  114. int outlineLevel;
  115. bool collapsed;
  116. };
  117. struct XlsxColumnInfo
  118. {
  119. XlsxColumnInfo(int firstColumn=0, int lastColumn=1, double width=0, const Format &format=Format(), bool hidden=false) :
  120. firstColumn(firstColumn), lastColumn(lastColumn), customWidth(false), width(width), format(format), hidden(hidden)
  121. , outlineLevel(0), collapsed(false)
  122. {
  123. }
  124. int firstColumn;
  125. int lastColumn;
  126. bool customWidth;
  127. double width;
  128. Format format;
  129. bool hidden;
  130. int outlineLevel;
  131. bool collapsed;
  132. };
  133. class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public AbstractSheetPrivate
  134. {
  135. Q_DECLARE_PUBLIC(Worksheet)
  136. public:
  137. WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag);
  138. ~WorksheetPrivate();
  139. int checkDimensions(int row, int col, bool ignore_row=false, bool ignore_col=false);
  140. Format cellFormat(int row, int col) const;
  141. QString generateDimensionString() const;
  142. void calculateSpans() const;
  143. void splitColsInfo(int colFirst, int colLast);
  144. void validateDimension();
  145. void saveXmlSheetData(QXmlStreamWriter &writer) const;
  146. void saveXmlCellData(QXmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell) const;
  147. void saveXmlMergeCells(QXmlStreamWriter &writer) const;
  148. void saveXmlHyperlinks(QXmlStreamWriter &writer) const;
  149. void saveXmlDrawings(QXmlStreamWriter &writer) const;
  150. void saveXmlDataValidations(QXmlStreamWriter &writer) const;
  151. int rowPixelsSize(int row) const;
  152. int colPixelsSize(int col) const;
  153. void loadXmlSheetData(QXmlStreamReader &reader);
  154. void loadXmlColumnsInfo(QXmlStreamReader &reader);
  155. void loadXmlMergeCells(QXmlStreamReader &reader);
  156. void loadXmlDataValidations(QXmlStreamReader &reader);
  157. void loadXmlSheetFormatProps(QXmlStreamReader &reader);
  158. void loadXmlSheetViews(QXmlStreamReader &reader);
  159. void loadXmlHyperlinks(QXmlStreamReader &reader);
  160. QList<QSharedPointer<XlsxRowInfo> > getRowInfoList(int rowFirst, int rowLast);
  161. QList <QSharedPointer<XlsxColumnInfo> > getColumnInfoList(int colFirst, int colLast);
  162. QList<int> getColumnIndexes(int colFirst, int colLast);
  163. bool isColumnRangeValid(int colFirst, int colLast);
  164. SharedStrings *sharedStrings() const;
  165. QMap<int, QMap<int, QSharedPointer<Cell> > > cellTable;
  166. QMap<int, QMap<int, QString> > comments;
  167. QMap<int, QMap<int, QSharedPointer<XlsxHyperlinkData> > > urlTable;
  168. QList<CellRange> merges;
  169. QMap<int, QSharedPointer<XlsxRowInfo> > rowsInfo;
  170. QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfo;
  171. QMap<int, QSharedPointer<XlsxColumnInfo> > colsInfoHelper;
  172. QList<DataValidation> dataValidationsList;
  173. QList<ConditionalFormatting> conditionalFormattingList;
  174. QMap<int, CellFormula> sharedFormulaMap;
  175. CellRange dimension;
  176. int previous_row;
  177. mutable QMap<int, QString> row_spans;
  178. QMap<int, double> row_sizes;
  179. QMap<int, double> col_sizes;
  180. int outline_row_level;
  181. int outline_col_level;
  182. int default_row_height;
  183. bool default_row_zeroed;
  184. XlsxSheetFormatProps sheetFormatProps;
  185. bool windowProtection;
  186. bool showFormulas;
  187. bool showGridLines;
  188. bool showRowColHeaders;
  189. bool showZeros;
  190. bool rightToLeft;
  191. bool tabSelected;
  192. bool showRuler;
  193. bool showOutlineSymbols;
  194. bool showWhiteSpace;
  195. QRegularExpression urlPattern;
  196. private:
  197. static double calculateColWidth(int characters);
  198. };
  199. }
  200. #endif // XLSXWORKSHEET_P_H