format.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. /*
  2. * libxlsxwriter
  3. *
  4. * Copyright 2014-2018, John McNamara, [email protected]. See LICENSE.txt.
  5. */
  6. /**
  7. * @page format_page The Format object
  8. *
  9. * The Format object represents an the formatting properties that can be
  10. * applied to a cell including: fonts, colors, patterns,
  11. * borders, alignment and number formatting.
  12. *
  13. * See @ref format.h for full details of the functionality.
  14. *
  15. * @file format.h
  16. *
  17. * @brief Functions and properties for adding formatting to cells in Excel.
  18. *
  19. * This section describes the functions and properties that are available for
  20. * formatting cells in Excel.
  21. *
  22. * The properties of a cell that can be formatted include: fonts, colors,
  23. * patterns, borders, alignment and number formatting.
  24. *
  25. * @image html formats_intro.png
  26. *
  27. * Formats in `libxlsxwriter` are accessed via the lxw_format
  28. * struct. Throughout this document these will be referred to simply as
  29. * *Formats*.
  30. *
  31. * Formats are created by calling the workbook_add_format() method as
  32. * follows:
  33. *
  34. * @code
  35. * lxw_format *format = workbook_add_format(workbook);
  36. * @endcode
  37. *
  38. * The members of the lxw_format struct aren't modified directly. Instead the
  39. * format properties are set by calling the functions shown in this section.
  40. * For example:
  41. *
  42. * @code
  43. * // Create the Format.
  44. * lxw_format *format = workbook_add_format(workbook);
  45. *
  46. * // Set some of the format properties.
  47. * format_set_bold(format);
  48. * format_set_font_color(format, LXW_COLOR_RED);
  49. *
  50. * // Use the format to change the text format in a cell.
  51. * worksheet_write_string(worksheet, 0, 0, "Hello", format);
  52. *
  53. * @endcode
  54. *
  55. * The full range of formatting options that can be applied using
  56. * `libxlsxwriter` are shown below.
  57. *
  58. */
  59. #ifndef __LXW_FORMAT_H__
  60. #define __LXW_FORMAT_H__
  61. #include <stdint.h>
  62. #include <string.h>
  63. #include "hash_table.h"
  64. #include "common.h"
  65. /**
  66. * @brief The type for RGB colors in libxlsxwriter.
  67. *
  68. * The type for RGB colors in libxlsxwriter. The valid range is `0x000000`
  69. * (black) to `0xFFFFFF` (white). See @ref working_with_colors.
  70. */
  71. typedef int32_t lxw_color_t;
  72. #define LXW_FORMAT_FIELD_LEN 128
  73. #define LXW_DEFAULT_FONT_NAME "Calibri"
  74. #define LXW_DEFAULT_FONT_FAMILY 2
  75. #define LXW_DEFAULT_FONT_THEME 1
  76. #define LXW_PROPERTY_UNSET -1
  77. #define LXW_COLOR_UNSET -1
  78. #define LXW_COLOR_MASK 0xFFFFFF
  79. #define LXW_MIN_FONT_SIZE 1.0
  80. #define LXW_MAX_FONT_SIZE 409.0
  81. #define LXW_FORMAT_FIELD_COPY(dst, src) \
  82. do{ \
  83. strncpy(dst, src, LXW_FORMAT_FIELD_LEN -1); \
  84. dst[LXW_FORMAT_FIELD_LEN - 1] = '\0'; \
  85. } while (0)
  86. /** Format underline values for format_set_underline(). */
  87. enum lxw_format_underlines {
  88. /** Single underline */
  89. LXW_UNDERLINE_SINGLE = 1,
  90. /** Double underline */
  91. LXW_UNDERLINE_DOUBLE,
  92. /** Single accounting underline */
  93. LXW_UNDERLINE_SINGLE_ACCOUNTING,
  94. /** Double accounting underline */
  95. LXW_UNDERLINE_DOUBLE_ACCOUNTING
  96. };
  97. /** Superscript and subscript values for format_set_font_script(). */
  98. enum lxw_format_scripts {
  99. /** Superscript font */
  100. LXW_FONT_SUPERSCRIPT = 1,
  101. /** Subscript font */
  102. LXW_FONT_SUBSCRIPT
  103. };
  104. /** Alignment values for format_set_align(). */
  105. enum lxw_format_alignments {
  106. /** No alignment. Cell will use Excel's default for the data type */
  107. LXW_ALIGN_NONE = 0,
  108. /** Left horizontal alignment */
  109. LXW_ALIGN_LEFT,
  110. /** Center horizontal alignment */
  111. LXW_ALIGN_CENTER,
  112. /** Right horizontal alignment */
  113. LXW_ALIGN_RIGHT,
  114. /** Cell fill horizontal alignment */
  115. LXW_ALIGN_FILL,
  116. /** Justify horizontal alignment */
  117. LXW_ALIGN_JUSTIFY,
  118. /** Center Across horizontal alignment */
  119. LXW_ALIGN_CENTER_ACROSS,
  120. /** Left horizontal alignment */
  121. LXW_ALIGN_DISTRIBUTED,
  122. /** Top vertical alignment */
  123. LXW_ALIGN_VERTICAL_TOP,
  124. /** Bottom vertical alignment */
  125. LXW_ALIGN_VERTICAL_BOTTOM,
  126. /** Center vertical alignment */
  127. LXW_ALIGN_VERTICAL_CENTER,
  128. /** Justify vertical alignment */
  129. LXW_ALIGN_VERTICAL_JUSTIFY,
  130. /** Distributed vertical alignment */
  131. LXW_ALIGN_VERTICAL_DISTRIBUTED
  132. };
  133. enum lxw_format_diagonal_types {
  134. LXW_DIAGONAL_BORDER_UP = 1,
  135. LXW_DIAGONAL_BORDER_DOWN,
  136. LXW_DIAGONAL_BORDER_UP_DOWN
  137. };
  138. /** Predefined values for common colors. */
  139. enum lxw_defined_colors {
  140. /** Black */
  141. LXW_COLOR_BLACK = 0x1000000,
  142. /** Blue */
  143. LXW_COLOR_BLUE = 0x0000FF,
  144. /** Brown */
  145. LXW_COLOR_BROWN = 0x800000,
  146. /** Cyan */
  147. LXW_COLOR_CYAN = 0x00FFFF,
  148. /** Gray */
  149. LXW_COLOR_GRAY = 0x808080,
  150. /** Green */
  151. LXW_COLOR_GREEN = 0x008000,
  152. /** Lime */
  153. LXW_COLOR_LIME = 0x00FF00,
  154. /** Magenta */
  155. LXW_COLOR_MAGENTA = 0xFF00FF,
  156. /** Navy */
  157. LXW_COLOR_NAVY = 0x000080,
  158. /** Orange */
  159. LXW_COLOR_ORANGE = 0xFF6600,
  160. /** Pink */
  161. LXW_COLOR_PINK = 0xFF00FF,
  162. /** Purple */
  163. LXW_COLOR_PURPLE = 0x800080,
  164. /** Red */
  165. LXW_COLOR_RED = 0xFF0000,
  166. /** Silver */
  167. LXW_COLOR_SILVER = 0xC0C0C0,
  168. /** White */
  169. LXW_COLOR_WHITE = 0xFFFFFF,
  170. /** Yellow */
  171. LXW_COLOR_YELLOW = 0xFFFF00
  172. };
  173. /** Pattern value for use with format_set_pattern(). */
  174. enum lxw_format_patterns {
  175. /** Empty pattern */
  176. LXW_PATTERN_NONE = 0,
  177. /** Solid pattern */
  178. LXW_PATTERN_SOLID,
  179. /** Medium gray pattern */
  180. LXW_PATTERN_MEDIUM_GRAY,
  181. /** Dark gray pattern */
  182. LXW_PATTERN_DARK_GRAY,
  183. /** Light gray pattern */
  184. LXW_PATTERN_LIGHT_GRAY,
  185. /** Dark horizontal line pattern */
  186. LXW_PATTERN_DARK_HORIZONTAL,
  187. /** Dark vertical line pattern */
  188. LXW_PATTERN_DARK_VERTICAL,
  189. /** Dark diagonal stripe pattern */
  190. LXW_PATTERN_DARK_DOWN,
  191. /** Reverse dark diagonal stripe pattern */
  192. LXW_PATTERN_DARK_UP,
  193. /** Dark grid pattern */
  194. LXW_PATTERN_DARK_GRID,
  195. /** Dark trellis pattern */
  196. LXW_PATTERN_DARK_TRELLIS,
  197. /** Light horizontal Line pattern */
  198. LXW_PATTERN_LIGHT_HORIZONTAL,
  199. /** Light vertical line pattern */
  200. LXW_PATTERN_LIGHT_VERTICAL,
  201. /** Light diagonal stripe pattern */
  202. LXW_PATTERN_LIGHT_DOWN,
  203. /** Reverse light diagonal stripe pattern */
  204. LXW_PATTERN_LIGHT_UP,
  205. /** Light grid pattern */
  206. LXW_PATTERN_LIGHT_GRID,
  207. /** Light trellis pattern */
  208. LXW_PATTERN_LIGHT_TRELLIS,
  209. /** 12.5% gray pattern */
  210. LXW_PATTERN_GRAY_125,
  211. /** 6.25% gray pattern */
  212. LXW_PATTERN_GRAY_0625
  213. };
  214. /** Cell border styles for use with format_set_border(). */
  215. enum lxw_format_borders {
  216. /** No border */
  217. LXW_BORDER_NONE,
  218. /** Thin border style */
  219. LXW_BORDER_THIN,
  220. /** Medium border style */
  221. LXW_BORDER_MEDIUM,
  222. /** Dashed border style */
  223. LXW_BORDER_DASHED,
  224. /** Dotted border style */
  225. LXW_BORDER_DOTTED,
  226. /** Thick border style */
  227. LXW_BORDER_THICK,
  228. /** Double border style */
  229. LXW_BORDER_DOUBLE,
  230. /** Hair border style */
  231. LXW_BORDER_HAIR,
  232. /** Medium dashed border style */
  233. LXW_BORDER_MEDIUM_DASHED,
  234. /** Dash-dot border style */
  235. LXW_BORDER_DASH_DOT,
  236. /** Medium dash-dot border style */
  237. LXW_BORDER_MEDIUM_DASH_DOT,
  238. /** Dash-dot-dot border style */
  239. LXW_BORDER_DASH_DOT_DOT,
  240. /** Medium dash-dot-dot border style */
  241. LXW_BORDER_MEDIUM_DASH_DOT_DOT,
  242. /** Slant dash-dot border style */
  243. LXW_BORDER_SLANT_DASH_DOT
  244. };
  245. /**
  246. * @brief Struct to represent the formatting properties of an Excel format.
  247. *
  248. * Formats in `libxlsxwriter` are accessed via this struct.
  249. *
  250. * The members of the lxw_format struct aren't modified directly. Instead the
  251. * format properties are set by calling the functions shown in format.h.
  252. *
  253. * For example:
  254. *
  255. * @code
  256. * // Create the Format.
  257. * lxw_format *format = workbook_add_format(workbook);
  258. *
  259. * // Set some of the format properties.
  260. * format_set_bold(format);
  261. * format_set_font_color(format, LXW_COLOR_RED);
  262. *
  263. * // Use the format to change the text format in a cell.
  264. * worksheet_write_string(worksheet, 0, 0, "Hello", format);
  265. *
  266. * @endcode
  267. *
  268. */
  269. typedef struct lxw_format {
  270. FILE *file;
  271. lxw_hash_table *xf_format_indices;
  272. uint16_t *num_xf_formats;
  273. int32_t xf_index;
  274. int32_t dxf_index;
  275. char num_format[LXW_FORMAT_FIELD_LEN];
  276. char font_name[LXW_FORMAT_FIELD_LEN];
  277. char font_scheme[LXW_FORMAT_FIELD_LEN];
  278. uint16_t num_format_index;
  279. uint16_t font_index;
  280. uint8_t has_font;
  281. uint8_t has_dxf_font;
  282. double font_size;
  283. uint8_t bold;
  284. uint8_t italic;
  285. lxw_color_t font_color;
  286. uint8_t underline;
  287. uint8_t font_strikeout;
  288. uint8_t font_outline;
  289. uint8_t font_shadow;
  290. uint8_t font_script;
  291. uint8_t font_family;
  292. uint8_t font_charset;
  293. uint8_t font_condense;
  294. uint8_t font_extend;
  295. uint8_t theme;
  296. uint8_t hyperlink;
  297. uint8_t hidden;
  298. uint8_t locked;
  299. uint8_t text_h_align;
  300. uint8_t text_wrap;
  301. uint8_t text_v_align;
  302. uint8_t text_justlast;
  303. int16_t rotation;
  304. lxw_color_t fg_color;
  305. lxw_color_t bg_color;
  306. uint8_t pattern;
  307. uint8_t has_fill;
  308. uint8_t has_dxf_fill;
  309. int32_t fill_index;
  310. int32_t fill_count;
  311. int32_t border_index;
  312. uint8_t has_border;
  313. uint8_t has_dxf_border;
  314. int32_t border_count;
  315. uint8_t bottom;
  316. uint8_t diag_border;
  317. uint8_t diag_type;
  318. uint8_t left;
  319. uint8_t right;
  320. uint8_t top;
  321. lxw_color_t bottom_color;
  322. lxw_color_t diag_color;
  323. lxw_color_t left_color;
  324. lxw_color_t right_color;
  325. lxw_color_t top_color;
  326. uint8_t indent;
  327. uint8_t shrink;
  328. uint8_t merge_range;
  329. uint8_t reading_order;
  330. uint8_t just_distrib;
  331. uint8_t color_indexed;
  332. uint8_t font_only;
  333. STAILQ_ENTRY (lxw_format) list_pointers;
  334. } lxw_format;
  335. /*
  336. * Struct to represent the font component of a format.
  337. */
  338. typedef struct lxw_font {
  339. char font_name[LXW_FORMAT_FIELD_LEN];
  340. double font_size;
  341. uint8_t bold;
  342. uint8_t italic;
  343. uint8_t underline;
  344. uint8_t font_strikeout;
  345. uint8_t font_outline;
  346. uint8_t font_shadow;
  347. uint8_t font_script;
  348. uint8_t font_family;
  349. uint8_t font_charset;
  350. uint8_t font_condense;
  351. uint8_t font_extend;
  352. lxw_color_t font_color;
  353. } lxw_font;
  354. /*
  355. * Struct to represent the border component of a format.
  356. */
  357. typedef struct lxw_border {
  358. uint8_t bottom;
  359. uint8_t diag_border;
  360. uint8_t diag_type;
  361. uint8_t left;
  362. uint8_t right;
  363. uint8_t top;
  364. lxw_color_t bottom_color;
  365. lxw_color_t diag_color;
  366. lxw_color_t left_color;
  367. lxw_color_t right_color;
  368. lxw_color_t top_color;
  369. } lxw_border;
  370. /*
  371. * Struct to represent the fill component of a format.
  372. */
  373. typedef struct lxw_fill {
  374. lxw_color_t fg_color;
  375. lxw_color_t bg_color;
  376. uint8_t pattern;
  377. } lxw_fill;
  378. /* *INDENT-OFF* */
  379. #ifdef __cplusplus
  380. extern "C" {
  381. #endif
  382. /* *INDENT-ON* */
  383. lxw_format *lxw_format_new();
  384. void lxw_format_free(lxw_format *format);
  385. int32_t lxw_format_get_xf_index(lxw_format *format);
  386. lxw_font *lxw_format_get_font_key(lxw_format *format);
  387. lxw_border *lxw_format_get_border_key(lxw_format *format);
  388. lxw_fill *lxw_format_get_fill_key(lxw_format *format);
  389. lxw_color_t lxw_format_check_color(lxw_color_t color);
  390. /**
  391. * @brief Set the font used in the cell.
  392. *
  393. * @param format Pointer to a Format instance.
  394. * @param font_name Cell font name.
  395. *
  396. * Specify the font used used in the cell format:
  397. *
  398. * @code
  399. * format_set_font_name(format, "Avenir Black Oblique");
  400. * @endcode
  401. *
  402. * @image html format_set_font_name.png
  403. *
  404. * Excel can only display fonts that are installed on the system that it is
  405. * running on. Therefore it is generally best to use the fonts that come as
  406. * standard with Excel such as Calibri, Times New Roman and Courier New.
  407. *
  408. * The default font in Excel 2007, and later, is Calibri.
  409. */
  410. void format_set_font_name(lxw_format *format, const char *font_name);
  411. /**
  412. * @brief Set the size of the font used in the cell.
  413. *
  414. * @param format Pointer to a Format instance.
  415. * @param size The cell font size.
  416. *
  417. * Set the font size of the cell format:
  418. *
  419. * @code
  420. * format_set_font_size(format, 30);
  421. * @endcode
  422. *
  423. * @image html format_font_size.png
  424. *
  425. * Excel adjusts the height of a row to accommodate the largest font
  426. * size in the row. You can also explicitly specify the height of a
  427. * row using the worksheet_set_row() function.
  428. */
  429. void format_set_font_size(lxw_format *format, double size);
  430. /**
  431. * @brief Set the color of the font used in the cell.
  432. *
  433. * @param format Pointer to a Format instance.
  434. * @param color The cell font color.
  435. *
  436. *
  437. * Set the font color:
  438. *
  439. * @code
  440. * format = workbook_add_format(workbook);
  441. * format_set_font_color(format, LXW_COLOR_RED);
  442. *
  443. * worksheet_write_string(worksheet, 0, 0, "Wheelbarrow", format);
  444. * @endcode
  445. *
  446. * @image html format_font_color.png
  447. *
  448. * The color should be an RGB integer value, see @ref working_with_colors.
  449. *
  450. * @note
  451. * The format_set_font_color() method is used to set the font color in a
  452. * cell. To set the color of a cell background use the format_set_bg_color()
  453. * and format_set_pattern() methods.
  454. */
  455. void format_set_font_color(lxw_format *format, lxw_color_t color);
  456. /**
  457. * @brief Turn on bold for the format font.
  458. *
  459. * @param format Pointer to a Format instance.
  460. *
  461. * Set the bold property of the font:
  462. *
  463. * @code
  464. * format = workbook_add_format(workbook);
  465. * format_set_bold(format);
  466. *
  467. * worksheet_write_string(worksheet, 0, 0, "Bold Text", format);
  468. * @endcode
  469. *
  470. * @image html format_font_bold.png
  471. */
  472. void format_set_bold(lxw_format *format);
  473. /**
  474. * @brief Turn on italic for the format font.
  475. *
  476. * @param format Pointer to a Format instance.
  477. *
  478. * Set the italic property of the font:
  479. *
  480. * @code
  481. * format = workbook_add_format(workbook);
  482. * format_set_italic(format);
  483. *
  484. * worksheet_write_string(worksheet, 0, 0, "Italic Text", format);
  485. * @endcode
  486. *
  487. * @image html format_font_italic.png
  488. */
  489. void format_set_italic(lxw_format *format);
  490. /**
  491. * @brief Turn on underline for the format:
  492. *
  493. * @param format Pointer to a Format instance.
  494. * @param style Underline style.
  495. *
  496. * Set the underline property of the format:
  497. *
  498. * @code
  499. * format_set_underline(format, LXW_UNDERLINE_SINGLE);
  500. * @endcode
  501. *
  502. * @image html format_font_underlined.png
  503. *
  504. * The available underline styles are:
  505. *
  506. * - #LXW_UNDERLINE_SINGLE
  507. * - #LXW_UNDERLINE_DOUBLE
  508. * - #LXW_UNDERLINE_SINGLE_ACCOUNTING
  509. * - #LXW_UNDERLINE_DOUBLE_ACCOUNTING
  510. *
  511. */
  512. void format_set_underline(lxw_format *format, uint8_t style);
  513. /**
  514. * @brief Set the strikeout property of the font.
  515. *
  516. * @param format Pointer to a Format instance.
  517. *
  518. * @image html format_font_strikeout.png
  519. *
  520. */
  521. void format_set_font_strikeout(lxw_format *format);
  522. /**
  523. * @brief Set the superscript/subscript property of the font.
  524. *
  525. * @param format Pointer to a Format instance.
  526. * @param style Superscript or subscript style.
  527. *
  528. * Set the superscript o subscript property of the font.
  529. *
  530. * @image html format_font_script.png
  531. *
  532. * The available script styles are:
  533. *
  534. * - #LXW_FONT_SUPERSCRIPT
  535. * - #LXW_FONT_SUBSCRIPT
  536. */
  537. void format_set_font_script(lxw_format *format, uint8_t style);
  538. /**
  539. * @brief Set the number format for a cell.
  540. *
  541. * @param format Pointer to a Format instance.
  542. * @param num_format The cell number format string.
  543. *
  544. * This method is used to define the numerical format of a number in
  545. * Excel. It controls whether a number is displayed as an integer, a
  546. * floating point number, a date, a currency value or some other user
  547. * defined format.
  548. *
  549. * The numerical format of a cell can be specified by using a format
  550. * string:
  551. *
  552. * @code
  553. * format = workbook_add_format(workbook);
  554. * format_set_num_format(format, "d mmm yyyy");
  555. * @endcode
  556. *
  557. * Format strings can control any aspect of number formatting allowed by Excel:
  558. *
  559. * @dontinclude format_num_format.c
  560. * @skipline set_num_format
  561. * @until 1209
  562. *
  563. * @image html format_set_num_format.png
  564. *
  565. * The number system used for dates is described in @ref working_with_dates.
  566. *
  567. * For more information on number formats in Excel refer to the
  568. * [Microsoft documentation on cell formats](http://office.microsoft.com/en-gb/assistance/HP051995001033.aspx).
  569. */
  570. void format_set_num_format(lxw_format *format, const char *num_format);
  571. /**
  572. * @brief Set the Excel built-in number format for a cell.
  573. *
  574. * @param format Pointer to a Format instance.
  575. * @param index The built-in number format index for the cell.
  576. *
  577. * This function is similar to format_set_num_format() except that it takes an
  578. * index to a limited number of Excel's built-in number formats instead of a
  579. * user defined format string:
  580. *
  581. * @code
  582. * format = workbook_add_format(workbook);
  583. * format_set_num_format(format, 0x0F); // d-mmm-yy
  584. * @endcode
  585. *
  586. * @note
  587. * Unless you need to specifically access one of Excel's built-in number
  588. * formats the format_set_num_format() function above is a better
  589. * solution. The format_set_num_format_index() function is mainly included for
  590. * backward compatibility and completeness.
  591. *
  592. * The Excel built-in number formats as shown in the table below:
  593. *
  594. * | Index | Index | Format String |
  595. * | ----- | ----- | ---------------------------------------------------- |
  596. * | 0 | 0x00 | `General` |
  597. * | 1 | 0x01 | `0` |
  598. * | 2 | 0x02 | `0.00` |
  599. * | 3 | 0x03 | `#,##0` |
  600. * | 4 | 0x04 | `#,##0.00` |
  601. * | 5 | 0x05 | `($#,##0_);($#,##0)` |
  602. * | 6 | 0x06 | `($#,##0_);[Red]($#,##0)` |
  603. * | 7 | 0x07 | `($#,##0.00_);($#,##0.00)` |
  604. * | 8 | 0x08 | `($#,##0.00_);[Red]($#,##0.00)` |
  605. * | 9 | 0x09 | `0%` |
  606. * | 10 | 0x0a | `0.00%` |
  607. * | 11 | 0x0b | `0.00E+00` |
  608. * | 12 | 0x0c | `# ?/?` |
  609. * | 13 | 0x0d | `# ??/??` |
  610. * | 14 | 0x0e | `m/d/yy` |
  611. * | 15 | 0x0f | `d-mmm-yy` |
  612. * | 16 | 0x10 | `d-mmm` |
  613. * | 17 | 0x11 | `mmm-yy` |
  614. * | 18 | 0x12 | `h:mm AM/PM` |
  615. * | 19 | 0x13 | `h:mm:ss AM/PM` |
  616. * | 20 | 0x14 | `h:mm` |
  617. * | 21 | 0x15 | `h:mm:ss` |
  618. * | 22 | 0x16 | `m/d/yy h:mm` |
  619. * | ... | ... | ... |
  620. * | 37 | 0x25 | `(#,##0_);(#,##0)` |
  621. * | 38 | 0x26 | `(#,##0_);[Red](#,##0)` |
  622. * | 39 | 0x27 | `(#,##0.00_);(#,##0.00)` |
  623. * | 40 | 0x28 | `(#,##0.00_);[Red](#,##0.00)` |
  624. * | 41 | 0x29 | `_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)` |
  625. * | 42 | 0x2a | `_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)` |
  626. * | 43 | 0x2b | `_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)` |
  627. * | 44 | 0x2c | `_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)` |
  628. * | 45 | 0x2d | `mm:ss` |
  629. * | 46 | 0x2e | `[h]:mm:ss` |
  630. * | 47 | 0x2f | `mm:ss.0` |
  631. * | 48 | 0x30 | `##0.0E+0` |
  632. * | 49 | 0x31 | `@` |
  633. *
  634. * @note
  635. * - Numeric formats 23 to 36 are not documented by Microsoft and may differ
  636. * in international versions. The listed date and currency formats may also
  637. * vary depending on system settings.
  638. * - The dollar sign in the above format appears as the defined local currency
  639. * symbol.
  640. * - These formats can also be set via format_set_num_format().
  641. */
  642. void format_set_num_format_index(lxw_format *format, uint8_t index);
  643. /**
  644. * @brief Set the cell unlocked state.
  645. *
  646. * @param format Pointer to a Format instance.
  647. *
  648. * This property can be used to allow modification of a cell in a protected
  649. * worksheet. In Excel, cell locking is turned on by default for all
  650. * cells. However, it only has an effect if the worksheet has been protected
  651. * using the worksheet worksheet_protect() function:
  652. *
  653. * @code
  654. * format = workbook_add_format(workbook);
  655. * format_set_unlocked(format);
  656. *
  657. * // Enable worksheet protection, without password or options.
  658. * worksheet_protect(worksheet, NULL, NULL);
  659. *
  660. * // This cell cannot be edited.
  661. * worksheet_write_formula(worksheet, 0, 0, "=1+2", NULL);
  662. *
  663. * // This cell can be edited.
  664. * worksheet_write_formula(worksheet, 1, 0, "=1+2", format);
  665. * @endcode
  666. */
  667. void format_set_unlocked(lxw_format *format);
  668. /**
  669. * @brief Hide formulas in a cell.
  670. *
  671. * @param format Pointer to a Format instance.
  672. *
  673. * This property is used to hide a formula while still displaying its
  674. * result. This is generally used to hide complex calculations from end users
  675. * who are only interested in the result. It only has an effect if the
  676. * worksheet has been protected using the worksheet worksheet_protect()
  677. * function:
  678. *
  679. * @code
  680. * format = workbook_add_format(workbook);
  681. * format_set_hidden(format);
  682. *
  683. * // Enable worksheet protection, without password or options.
  684. * worksheet_protect(worksheet, NULL, NULL);
  685. *
  686. * // The formula in this cell isn't visible.
  687. * worksheet_write_formula(worksheet, 0, 0, "=1+2", format);
  688. * @endcode
  689. */
  690. void format_set_hidden(lxw_format *format);
  691. /**
  692. * @brief Set the alignment for data in the cell.
  693. *
  694. * @param format Pointer to a Format instance.
  695. * @param alignment The horizontal and or vertical alignment direction.
  696. *
  697. * This method is used to set the horizontal and vertical text alignment within a
  698. * cell. The following are the available horizontal alignments:
  699. *
  700. * - #LXW_ALIGN_LEFT
  701. * - #LXW_ALIGN_CENTER
  702. * - #LXW_ALIGN_RIGHT
  703. * - #LXW_ALIGN_FILL
  704. * - #LXW_ALIGN_JUSTIFY
  705. * - #LXW_ALIGN_CENTER_ACROSS
  706. * - #LXW_ALIGN_DISTRIBUTED
  707. *
  708. * The following are the available vertical alignments:
  709. *
  710. * - #LXW_ALIGN_VERTICAL_TOP
  711. * - #LXW_ALIGN_VERTICAL_BOTTOM
  712. * - #LXW_ALIGN_VERTICAL_CENTER
  713. * - #LXW_ALIGN_VERTICAL_JUSTIFY
  714. * - #LXW_ALIGN_VERTICAL_DISTRIBUTED
  715. *
  716. * As in Excel, vertical and horizontal alignments can be combined:
  717. *
  718. * @code
  719. * format = workbook_add_format(workbook);
  720. *
  721. * format_set_align(format, LXW_ALIGN_CENTER);
  722. * format_set_align(format, LXW_ALIGN_VERTICAL_CENTER);
  723. *
  724. * worksheet_set_row(0, 30);
  725. * worksheet_write_string(worksheet, 0, 0, "Some Text", format);
  726. * @endcode
  727. *
  728. * @image html format_font_align.png
  729. *
  730. * Text can be aligned across two or more adjacent cells using the
  731. * center_across property. However, for genuine merged cells it is better to
  732. * use the worksheet_merge_range() worksheet method.
  733. *
  734. * The vertical justify option can be used to provide automatic text wrapping
  735. * in a cell. The height of the cell will be adjusted to accommodate the
  736. * wrapped text. To specify where the text wraps use the
  737. * format_set_text_wrap() method.
  738. */
  739. void format_set_align(lxw_format *format, uint8_t alignment);
  740. /**
  741. * @brief Wrap text in a cell.
  742. *
  743. * Turn text wrapping on for text in a cell.
  744. *
  745. * @code
  746. * format = workbook_add_format(workbook);
  747. * format_set_text_wrap(format);
  748. *
  749. * worksheet_write_string(worksheet, 0, 0, "Some long text to wrap in a cell", format);
  750. * @endcode
  751. *
  752. * If you wish to control where the text is wrapped you can add newline characters
  753. * to the string:
  754. *
  755. * @code
  756. * format = workbook_add_format(workbook);
  757. * format_set_text_wrap(format);
  758. *
  759. * worksheet_write_string(worksheet, 0, 0, "It's\na bum\nwrap", format);
  760. * @endcode
  761. *
  762. * @image html format_font_text_wrap.png
  763. *
  764. * Excel will adjust the height of the row to accommodate the wrapped text. A
  765. * similar effect can be obtained without newlines using the
  766. * format_set_align() function with #LXW_ALIGN_VERTICAL_JUSTIFY.
  767. */
  768. void format_set_text_wrap(lxw_format *format);
  769. /**
  770. * @brief Set the rotation of the text in a cell.
  771. *
  772. * @param format Pointer to a Format instance.
  773. * @param angle Rotation angle in the range -90 to 90 and 270.
  774. *
  775. * Set the rotation of the text in a cell. The rotation can be any angle in the
  776. * range -90 to 90 degrees:
  777. *
  778. * @code
  779. * format = workbook_add_format(workbook);
  780. * format_set_rotation(format, 30);
  781. *
  782. * worksheet_write_string(worksheet, 0, 0, "This text is rotated", format);
  783. * @endcode
  784. *
  785. * @image html format_font_text_rotated.png
  786. *
  787. * The angle 270 is also supported. This indicates text where the letters run from
  788. * top to bottom.
  789. */
  790. void format_set_rotation(lxw_format *format, int16_t angle);
  791. /**
  792. * @brief Set the cell text indentation level.
  793. *
  794. * @param format Pointer to a Format instance.
  795. * @param level Indentation level.
  796. *
  797. * This method can be used to indent text in a cell. The argument, which should be
  798. * an integer, is taken as the level of indentation:
  799. *
  800. * @code
  801. * format1 = workbook_add_format(workbook);
  802. * format2 = workbook_add_format(workbook);
  803. *
  804. * format_set_indent(format1, 1);
  805. * format_set_indent(format2, 2);
  806. *
  807. * worksheet_write_string(worksheet, 0, 0, "This text is indented 1 level", format1);
  808. * worksheet_write_string(worksheet, 1, 0, "This text is indented 2 levels", format2);
  809. * @endcode
  810. *
  811. * @image html text_indent.png
  812. *
  813. * @note
  814. * Indentation is a horizontal alignment property. It will override any other
  815. * horizontal properties but it can be used in conjunction with vertical
  816. * properties.
  817. */
  818. void format_set_indent(lxw_format *format, uint8_t level);
  819. /**
  820. * @brief Turn on the text "shrink to fit" for a cell.
  821. *
  822. * @param format Pointer to a Format instance.
  823. *
  824. * This method can be used to shrink text so that it fits in a cell:
  825. *
  826. * @code
  827. * format = workbook_add_format(workbook);
  828. * format_set_shrink(format);
  829. *
  830. * worksheet_write_string(worksheet, 0, 0, "Honey, I shrunk the text!", format);
  831. * @endcode
  832. */
  833. void format_set_shrink(lxw_format *format);
  834. /**
  835. * @brief Set the background fill pattern for a cell
  836. *
  837. * @param format Pointer to a Format instance.
  838. * @param index Pattern index.
  839. *
  840. * Set the background pattern for a cell.
  841. *
  842. * The most common pattern is a solid fill of the background color:
  843. *
  844. * @code
  845. * format = workbook_add_format(workbook);
  846. *
  847. * format_set_pattern (format, LXW_PATTERN_SOLID);
  848. * format_set_bg_color(format, LXW_COLOR_YELLOW);
  849. * @endcode
  850. *
  851. * The available fill patterns are:
  852. *
  853. * Fill Type | Define
  854. * ----------------------------- | -----------------------------
  855. * Solid | #LXW_PATTERN_SOLID
  856. * Medium gray | #LXW_PATTERN_MEDIUM_GRAY
  857. * Dark gray | #LXW_PATTERN_DARK_GRAY
  858. * Light gray | #LXW_PATTERN_LIGHT_GRAY
  859. * Dark horizontal line | #LXW_PATTERN_DARK_HORIZONTAL
  860. * Dark vertical line | #LXW_PATTERN_DARK_VERTICAL
  861. * Dark diagonal stripe | #LXW_PATTERN_DARK_DOWN
  862. * Reverse dark diagonal stripe | #LXW_PATTERN_DARK_UP
  863. * Dark grid | #LXW_PATTERN_DARK_GRID
  864. * Dark trellis | #LXW_PATTERN_DARK_TRELLIS
  865. * Light horizontal line | #LXW_PATTERN_LIGHT_HORIZONTAL
  866. * Light vertical line | #LXW_PATTERN_LIGHT_VERTICAL
  867. * Light diagonal stripe | #LXW_PATTERN_LIGHT_DOWN
  868. * Reverse light diagonal stripe | #LXW_PATTERN_LIGHT_UP
  869. * Light grid | #LXW_PATTERN_LIGHT_GRID
  870. * Light trellis | #LXW_PATTERN_LIGHT_TRELLIS
  871. * 12.5% gray | #LXW_PATTERN_GRAY_125
  872. * 6.25% gray | #LXW_PATTERN_GRAY_0625
  873. *
  874. */
  875. void format_set_pattern(lxw_format *format, uint8_t index);
  876. /**
  877. * @brief Set the pattern background color for a cell.
  878. *
  879. * @param format Pointer to a Format instance.
  880. * @param color The cell pattern background color.
  881. *
  882. * The format_set_bg_color() method can be used to set the background color of
  883. * a pattern. Patterns are defined via the format_set_pattern() method. If a
  884. * pattern hasn't been defined then a solid fill pattern is used as the
  885. * default.
  886. *
  887. * Here is an example of how to set up a solid fill in a cell:
  888. *
  889. * @code
  890. * format = workbook_add_format(workbook);
  891. *
  892. * format_set_pattern (format, LXW_PATTERN_SOLID);
  893. * format_set_bg_color(format, LXW_COLOR_GREEN);
  894. *
  895. * worksheet_write_string(worksheet, 0, 0, "Ray", format);
  896. * @endcode
  897. *
  898. * @image html formats_set_bg_color.png
  899. *
  900. * The color should be an RGB integer value, see @ref working_with_colors.
  901. *
  902. */
  903. void format_set_bg_color(lxw_format *format, lxw_color_t color);
  904. /**
  905. * @brief Set the pattern foreground color for a cell.
  906. *
  907. * @param format Pointer to a Format instance.
  908. * @param color The cell pattern foreground color.
  909. *
  910. * The format_set_fg_color() method can be used to set the foreground color of
  911. * a pattern.
  912. *
  913. * The color should be an RGB integer value, see @ref working_with_colors.
  914. *
  915. */
  916. void format_set_fg_color(lxw_format *format, lxw_color_t color);
  917. /**
  918. * @brief Set the cell border style.
  919. *
  920. * @param format Pointer to a Format instance.
  921. * @param style Border style index.
  922. *
  923. * Set the cell border style:
  924. *
  925. * @code
  926. * format_set_border(format, LXW_BORDER_THIN);
  927. * @endcode
  928. *
  929. * Individual border elements can be configured using the following functions with
  930. * the same parameters:
  931. *
  932. * - format_set_bottom()
  933. * - format_set_top()
  934. * - format_set_left()
  935. * - format_set_right()
  936. *
  937. * A cell border is comprised of a border on the bottom, top, left and right.
  938. * These can be set to the same value using format_set_border() or
  939. * individually using the relevant method calls shown above.
  940. *
  941. * The following border styles are available:
  942. *
  943. * - #LXW_BORDER_THIN
  944. * - #LXW_BORDER_MEDIUM
  945. * - #LXW_BORDER_DASHED
  946. * - #LXW_BORDER_DOTTED
  947. * - #LXW_BORDER_THICK
  948. * - #LXW_BORDER_DOUBLE
  949. * - #LXW_BORDER_HAIR
  950. * - #LXW_BORDER_MEDIUM_DASHED
  951. * - #LXW_BORDER_DASH_DOT
  952. * - #LXW_BORDER_MEDIUM_DASH_DOT
  953. * - #LXW_BORDER_DASH_DOT_DOT
  954. * - #LXW_BORDER_MEDIUM_DASH_DOT_DOT
  955. * - #LXW_BORDER_SLANT_DASH_DOT
  956. *
  957. * The most commonly used style is the `thin` style.
  958. */
  959. void format_set_border(lxw_format *format, uint8_t style);
  960. /**
  961. * @brief Set the cell bottom border style.
  962. *
  963. * @param format Pointer to a Format instance.
  964. * @param style Border style index.
  965. *
  966. * Set the cell bottom border style. See format_set_border() for details on the
  967. * border styles.
  968. */
  969. void format_set_bottom(lxw_format *format, uint8_t style);
  970. /**
  971. * @brief Set the cell top border style.
  972. *
  973. * @param format Pointer to a Format instance.
  974. * @param style Border style index.
  975. *
  976. * Set the cell top border style. See format_set_border() for details on the border
  977. * styles.
  978. */
  979. void format_set_top(lxw_format *format, uint8_t style);
  980. /**
  981. * @brief Set the cell left border style.
  982. *
  983. * @param format Pointer to a Format instance.
  984. * @param style Border style index.
  985. *
  986. * Set the cell left border style. See format_set_border() for details on the
  987. * border styles.
  988. */
  989. void format_set_left(lxw_format *format, uint8_t style);
  990. /**
  991. * @brief Set the cell right border style.
  992. *
  993. * @param format Pointer to a Format instance.
  994. * @param style Border style index.
  995. *
  996. * Set the cell right border style. See format_set_border() for details on the
  997. * border styles.
  998. */
  999. void format_set_right(lxw_format *format, uint8_t style);
  1000. /**
  1001. * @brief Set the color of the cell border.
  1002. *
  1003. * @param format Pointer to a Format instance.
  1004. * @param color The cell border color.
  1005. *
  1006. * Individual border elements can be configured using the following methods with
  1007. * the same parameters:
  1008. *
  1009. * - format_set_bottom_color()
  1010. * - format_set_top_color()
  1011. * - format_set_left_color()
  1012. * - format_set_right_color()
  1013. *
  1014. * Set the color of the cell borders. A cell border is comprised of a border
  1015. * on the bottom, top, left and right. These can be set to the same color
  1016. * using format_set_border_color() or individually using the relevant method
  1017. * calls shown above.
  1018. *
  1019. * The color should be an RGB integer value, see @ref working_with_colors.
  1020. */
  1021. void format_set_border_color(lxw_format *format, lxw_color_t color);
  1022. /**
  1023. * @brief Set the color of the bottom cell border.
  1024. *
  1025. * @param format Pointer to a Format instance.
  1026. * @param color The cell border color.
  1027. *
  1028. * See format_set_border_color() for details on the border colors.
  1029. */
  1030. void format_set_bottom_color(lxw_format *format, lxw_color_t color);
  1031. /**
  1032. * @brief Set the color of the top cell border.
  1033. *
  1034. * @param format Pointer to a Format instance.
  1035. * @param color The cell border color.
  1036. *
  1037. * See format_set_border_color() for details on the border colors.
  1038. */
  1039. void format_set_top_color(lxw_format *format, lxw_color_t color);
  1040. /**
  1041. * @brief Set the color of the left cell border.
  1042. *
  1043. * @param format Pointer to a Format instance.
  1044. * @param color The cell border color.
  1045. *
  1046. * See format_set_border_color() for details on the border colors.
  1047. */
  1048. void format_set_left_color(lxw_format *format, lxw_color_t color);
  1049. /**
  1050. * @brief Set the color of the right cell border.
  1051. *
  1052. * @param format Pointer to a Format instance.
  1053. * @param color The cell border color.
  1054. *
  1055. * See format_set_border_color() for details on the border colors.
  1056. */
  1057. void format_set_right_color(lxw_format *format, lxw_color_t color);
  1058. void format_set_diag_type(lxw_format *format, uint8_t value);
  1059. void format_set_diag_color(lxw_format *format, lxw_color_t color);
  1060. void format_set_diag_border(lxw_format *format, uint8_t value);
  1061. void format_set_font_outline(lxw_format *format);
  1062. void format_set_font_shadow(lxw_format *format);
  1063. void format_set_font_family(lxw_format *format, uint8_t value);
  1064. void format_set_font_charset(lxw_format *format, uint8_t value);
  1065. void format_set_font_scheme(lxw_format *format, const char *font_scheme);
  1066. void format_set_font_condense(lxw_format *format);
  1067. void format_set_font_extend(lxw_format *format);
  1068. void format_set_reading_order(lxw_format *format, uint8_t value);
  1069. void format_set_theme(lxw_format *format, uint8_t value);
  1070. /* Declarations required for unit testing. */
  1071. #ifdef TESTING
  1072. #endif /* TESTING */
  1073. /* *INDENT-OFF* */
  1074. #ifdef __cplusplus
  1075. }
  1076. #endif
  1077. /* *INDENT-ON* */
  1078. #endif /* __LXW_FORMAT_H__ */