ExcelFormat.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /*
  2. ExcelFormat.h
  3. Copyright (c) 2009, 2010, 2011 Martin Fuchs <martin-fuchs@gmx.net>
  4. License: CPOL
  5. THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CODE PROJECT OPEN LICENSE ("LICENSE").
  6. THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
  7. AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
  8. BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HEREIN, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS
  9. OF THIS LICENSE. THE AUTHOR GRANTS YOU THE RIGHTS CONTAINED HEREIN IN CONSIDERATION OF YOUR ACCEPTANCE
  10. OF SUCH TERMS AND CONDITIONS. IF YOU DO NOT AGREE TO ACCEPT AND BE BOUND BY THE TERMS OF THIS LICENSE,
  11. YOU CANNOT MAKE ANY USE OF THE WORK.
  12. */
  13. #ifndef EXCELFORMAT_H
  14. #define EXCELFORMAT_H
  15. #include "BasicExcel.hpp"
  16. namespace ExcelFormat {
  17. using namespace YExcel;
  18. #define XLS_FORMAT_GENERAL L"General"
  19. #define XLS_FORMAT_TEXT L"@"
  20. #define XLS_FORMAT_INTEGER L"0"
  21. #define XLS_FORMAT_DECIMAL L"0.00"
  22. #define XLS_FORMAT_PERCENT L"0%"
  23. #define XLS_FORMAT_DATE L"M/D/YY"
  24. #define XLS_FORMAT_TIME L"h:mm:ss"
  25. #define XLS_FORMAT_DATETIME L"M/D/YY h:mm"
  26. #define FIRST_USER_FORMAT_IDX 164
  27. // Font option flags
  28. enum EXCEL_FONT_OPTIONS {
  29. EXCEL_FONT_BOLD = 0x01, // redundant in BIFF5-BIFF8, see ExcelFont::_weight
  30. EXCEL_FONT_ITALIC = 0x02,
  31. EXCEL_FONT_UNDERLINED = 0x04, // redundant in BIFF5-BIFF8, see ExcelFont::_underline_type
  32. EXCEL_FONT_STRUCK_OUT = 0x08,
  33. EXCEL_FONT_OUTLINED = 0x10,
  34. EXCEL_FONT_SHADOWED = 0x20,
  35. EXCEL_FONT_CONDENSED = 0x40,
  36. EXCEL_FONT_EXTENDED = 0x80
  37. };
  38. // Font escapement types
  39. enum EXCEL_ESCAPEMENT {
  40. EXCEL_ESCAPEMENT_NONE = 0,
  41. EXCEL_ESCAPEMENT_SUPERSCRIPT = 1,
  42. EXCEL_ESCAPEMENT_SUBSCRIPT = 2
  43. };
  44. // Font underline types
  45. enum EXCEL_UNDERLINE_FLAGS {
  46. EXCEL_UNDERLINE_NONE = 0x00,
  47. EXCEL_UNDERLINE_SINGLE = 0x01,
  48. EXCEL_UNDERLINE_DOUBLE = 0x02,
  49. EXCEL_UNDERLINE_SINGLE_ACCOUNTING = 0x21,
  50. EXCEL_UNDERLINE_DOUBLE_ACCOUNTING = 0x22
  51. };
  52. // Excel font family constants, see also FF_DONTCARE, ... in wingdi.h
  53. enum EXCEL_FONT_FAMILY {
  54. EXCEL_FONT_FAMILY_DONTCARE = 0,
  55. EXCEL_FONT_FAMILY_ROMAN = 1,
  56. EXCEL_FONT_FAMILY_SWISS = 2,
  57. EXCEL_FONT_FAMILY_MODERN = 3,
  58. EXCEL_FONT_FAMILY_SCRIPT = 4,
  59. EXCEL_FONT_FAMILY_DECORATIVE = 5
  60. };
  61. struct ExcelFont
  62. {
  63. ExcelFont()
  64. : _height(200),
  65. _options(0),
  66. _color_index(0x7FFF),
  67. _weight(400), // FW_NORMAL
  68. _escapement_type(EXCEL_ESCAPEMENT_NONE),
  69. _underline_type(EXCEL_UNDERLINE_NONE),
  70. _font_family(EXCEL_FONT_FAMILY_DONTCARE),
  71. _character_set(0), // ANSI_CHARSET
  72. _name(L"Arial")
  73. {
  74. }
  75. ExcelFont(const Workbook::Font& font)
  76. : _height(font.height_),
  77. _options(font.options_),
  78. _color_index(font.colourIndex_),
  79. _weight(font.weight_),
  80. _escapement_type(font.escapementType_),
  81. _underline_type(font.underlineType_),
  82. _font_family(font.family_),
  83. _character_set(font.characterSet_),
  84. _name(wstringFromSmallString(font.name_))
  85. {
  86. }
  87. wstring _name;
  88. short _height; // font height in twips (1/20 of a point)
  89. short _weight; // FW_NORMAL, FW_BOLD, ...
  90. short _options; // see EXCEL_FONT_OPTIONS
  91. short _color_index; // font colour index
  92. short _escapement_type; // see EXCEL_ESCAPEMENT
  93. char _underline_type; // see EXCEL_UNDERLINE_FLAGS
  94. char _font_family; // see EXCEL_FONT_FAMILY
  95. char _character_set; // ANSI_CHARSET, DEFAULT_CHARSET, SYMBOL_CHARSET, ...
  96. ExcelFont& set_height(int height)
  97. {
  98. _height = height;
  99. return *this;
  100. }
  101. ExcelFont& set_weight(int weight)
  102. {
  103. _weight = weight;
  104. return *this;
  105. }
  106. ExcelFont& set_italic(bool italic)
  107. {
  108. _options = (_options&~EXCEL_FONT_ITALIC) | (italic? EXCEL_FONT_ITALIC: 0);
  109. return *this;
  110. }
  111. ExcelFont& set_color_index(int color_idx)
  112. {
  113. _color_index = color_idx;
  114. return *this;
  115. }
  116. ExcelFont& set_underline_type(char underline_type)
  117. {
  118. _underline_type = underline_type;
  119. return *this;
  120. }
  121. ExcelFont& set_escapement(short escapement_type)
  122. {
  123. _escapement_type = escapement_type;
  124. return *this;
  125. }
  126. ExcelFont& set_font_name(const wchar_t* name)
  127. {
  128. _name = name;
  129. return *this;
  130. }
  131. bool matches(const Workbook::Font& font) const
  132. {
  133. if (wstringFromSmallString(font.name_) != _name)
  134. return false;
  135. if (font.height_ != _height)
  136. return false;
  137. if (font.weight_ != _weight)
  138. return false;
  139. if (font.options_ != _options)
  140. return false;
  141. if (font.colourIndex_ != _color_index)
  142. return false;
  143. if (font.escapementType_ != _escapement_type)
  144. return false;
  145. if (font.underlineType_ != _underline_type)
  146. return false;
  147. if (font.family_ != _font_family)
  148. return false;
  149. if (font.characterSet_ != _character_set)
  150. return false;
  151. return true;
  152. }
  153. };
  154. struct CellFormat;
  155. // Excel cell format manager class
  156. struct XLSFormatManager
  157. {
  158. XLSFormatManager(BasicExcel& xls);
  159. const Workbook::Font& get_font(const CellFormat& fmt) const;
  160. wstring get_format_string(const CellFormat& fmt) const;
  161. const Workbook::XF& get_XF(int xf_idx) const {return _xls.workbook_.XFs_[xf_idx];}
  162. int get_font_idx(const ExcelFont& font);
  163. int get_format_idx(const wstring& fmt_str);
  164. int get_xf_idx(const CellFormat& fmt);
  165. private:
  166. BasicExcel& _xls;
  167. int _next_fmt_idx;
  168. typedef map<int, wstring> FormatMap;
  169. typedef map<wstring, int> FormatRevMap;
  170. FormatMap _formats;
  171. FormatRevMap _formats_rev;
  172. };
  173. enum XF_USED_ATTRIB {
  174. XF_USED_ATTRIB_NUMBER_FORMAT = 0x01,
  175. XF_USED_ATTRIB_FONT = 0x02,
  176. XF_USED_ATTRIB_ALIGN = 0x04, // horizontal and vertical alignment, text wrap, indentation, orientation, rotation, and text direction
  177. XF_USED_ATTRIB_BORDER_LINES = 0x08,
  178. XF_USED_ATTRIB_BKGND_AREA_STYLE = 0x10,
  179. XF_USED_ATTRIB_CELL_PROTECTION = 0x20
  180. };
  181. /*
  182. Bit Mask Contents of alignment byte
  183. 2- 0 07H XF_HOR_ALIGN: Horizontal alignment
  184. 3 08H 1 = Text is wrapped at right border
  185. 6- 4 70H XF_VERT_ALIGN: Vertical alignment
  186. 7 80H 1 = Justify last line in justified or distibuted text
  187. */
  188. enum EXCEL_ALIGNMENT {
  189. // horizontal aligmment
  190. EXCEL_HALIGN_GENERAL = 0x00,
  191. EXCEL_HALIGN_LEFT = 0x01,
  192. EXCEL_HALIGN_CENTRED = 0x02,
  193. EXCEL_HALIGN_RIGHT = 0x03,
  194. EXCEL_HALIGN_FILLED = 0x04,
  195. EXCEL_HALIGN_JUSITFIED = 0x05,
  196. EXCEL_HALIGN_SEL_CENTRED = 0x06, // centred across selection
  197. EXCEL_HALIGN_DISTRIBUTED = 0x07, // available in Excel 10.0 (Excel XP) and later only
  198. // vertical alignment
  199. EXCEL_VALIGN_TOP = 0x00,
  200. EXCEL_VALIGN_CENTRED = 0x10,
  201. EXCEL_VALIGN_BOTTOM = 0x20,
  202. EXCEL_VALIGN_JUSTIFIED = 0x30,
  203. EXCEL_VALIGN_DISTRIBUTED = 0x40, // available in Excel 10.0 (Excel XP) and later only
  204. EXCEL_JUSTIFY_LAST_LINE = 0x80 // justify last line in justified or distibuted text
  205. };
  206. /*
  207. Indentation, shrink to cell size, and text direction:
  208. Bit Mask Contents
  209. 3- 0 0FH Indent level
  210. 4 10H 1 = Shrink content to fit into cell
  211. 7- 6 C0H Text direction: 0 = According to context; 1 = Left-to-right; 2 = Right-to-left
  212. */
  213. #define MAKE_TEXT_PROPS(indent, flags) ((indent) | (flags))
  214. enum EXCEL_TEXT_PROP_FLAGS {
  215. // shrink flag
  216. EXCEL_TEXT_PROP_SHRINK = 0x10,
  217. // text direction
  218. EXCEL_TEXT_PROP_DEFAULT = 0x00,
  219. EXCEL_TEXT_PROP_LEFT_TO_RIGHT = 0x40,
  220. EXCEL_TEXT_PROP_RIGHT_TO_LEFT = 0x80
  221. };
  222. /*
  223. Bit Mask Contents of cell border lines and background area:
  224. 3- 0 0000000FH Left line style
  225. 7- 4 000000F0H Right line style
  226. 11- 8 00000F00H Top line style
  227. 15-12 0000F000H Bottom line style
  228. 22-16 007F0000H Color index for left line colour
  229. 29-23 3F800000H Color index for right line colour
  230. 30 40000000H 1 = Diagonal line from top left to right bottom
  231. 31 80000000H 1 = Diagonal line from bottom left to right top
  232. */
  233. #define MAKE_BORDERSTYLE(left, right, top, bottom, lcol, rcol) \
  234. ((left) | ((right)<<4) | ((top)<<8) | ((bottom)<<12) | ((lcol)<<16) | ((rcol)<<23))
  235. // line style constants
  236. enum EXCEL_LS {
  237. EXCEL_LS_NO_LINE = 0x00,
  238. EXCEL_LS_THIN = 0x01,
  239. EXCEL_LS_MEDIUM = 0x02,
  240. EXCEL_LS_DASHED = 0x03,
  241. EXCEL_LS_DOTTED = 0x04,
  242. EXCEL_LS_THICK = 0x05,
  243. EXCEL_LS_DOUBLE = 0x06,
  244. EXCEL_LS_HAIR = 0x07,
  245. EXCEL_LS_MEDIUM_DASHED = 0x08,
  246. EXCEL_LS_THIN_DASH_DOTTED = 0x09,
  247. EXCEL_LS_MEDIUM_DASH_DOTTED = 0x0A,
  248. EXCEL_LS_THIN_DASH_DOT_DOTTED = 0x0B,
  249. EXCEL_LS_MEDIUM_DASH_DOT_DOTTED = 0x0C,
  250. EXCEL_LS_SLANTED_MEDIUM_DASH_DOTTED = 0x0D
  251. };
  252. // borderline flags for diagonal lines
  253. enum BORDERLINE_FLAGS {
  254. BORDERLINE_DIAG1 = 0x40000000,
  255. BORDERLINE_DIAG2 = 0x80000000
  256. };
  257. /*
  258. Bit Mask Contents of COLOR1
  259. 06- 0 0000007FH Color index for top line colour
  260. 13- 7 00003F80H Color index for bottom line colour
  261. 20-14 001FC000H Color index for diagonal line colour
  262. 24-21 01E00000H Diagonal line style
  263. 31-26 FC000000H Fill pattern
  264. */
  265. #define MAKE_COLOR1(top, bottom, diag, pat) ((top) | ((bottom)<<7) | ((diag)<<14) | pat)
  266. // line style constants for COLOR1
  267. enum COLOR1_LS { // EXCEL_LS << 21
  268. COLOR1_LS_NO_LINE = 0x0000000,
  269. COLOR1_LS_THIN = 0x0200000,
  270. COLOR1_LS_MEDIUM = 0x0400000,
  271. COLOR1_LS_DASHED = 0x0600000,
  272. COLOR1_LS_DOTTED = 0x0800000,
  273. COLOR1_LS_THICK = 0x0A00000,
  274. COLOR1_LS_DOUBLE = 0x0C00000,
  275. COLOR1_LS_HAIR = 0x0E00000,
  276. COLOR1_LS_MEDIUM_DASHED = 0x1000000,
  277. COLOR1_LS_THIN_DASH_DOTTED = 0x1200000,
  278. COLOR1_LS_MEDIUM_DASH_DOTTED = 0x1400000,
  279. COLOR1_LS_THIN_DASH_DOT_DOTTED = 0x1600000,
  280. COLOR1_LS_MEDIUM_DASH_DOT_DOTTED = 0x1800000,
  281. COLOR1_LS_SLANTED_MEDIUM_DASH_DOTTED = 0x1A00000
  282. };
  283. // pattern constants
  284. enum COLOR1_PAT {
  285. COLOR1_PAT_EMPTY = 0x00000000,
  286. COLOR1_PAT_SOLID = 0x04000000,
  287. COLOR1_PAT_2 = 0x08000000,
  288. COLOR1_PAT_3 = 0x0C000000,
  289. COLOR1_PAT_4 = 0x10000000,
  290. COLOR1_PAT_5 = 0x14000000,
  291. COLOR1_PAT_6 = 0x18000000,
  292. COLOR1_PAT_7 = 0x1C000000,
  293. COLOR1_PAT_8 = 0x20000000,
  294. COLOR1_PAT_9 = 0x24000000,
  295. COLOR1_PAT_10 = 0x28000000,
  296. COLOR1_PAT_11 = 0x2C000000,
  297. COLOR1_PAT_12 = 0x30000000,
  298. COLOR1_PAT_13 = 0x34000000,
  299. COLOR1_PAT_14 = 0x38000000,
  300. COLOR1_PAT_15 = 0x3C000000,
  301. COLOR1_PAT_16 = 0x40000000,
  302. COLOR1_PAT_17 = 0x44000000,
  303. COLOR1_PAT_18 = 0x48000000
  304. };
  305. /*
  306. Bit Mask Contents of COLOR2
  307. 6- 0 007FH Color index for pattern colour
  308. 13- 7 3F80H Color index for pattern background
  309. */
  310. #define MAKE_COLOR2(pc, pbc) ((pc) | ((pbc)<<7))
  311. // predefined Excel color definitions
  312. enum EXCEL_COLORS {
  313. EGA_BLACK = 0, // 000000H
  314. EGA_WHITE = 1, // FFFFFFH
  315. EGA_RED = 2, // FF0000H
  316. EGA_GREEN = 3, // 00FF00H
  317. EGA_BLUE = 4, // 0000FFH
  318. EGA_YELLOW = 5, // FFFF00H
  319. EGA_MAGENTA = 6, // FF00FFH
  320. EGA_CYAN = 7 // 00FFFFH
  321. };
  322. // Excel cell format
  323. struct CellFormat
  324. {
  325. CellFormat(XLSFormatManager& mgr)
  326. : _mgr(mgr)
  327. {
  328. init();
  329. }
  330. CellFormat(XLSFormatManager& mgr, const ExcelFont& font)
  331. : _mgr(mgr)
  332. {
  333. init();
  334. set_font(font);
  335. }
  336. CellFormat(XLSFormatManager& mgr, const Workbook::XF& xf, int xf_idx)
  337. : _mgr(mgr)
  338. {
  339. init(xf, xf_idx);
  340. }
  341. CellFormat(XLSFormatManager& mgr, const BasicExcelCell* cell)
  342. : _mgr(mgr)
  343. {
  344. int xf_idx = cell->GetXFormatIdx();
  345. init(mgr.get_XF(xf_idx), xf_idx);
  346. }
  347. XLSFormatManager& get_format_manager() const
  348. {
  349. return _mgr;
  350. }
  351. // return XF index for all current attributes
  352. int get_xf_idx() const
  353. {
  354. if (_xf_idx == -1)
  355. _xf_idx = _mgr.get_xf_idx(*this);
  356. return _xf_idx;
  357. }
  358. void flush()
  359. {
  360. _xf_idx = -1; // invalidate XF index
  361. }
  362. int get_font_idx() const
  363. {
  364. return _font_idx;
  365. }
  366. int get_fmt_idx() const
  367. {
  368. return _fmt_idx;
  369. }
  370. ExcelFont get_font()
  371. {
  372. return ExcelFont(_mgr.get_font(*this));
  373. }
  374. CellFormat& set_font(const ExcelFont& font)
  375. {
  376. _font_idx = _mgr.get_font_idx(font);
  377. flush();
  378. return *this;
  379. }
  380. wstring get_format_string() const
  381. {
  382. return _mgr.get_format_string(*this);
  383. }
  384. CellFormat& set_format_string(const char* fmt_str)
  385. {
  386. return set_format_string(widen_string(fmt_str));
  387. }
  388. CellFormat& set_format_string(const wstring& fmt_str)
  389. {
  390. _fmt_idx = _mgr.get_format_idx(fmt_str);
  391. flush();
  392. return *this;
  393. }
  394. int get_color1() const
  395. {
  396. return _color1;
  397. }
  398. CellFormat& set_color1(unsigned color)
  399. {
  400. _color1 = color;
  401. flush();
  402. return *this;
  403. }
  404. unsigned short get_color2() const
  405. {
  406. return _color2;
  407. }
  408. CellFormat& set_color2(unsigned short color)
  409. {
  410. _color2 = color;
  411. flush();
  412. return *this;
  413. }
  414. // convenience function to set color1 and color2 at the same time
  415. CellFormat& set_background(unsigned short color2, unsigned color1=COLOR1_PAT_SOLID)
  416. {
  417. return set_color1(color1).set_color2(color2);
  418. }
  419. char get_alignment() const
  420. {
  421. return _alignment;
  422. }
  423. CellFormat& set_alignment(char alignment)
  424. {
  425. _alignment = alignment;
  426. flush();
  427. return *this;
  428. }
  429. bool is_wrapping()
  430. {
  431. return (_alignment & 0x08)? true: false;
  432. }
  433. CellFormat& set_wrapping(bool wrap)
  434. {
  435. return set_alignment((_alignment&~0x08) | (wrap? 0x08: 0x00));
  436. }
  437. char get_rotation() const
  438. {
  439. return _rotation;
  440. }
  441. CellFormat& set_rotation(char rotation)
  442. {
  443. _rotation = rotation;
  444. flush();
  445. return *this;
  446. }
  447. char get_text_props() const
  448. {
  449. return _text_props;
  450. }
  451. CellFormat& set_text_props(char text_props)
  452. {
  453. _text_props = text_props;
  454. flush();
  455. return *this;
  456. }
  457. int get_borderlines() const
  458. {
  459. return _borderlines;
  460. }
  461. CellFormat& set_borderlines(int borderlines)
  462. {
  463. _borderlines = borderlines;
  464. flush();
  465. return *this;
  466. }
  467. // set borderlines using EXCEL_LS enumeration constants and colour indices
  468. CellFormat& set_borderlines(
  469. EXCEL_LS left, EXCEL_LS right, EXCEL_LS top, EXCEL_LS bottom,
  470. unsigned idxLclr, unsigned idxRclr
  471. )
  472. {
  473. _borderlines = MAKE_BORDERSTYLE(left, right, top, bottom, idxLclr, idxRclr);
  474. flush();
  475. return *this;
  476. }
  477. // set borderlines including the top and bottom colour
  478. CellFormat& set_borderlines(
  479. EXCEL_LS left, EXCEL_LS right, EXCEL_LS top, EXCEL_LS bottom,
  480. unsigned idxLclr, unsigned idxRclr, unsigned idxTclr, unsigned idxBclr,
  481. EXCEL_LS diag, // diagonal line style
  482. COLOR1_PAT pattern // fill pattern
  483. )
  484. {
  485. _borderlines = MAKE_BORDERSTYLE(left, right, top, bottom, idxLclr, idxRclr);
  486. _color1 = MAKE_COLOR1(idxTclr, idxBclr, diag, pattern);
  487. flush();
  488. return *this;
  489. }
  490. bool matches(const Workbook::XF& xf) const
  491. {
  492. if (xf.fontRecordIndex_ != _font_idx)
  493. return false;
  494. if (xf.formatRecordIndex_ != _fmt_idx)
  495. return false;
  496. if (xf.alignment_ != _alignment)
  497. return false;
  498. if (xf.rotation_ != _rotation)
  499. return false;
  500. if (xf.textProperties_ != _text_props)
  501. return false;
  502. if (xf.borderLines_ != _borderlines)
  503. return false;
  504. if (xf.colour1_ != _color1)
  505. return false;
  506. if (xf.colour2_ != _color2)
  507. return false;
  508. return true;
  509. }
  510. void get_xf(Workbook::XF& xf) const
  511. {
  512. xf.fontRecordIndex_ = _font_idx;
  513. xf.formatRecordIndex_ = _fmt_idx;
  514. xf.alignment_ = _alignment;
  515. xf.rotation_= _rotation;
  516. xf.textProperties_= _text_props;
  517. xf.borderLines_= _borderlines;
  518. xf.colour1_ = _color1;
  519. xf.colour2_ = _color2;
  520. }
  521. private:
  522. XLSFormatManager& _mgr;
  523. mutable int _xf_idx; // cached XF index
  524. int _font_idx;
  525. int _fmt_idx;
  526. // char _protectionType;
  527. char _alignment; // alignment and text break, see EXCEL_ALIGNMENT
  528. char _rotation; // text rotation angle in degrees
  529. char _text_props; // see MAKE_TEXT_PROPS() and EXCEL_TEXT_PROP_FLAGS
  530. // char _usedAttributes;
  531. int _borderlines; // see MAKE_BORDERSTYLE(), EXCEL_LS and BORDERLINE_FLAGS
  532. unsigned _color1; // see MAKE_COLOR1(), COLOR1_LS and COLOR1_PAT
  533. unsigned short _color2; // see MAKE_COLOR2()
  534. void init()
  535. {
  536. _font_idx = 0;
  537. _fmt_idx = 0;
  538. _alignment = EXCEL_VALIGN_BOTTOM;
  539. _rotation = 0;
  540. _text_props = MAKE_TEXT_PROPS(0, EXCEL_TEXT_PROP_DEFAULT);
  541. _borderlines = 0;
  542. _color1 = 0;
  543. _color2 = MAKE_COLOR2(64, 65); // 0x20C0
  544. _xf_idx = 0;
  545. }
  546. void init(const Workbook::XF& xf, int xf_idx)
  547. {
  548. _font_idx = xf.fontRecordIndex_;
  549. _fmt_idx = xf.formatRecordIndex_;
  550. _alignment = xf.alignment_;
  551. _rotation = xf.rotation_;
  552. _text_props = xf.textProperties_;
  553. _borderlines = xf.borderLines_;
  554. _color1 = xf.colour1_;
  555. _color2 = xf.colour2_;
  556. _xf_idx = xf_idx;
  557. }
  558. };
  559. } // namespace ExcelFormat
  560. namespace YExcel {
  561. inline void BasicExcelCell::SetFormat(const ExcelFormat::CellFormat& fmt)
  562. {
  563. _xf_idx = fmt.get_xf_idx();
  564. }
  565. }
  566. #endif // EXCELFORMAT_H