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