SimpleXlsx  r0.19
 All Classes Namespaces Functions Variables Enumerations Pages
SimpleXlsxDef.h
1 #ifndef __SIMPLE_XLSX_DEF_H__
2 #define __SIMPLE_XLSX_DEF_H__
3 
4 #include <stdint.h>
5 #include <vector>
6 #include <map>
7 #include <string>
8 #include <utility>
9 #include <ctime>
10 #include <fstream>
11 
12 #ifdef _WIN32
13 #include <tchar.h>
14 #else
15 #include "../tchar.h"
16 #endif // _WIN32
17 
18 #ifdef _UNICODE
19  typedef std::wofstream _tofstream;
20  typedef std::wstring _tstring;
21  typedef std::wostringstream _tstringstream;
22  typedef std::wostream _tstream;
23 #else
24  typedef std::ofstream _tofstream;
25  typedef std::string _tstring;
26  typedef std::ostringstream _tstringstream;
27  typedef std::ostream _tstream;
28 #endif // _UNICODE
29 
30 #define SIMPLE_XLSX_VERSION _T("0.19")
31 
32 namespace SimpleXlsx {
33 
36  CHART_NONE = -1,
37  CHART_LINEAR = 0,
38  CHART_BAR,
39  CHART_SCATTER,
40 };
41 
44  BORDER_NONE = 0,
45  BORDER_THIN,
46  BORDER_MEDIUM,
47  BORDER_DASHED,
48  BORDER_DOTTED,
49  BORDER_THICK,
50  BORDER_DOUBLE,
51  BORDER_HAIR,
52  BORDER_MEDIUM_DASHED,
53  BORDER_DASH_DOT,
54  BORDER_MEDIUM_DASH_DOT,
55  BORDER_DASH_DOT_DOT,
56  BORDER_MEDIUM_DASH_DOT_DOT,
57  BORDER_SLANT_DASH_DOT
58 };
59 
62  FONT_NORMAL = 0,
63  FONT_BOLD = 1,
64  FONT_ITALIC = 2,
65  FONT_UNDERLINED = 4,
66  FONT_STRIKE = 8,
67  FONT_OUTLINE = 16,
68  FONT_SHADOW = 32,
69  FONT_CONDENSE = 64,
70  FONT_EXTEND = 128,
71 };
72 
75  PATTERN_NONE = 0,
76  PATTERN_SOLID,
77  PATTERN_MEDIUM_GRAY,
78  PATTERN_DARK_GRAY,
79  PATTERN_LIGHT_GRAY,
80  PATTERN_DARK_HORIZ,
81  PATTERN_DARK_VERT,
82  PATTERN_DARK_DOWN,
83  PATTERN_DARK_UP,
84  PATTERN_DARK_GRID,
85  PATTERN_DARK_TRELLIS,
86  PATTERN_LIGHT_HORIZ,
87  PATTERN_LIGHT_VERT,
88  PATTERN_LIGHT_DOWN,
89  PATTERN_LIGHT_UP,
90  PATTERN_LIGHT_GRID,
91  PATTERN_LIGHT_TRELLIS,
92  PATTERN_GRAY_125,
93  PATTERN_GRAY_0625
94 };
95 
98  ALIGN_H_NONE = 0,
99  ALIGN_H_LEFT,
100  ALIGN_H_CENTER,
101  ALIGN_H_RIGHT
102 };
103 
106  ALIGN_V_NONE = 0,
107  ALIGN_V_TOP,
108  ALIGN_V_CENTER,
109  ALIGN_V_BOTTOM
110 };
111 
114  NUMSTYLE_GENERAL = 0,
115  NUMSTYLE_NUMERIC,
116  NUMSTYLE_PERCENTAGE,
117  NUMSTYLE_EXPONENTIAL,
118  NUMSTYLE_FINANCIAL,
119  NUMSTYLE_MONEY,
120  NUMSTYLE_DATE,
121  NUMSTYLE_TIME,
122  NUMSTYLE_DATETIME,
123 };
124 
127  NUMSTYLE_COLOR_DEFAULT = 0,
128  NUMSTYLE_COLOR_BLACK,
129  NUMSTYLE_COLOR_GREEN,
130  NUMSTYLE_COLOR_WHITE,
131  NUMSTYLE_COLOR_BLUE,
132  NUMSTYLE_COLOR_MAGENTA,
133  NUMSTYLE_COLOR_YELLOW,
134  NUMSTYLE_COLOR_CYAN,
135  NUMSTYLE_COLOR_RED
136 };
137 
140 class Font {
141 public:
142  int32_t size;
143  _tstring name;
144  bool theme;
145  _tstring color;
146  int32_t attributes;
147 
148 public:
149  Font() {
150  Clear();
151  }
152 
153  void Clear() {
154  size = 11;
155  name = _T("Calibri");
156  theme = true;
157  color = _T("");
158  attributes = FONT_NORMAL;
159  }
160 
161  bool operator==(const Font& _font) const {
162  return (size == _font.size && name == _font.name && theme == _font.theme &&
163  color == _font.color && attributes == _font.attributes);
164  }
165 };
166 
170 class Fill {
171 public:
173  _tstring fgColor;
174  _tstring bgColor;
175 
176 public:
177  Fill() {
178  Clear();
179  }
180 
181  void Clear() {
182  patternType = PATTERN_NONE;
183  fgColor = _T("");
184  bgColor = _T("");
185  }
186 
187  bool operator==(const Fill& _fill) const {
188  return (patternType == _fill.patternType && fgColor == _fill.fgColor && bgColor == _fill.bgColor);
189  }
190 };
191 
194 class Border {
195 public:
197  struct BorderItem {
199  _tstring color;
200 
201  BorderItem() {
202  Clear();
203  }
204 
205  void Clear() {
206  style = BORDER_NONE;
207  color = _T("");
208  }
209 
210  bool operator==(const BorderItem& _borderItem) const {
211  return (color == _borderItem.color && style == _borderItem.style);
212  }
213  };
214 
215 public:
223 
224 public:
225  Border() {
226  Clear();
227  }
228 
229  void Clear() {
230  isDiagonalUp = false;
231  isDiagonalDown = false;
232 
233  left.Clear();
234  right.Clear();
235  bottom.Clear();
236  top.Clear();
237  }
238 
239  bool operator==(const Border& _border) const {
240  return (isDiagonalUp == _border.isDiagonalUp && isDiagonalDown == _border.isDiagonalDown &&
241  left == _border.left && right == _border.right &&
242  bottom == _border.bottom && top == _border.top);
243  }
244 };
245 
247 class NumFormat {
248 public:
249  mutable size_t id;
250 
251  _tstring formatString;
252 
259 
260 public:
261  NumFormat() {
262  Clear();
263  }
264 
265  void Clear() {
266  id = 164;
267  formatString = _T("");
268 
269  numberStyle = NUMSTYLE_GENERAL;
270  positiveColor = NUMSTYLE_COLOR_DEFAULT;
271  negativeColor = NUMSTYLE_COLOR_DEFAULT;
272  zeroColor = NUMSTYLE_COLOR_DEFAULT;
273  showThousandsSeparator = false;
275  }
276 
277  bool operator==(const NumFormat& _num) const {
278  return (formatString == _num.formatString &&
279  numberStyle == _num.numberStyle && numberOfDigitsAfterPoint == _num.numberOfDigitsAfterPoint &&
280  positiveColor == _num.positiveColor && negativeColor == _num.negativeColor &&
281  zeroColor == _num.zeroColor && showThousandsSeparator == _num.showThousandsSeparator);
282  }
283 };
284 
289 class Style {
290 public:
297  bool wrapText;
298 
299 public:
300  Style() {
301  Clear();
302  }
303 
304  void Clear() {
305  font.Clear();
306  fill.Clear();
307  border.Clear();
308  horizAlign = ALIGN_H_NONE;
309  vertAlign = ALIGN_V_NONE;
310  wrapText = false;
311  }
312 };
313 
315 class CellCoord {
316 public:
317  uint32_t row;
318  uint32_t col;
319 
320 public:
321  CellCoord() { Clear(); }
322  CellCoord(uint32_t _r, uint32_t _c) : row(_r), col(_c) {}
323 
324  void Clear() {
325  row = 1;
326  col = 0;
327  }
328 };
329 
331 class ColumnWidth {
332 public:
333  uint32_t colFrom;
334  uint32_t colTo;
335  float width;
336 
337 public:
338  ColumnWidth() {colFrom = colTo = 0; width = 15;}
339  ColumnWidth(uint32_t min, uint32_t max, float w) : colFrom(min), colTo(max), width(w) {}
340 };
341 
342 class CellDataStr {
343 public:
344  _tstring value;
345  int32_t style_id;
346 
347 public:
348  CellDataStr() : value(_T("")), style_id(0) {}
349  CellDataStr(const TCHAR *pStr) : value(pStr), style_id(0) {}
350  CellDataStr(const _tstring &_str) : value(_str), style_id(0) {}
351 
352  CellDataStr& operator=(const CellDataStr& obj) {
353  value = obj.value;
354  style_id = obj.style_id;
355  return *this;
356  }
357 
358  CellDataStr& operator=(const TCHAR *pStr) {
359  value = pStr;
360  return *this;
361  }
362 
363  CellDataStr& operator=(const _tstring &_str) {
364  value = _str;
365  return *this;
366  }
367 };
369 public:
370  time_t value;
371  int32_t style_id;
372 
373 public:
374  CellDataTime() : value(0), style_id(0) {}
375  CellDataTime(time_t _val) : value(_val), style_id(0) {}
376 
377  CellDataTime& operator=(const CellDataTime& obj) {
378  value = obj.value;
379  style_id = obj.style_id;
380  return *this;
381  }
382 
383  CellDataTime& operator=(time_t _val) {
384  value = _val;
385  return *this;
386  }
387 };
388 class CellDataInt {
389 public:
390  int32_t value;
391  int32_t style_id;
392 
393 public:
394  CellDataInt() : value(0), style_id(0) {}
395  CellDataInt(int32_t _val) : value(_val), style_id(0) {}
396 
397  CellDataInt& operator=(const CellDataInt& obj) {
398  value = obj.value;
399  style_id = obj.style_id;
400  return *this;
401  }
402 
403  CellDataInt& operator=(int32_t _val) {
404  value = _val;
405  return *this;
406  }
407 };
409 public:
410  uint32_t value;
411  int32_t style_id;
412 
413 public:
414  CellDataUInt() : value(0), style_id(0) {}
415  CellDataUInt(uint32_t _val) : value(_val), style_id(0) {}
416 
417  CellDataUInt& operator=(const CellDataUInt& obj) {
418  value = obj.value;
419  style_id = obj.style_id;
420  return *this;
421  }
422 
423  CellDataUInt& operator=(uint32_t _val) {
424  value = _val;
425  return *this;
426  }
427 };
428 class CellDataDbl {
429 public:
430  double value;
431  int32_t style_id;
432 
433 public:
434  CellDataDbl() : value(0.0), style_id(0) {}
435  CellDataDbl(double _val) : value(_val), style_id(0) {}
436 
437  CellDataDbl& operator=(const CellDataDbl& obj) {
438  value = obj.value;
439  style_id = obj.style_id;
440  return *this;
441  }
442 
443  CellDataDbl& operator=(double _val) {
444  value = _val;
445  return *this;
446  }
447 };
448 class CellDataFlt {
449 public:
450  float value;
451  int32_t style_id;
452 
453 public:
454  CellDataFlt() : value(0.0), style_id(0) {}
455  CellDataFlt(float _val) : value(_val), style_id(0) {}
456 
457  CellDataFlt& operator=(const CellDataFlt& obj) {
458  value = obj.value;
459  style_id = obj.style_id;
460  return *this;
461  }
462 
463  CellDataFlt& operator=(float _val) {
464  value = _val;
465  return *this;
466  }
467 };
468 
470 struct Comment {
472  std::vector<std::pair<Font, _tstring> > contents;
474  _tstring fillColor;
475  bool isHidden;
476  int x;
477  int y;
478  int width;
479  int height;
480 
481  Comment() {
482  Clear();
483  }
484 
485  void Clear() {
486  contents.clear();
487  cellRef.Clear();
488  fillColor = _T("#FFEFD5"); // papaya whip
489  isHidden = true;
490  x = y = 50;
491  width = height = 100;
492  }
493 
494  bool operator < (const Comment& _comm) const {
495  return (sheetIndex < _comm.sheetIndex);
496  }
497 };
498 
499 } // namespace SimpleXlsx
500 
501 #endif // __SIMPLE_XLSX_DEF_H__