1 /*
2  * libxlsxwriter
3  *
4  * Copyright 2014-2016, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
5  */
6 
7 /**
8  * @page worksheet_page The Worksheet object
9  *
10  * The Worksheet object represents an Excel worksheet. It handles
11  * operations such as writing data to cells or formatting worksheet
12  * layout.
13  *
14  * See @ref worksheet.h for full details of the functionality.
15  *
16  * @file worksheet.h
17  *
18  * @brief Functions related to adding data and formatting to a worksheet.
19  *
20  * The Worksheet object represents an Excel worksheet. It handles
21  * operations such as writing data to cells or formatting worksheet
22  * layout.
23  *
24  * A Worksheet object isn't created directly. Instead a worksheet is
25  * created by calling the workbook_add_worksheet() function from a
26  * Workbook object:
27  *
28  * @code
29  *     #include "xlsxwriter.h"
30  *
31  *     int main() {
32  *
33  *         lxw_workbook  *workbook  = workbook_new("filename.xlsx");
34  *         lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
35  *
36  *         worksheet_write_string(worksheet, 0, 0, "Hello Excel", NULL);
37  *
38  *         return workbook_close(workbook);
39  *     }
40  * @endcode
41  *
42  */
43 module xlsxwriter.worksheet;
44 
45 import core.stdc.stdint;
46 
47 import xlsxwriter.chart;
48 import xlsxwriter.common;
49 import xlsxwriter.format;
50 import xlsxwriter.utility;
51 
52 extern(C):
53 
54 enum LXW_ROW_MAX = 1048576;
55 enum LXW_COL_MAX  = 16384;
56 enum LXW_COL_META_MAX = 128;
57 enum LXW_HEADER_FOOTER_MAX = 255;
58 enum LXW_MAX_NUMBER_URLS = 65530;
59 enum LXW_PANE_NAME_LENGTH = 12; /* bottomRight + 1 */
60 
61 /* The Excel 2007 specification says that the maximum number of page
62  * breaks is 1026. However, in practice it is actually 1023. */
63 enum LXW_BREAKS_MAX = 1023;
64 
65 /** Default column width in Excel */
66 enum LXW_DEF_COL_WIDTH = 8.43;
67 
68 /** Default row height in Excel */
69 enum LXW_DEF_ROW_HEIGHT  = 15.0;
70 
71 /** Gridline options using in `worksheet_gridlines()`. */
72 enum lxw_gridlines {
73     /** Hide screen and print gridlines. */
74     LXW_HIDE_ALL_GRIDLINES = 0,
75     /** Show screen gridlines. */
76     LXW_SHOW_SCREEN_GRIDLINES,
77     /** Show print gridlines. */
78     LXW_SHOW_PRINT_GRIDLINES,
79     /** Show screen and print gridlines. */
80     LXW_SHOW_ALL_GRIDLINES
81 }
82 
83 enum cell_types {
84     NUMBER_CELL = 1,
85     STRING_CELL,
86     INLINE_STRING_CELL,
87     FORMULA_CELL,
88     ARRAY_FORMULA_CELL,
89     BLANK_CELL,
90     BOOLEAN_CELL,
91     HYPERLINK_URL,
92     HYPERLINK_INTERNAL,
93     HYPERLINK_EXTERNAL
94 }
95 
96 enum pane_types {
97     NO_PANES = 0,
98     FREEZE_PANES,
99     SPLIT_PANES,
100     FREEZE_SPLIT_PANES
101 }
102 
103 
104 /* Define a RB_TREE struct manually to add extra members. */
105 struct lxw_table_rows {}
106 
107 /**
108  * @brief Options for rows and columns.
109  *
110  * Options struct for the worksheet_set_column() and worksheet_set_row()
111  * functions.
112  *
113  * It has the following members but currently only the `hidden` property is
114  * supported:
115  *
116  * * `hidden`
117  * * `level`
118  * * `collapsed`
119  */
120 struct lxw_row_col_options {
121     /** Hide the row/column */
122     uint8_t hidden;
123     uint8_t level;
124     uint8_t collapsed;
125 }
126 
127 struct lxw_col_options {
128     lxw_col_t firstcol;
129     lxw_col_t lastcol;
130     double width;
131     lxw_format *format;
132     uint8_t hidden;
133     uint8_t level;
134     uint8_t collapsed;
135 } 
136 
137 struct lxw_merged_range {}
138 
139 struct lxw_repeat_rows {}
140 
141 struct lxw_repeat_cols {
142     uint8_t in_use;
143     lxw_col_t first_col;
144     lxw_col_t last_col;
145 }
146 
147 struct lxw_print_area {
148     uint8_t in_use;
149     lxw_row_t first_row;
150     lxw_row_t last_row;
151     lxw_col_t first_col;
152     lxw_col_t last_col;
153 }
154 
155 struct lxw_autofilter {
156     uint8_t in_use;
157     lxw_row_t first_row;
158     lxw_row_t last_row;
159     lxw_col_t first_col;
160     lxw_col_t last_col;
161 }
162 
163 struct lxw_panes {
164     uint8_t type;
165     lxw_row_t first_row;
166     lxw_col_t first_col;
167     lxw_row_t top_row;
168     lxw_col_t left_col;
169     double x_split;
170     double y_split;
171 }
172 
173 struct lxw_selection {}
174 
175 /**
176  * @brief Options for inserted images
177  *
178  * Options for modifying images inserted via `worksheet_insert_image_opt()`.
179  *
180  */
181 struct lxw_image_options {
182 
183     /** Offset from the left of the cell in pixels. */
184     int32_t x_offset;
185 
186     /** Offset from the top of the cell in pixels. */
187     int32_t y_offset;
188 
189     /** X scale of the image as a decimal. */
190     double x_scale;
191 
192     /** Y scale of the image as a decimal. */
193     double y_scale;
194 
195 }
196 
197 /**
198  * @brief Header and footer options.
199  *
200  * Optional parameters used in the worksheet_set_header_opt() and
201  * worksheet_set_footer_opt() functions.
202  *
203  */
204 struct lxw_header_footer_options {
205     /** Header or footer margin in inches. Excel default is 0.3. */
206     double margin;
207 }
208 
209 /**
210  * @brief Worksheet protection options.
211  */
212 struct lxw_protection {
213     /** Turn off selection of locked cells. This in on in Excel by default.*/
214     uint8_t no_select_locked_cells;
215 
216     /** Turn off selection of unlocked cells. This in on in Excel by default.*/
217     uint8_t no_select_unlocked_cells;
218 
219     /** Prevent formatting of cells. */
220     uint8_t format_cells;
221 
222     /** Prevent formatting of columns. */
223     uint8_t format_columns;
224 
225     /** Prevent formatting of rows. */
226     uint8_t format_rows;
227 
228     /** Prevent insertion of columns. */
229     uint8_t insert_columns;
230 
231     /** Prevent insertion of rows. */
232     uint8_t insert_rows;
233 
234     /** Prevent insertion of hyperlinks. */
235     uint8_t insert_hyperlinks;
236 
237     /** Prevent deletion of columns. */
238     uint8_t delete_columns;
239 
240     /** Prevent deletion of rows. */
241     uint8_t delete_rows;
242 
243     /** Prevent sorting data. */
244     uint8_t sort;
245 
246     /** Prevent filtering data. */
247     uint8_t autofilter;
248 
249     /** Prevent insertion of pivot tables. */
250     uint8_t pivot_tables;
251 
252     /** Protect scenarios. */
253     uint8_t scenarios;
254 
255     /** Protect drawing objects. */
256     uint8_t objects;
257 
258 }
259 
260 /**
261  * @brief Struct to represent an Excel worksheet.
262  *
263  * The members of the lxw_worksheet struct aren't modified directly. Instead
264  * the worksheet properties are set by calling the functions shown in
265  * worksheet.h.
266  */
267 struct lxw_worksheet {}
268 
269 /*
270  * Worksheet initialization data.
271  */
272 struct lxw_worksheet_init_data {}
273 
274 /* Struct to represent a worksheet row. */
275 struct lxw_row {}
276 
277 /* Struct to represent a worksheet cell. */
278 struct lxw_cell {}
279 
280 /**
281  * @brief Write a number to a worksheet cell.
282  *
283  * @param worksheet pointer to a lxw_worksheet instance to be updated.
284  * @param row       The zero indexed row number.
285  * @param col       The zero indexed column number.
286  * @param number    The number to write to the cell.
287  * @param format    A pointer to a Format instance or NULL.
288  *
289  * @return A #lxw_error code.
290  *
291  * The `worksheet_write_number()` function writes numeric types to the cell
292  * specified by `row` and `column`:
293  *
294  * @code
295  *     worksheet_write_number(worksheet, 0, 0, 123456, NULL);
296  *     worksheet_write_number(worksheet, 1, 0, 2.3451, NULL);
297  * @endcode
298  *
299  * @image html write_number01.png
300  *
301  * The native data type for all numbers in Excel is a IEEE-754 64-bit
302  * double-precision floating point, which is also the default type used by
303  * `%worksheet_write_number`.
304  *
305  * The `format` parameter is used to apply formatting to the cell. This
306  * parameter can be `NULL` to indicate no formatting or it can be a
307  * @ref format.h "Format" object.
308  *
309  * @code
310  *     lxw_format *format = workbook_add_format(workbook);
311  *     format_set_num_format(format, "$#,##0.00");
312  *
313  *     worksheet_write_number(worksheet, 0, 0, 1234.567, format);
314  * @endcode
315  *
316  * @image html write_number02.png
317  *
318  */
319 lxw_error worksheet_write_number(lxw_worksheet *worksheet,
320                                  lxw_row_t row,
321                                  lxw_col_t col, double number,
322                                  lxw_format *format);
323 /**
324  * @brief Write a string to a worksheet cell.
325  *
326  * @param worksheet pointer to a lxw_worksheet instance to be updated.
327  * @param row       The zero indexed row number.
328  * @param col       The zero indexed column number.
329  * @param string    String to write to cell.
330  * @param format    A pointer to a Format instance or NULL.
331  *
332  * @return A #lxw_error code.
333  *
334  * The `%worksheet_write_string()` function writes a string to the cell
335  * specified by `row` and `column`:
336  *
337  * @code
338  *     worksheet_write_string(worksheet, 0, 0, "This phrase is English!", NULL);
339  * @endcode
340  *
341  * @image html write_string01.png
342  *
343  * The `format` parameter is used to apply formatting to the cell. This
344  * parameter can be `NULL` to indicate no formatting or it can be a
345  * @ref format.h "Format" object:
346  *
347  * @code
348  *     lxw_format *format = workbook_add_format(workbook);
349  *     format_set_bold(format);
350  *
351  *     worksheet_write_string(worksheet, 0, 0, "This phrase is Bold!", format);
352  * @endcode
353  *
354  * @image html write_string02.png
355  *
356  * Unicode strings are supported in UTF-8 encoding. This generally requires
357  * that your source file is UTF-8 encoded or that the data has been read from
358  * a UTF-8 source:
359  *
360  * @code
361  *    worksheet_write_string(worksheet, 0, 0, "Это фраза на русском!", NULL);
362  * @endcode
363  *
364  * @image html write_string03.png
365  *
366  */
367 lxw_error worksheet_write_string(lxw_worksheet *worksheet,
368                                  lxw_row_t row,
369                                  lxw_col_t col, const char *string,
370                                  lxw_format *format);
371 /**
372  * @brief Write a formula to a worksheet cell.
373  *
374  * @param worksheet pointer to a lxw_worksheet instance to be updated.
375  * @param row       The zero indexed row number.
376  * @param col       The zero indexed column number.
377  * @param formula   Formula string to write to cell.
378  * @param format    A pointer to a Format instance or NULL.
379  *
380  * @return A #lxw_error code.
381  *
382  * The `%worksheet_write_formula()` function writes a formula or function to
383  * the cell specified by `row` and `column`:
384  *
385  * @code
386  *  worksheet_write_formula(worksheet, 0, 0, "=B3 + 6",                    NULL);
387  *  worksheet_write_formula(worksheet, 1, 0, "=SIN(PI()/4)",               NULL);
388  *  worksheet_write_formula(worksheet, 2, 0, "=SUM(A1:A2)",                NULL);
389  *  worksheet_write_formula(worksheet, 3, 0, "=IF(A3>1,\"Yes\", \"No\")",  NULL);
390  *  worksheet_write_formula(worksheet, 4, 0, "=AVERAGE(1, 2, 3, 4)",       NULL);
391  *  worksheet_write_formula(worksheet, 5, 0, "=DATEVALUE(\"1-Jan-2013\")", NULL);
392  * @endcode
393  *
394  * @image html write_formula01.png
395  *
396  * The `format` parameter is used to apply formatting to the cell. This
397  * parameter can be `NULL` to indicate no formatting or it can be a
398  * @ref format.h "Format" object.
399  *
400  * Libxlsxwriter doesn't calculate the value of a formula and instead stores a
401  * default value of `0`. The correct formula result is displayed in Excel, as
402  * shown in the example above, since it recalculates the formulas when it loads
403  * the file. For cases where this is an issue see the
404  * `worksheet_write_formula_num()` function and the discussion in that section.
405  *
406  * Formulas must be written with the US style separator/range operator which
407  * is a comma (not semi-colon). Therefore a formula with multiple values
408  * should be written as follows:
409  *
410  * @code
411  *     // OK.
412  *     worksheet_write_formula(worksheet, 0, 0, "=SUM(1, 2, 3)", NULL);
413  *
414  *     // NO. Error on load.
415  *     worksheet_write_formula(worksheet, 1, 0, "=SUM(1; 2; 3)", NULL);
416  * @endcode
417  *
418  */
419 lxw_error worksheet_write_formula(lxw_worksheet *worksheet,
420                                   lxw_row_t row,
421                                   lxw_col_t col, const char *formula,
422                                   lxw_format *format);
423 /**
424  * @brief Write an array formula to a worksheet cell.
425  *
426  * @param worksheet
427  * @param first_row   The first row of the range. (All zero indexed.)
428  * @param first_col   The first column of the range.
429  * @param last_row    The last row of the range.
430  * @param last_col    The last col of the range.
431  * @param formula     Array formula to write to cell.
432  * @param format      A pointer to a Format instance or NULL.
433  *
434  * @return A #lxw_error code.
435  *
436   * The `%worksheet_write_array_formula()` function writes an array formula to
437  * a cell range. In Excel an array formula is a formula that performs a
438  * calculation on a set of values.
439  *
440  * In Excel an array formula is indicated by a pair of braces around the
441  * formula: `{=SUM(A1:B1*A2:B2)}`.
442  *
443  * Array formulas can return a single value or a range or values. For array
444  * formulas that return a range of values you must specify the range that the
445  * return values will be written to. This is why this function has `first_`
446  * and `last_` row/column parameters. The RANGE() macro can also be used to
447  * specify the range:
448  *
449  * @code
450  *     worksheet_write_array_formula(worksheet, 4, 0, 6, 0,     "{=TREND(C5:C7,B5:B7)}", NULL);
451  *
452  *     // Same as above using the RANGE() macro.
453  *     worksheet_write_array_formula(worksheet, RANGE("A5:A7"), "{=TREND(C5:C7,B5:B7)}", NULL);
454  * @endcode
455  *
456  * If the array formula returns a single value then the `first_` and `last_`
457  * parameters should be the same:
458  *
459  * @code
460  *     worksheet_write_array_formula(worksheet, 1, 0, 1, 0,     "{=SUM(B1:C1*B2:C2)}", NULL);
461  *     worksheet_write_array_formula(worksheet, RANGE("A2:A2"), "{=SUM(B1:C1*B2:C2)}", NULL);
462  * @endcode
463  *
464  */
465 lxw_error worksheet_write_array_formula(lxw_worksheet *worksheet,
466                                         lxw_row_t first_row,
467                                         lxw_col_t first_col,
468                                         lxw_row_t last_row,
469                                         lxw_col_t last_col,
470                                         const char *formula,
471                                         lxw_format *format);
472 
473 lxw_error worksheet_write_array_formula_num(lxw_worksheet *worksheet,
474                                             lxw_row_t first_row,
475                                             lxw_col_t first_col,
476                                             lxw_row_t last_row,
477                                             lxw_col_t last_col,
478                                             const char *formula,
479                                             lxw_format *format,
480                                             double result);
481 
482 /**
483  * @brief Write a date or time to a worksheet cell.
484  *
485  * @param worksheet pointer to a lxw_worksheet instance to be updated.
486  * @param row       The zero indexed row number.
487  * @param col       The zero indexed column number.
488  * @param datetime  The datetime to write to the cell.
489  * @param format    A pointer to a Format instance or NULL.
490  *
491  * @return A #lxw_error code.
492  *
493  * The `worksheet_write_datetime()` function can be used to write a date or
494  * time to the cell specified by `row` and `column`:
495  *
496  * @dontinclude dates_and_times02.c
497  * @skip include
498  * @until num_format
499  * @skip Feb
500  * @until }
501  *
502  * The `format` parameter should be used to apply formatting to the cell using
503  * a @ref format.h "Format" object as shown above. Without a date format the
504  * datetime will appear as a number only.
505  *
506  * See @ref working_with_dates for more information about handling dates and
507  * times in libxlsxwriter.
508  */
509 lxw_error worksheet_write_datetime(lxw_worksheet *worksheet,
510                                    lxw_row_t row,
511                                    lxw_col_t col, lxw_datetime *datetime,
512                                    lxw_format *format);
513 
514 lxw_error worksheet_write_url_opt(lxw_worksheet *worksheet,
515                                   lxw_row_t row_num,
516                                   lxw_col_t col_num, const char *url,
517                                   lxw_format *format, const char *string,
518                                   const char *tooltip);
519 /**
520  *
521  * @param worksheet pointer to a lxw_worksheet instance to be updated.
522  * @param row       The zero indexed row number.
523  * @param col       The zero indexed column number.
524  * @param url       The url to write to the cell.
525  * @param format    A pointer to a Format instance or NULL.
526  *
527  * @return A #lxw_error code.
528  *
529  *
530  * The `%worksheet_write_url()` function is used to write a URL/hyperlink to a
531  * worksheet cell specified by `row` and `column`.
532  *
533  * @code
534  *     worksheet_write_url(worksheet, 0, 0, "http://libxlsxwriter.github.io", url_format);
535  * @endcode
536  *
537  * @image html hyperlinks_short.png
538  *
539  * The `format` parameter is used to apply formatting to the cell. This
540  * parameter can be `NULL` to indicate no formatting or it can be a @ref
541  * format.h "Format" object. The typical worksheet format for a hyperlink is a
542  * blue underline:
543  *
544  * @code
545  *    lxw_format *url_format   = workbook_add_format(workbook);
546  *
547  *    format_set_underline (url_format, LXW_UNDERLINE_SINGLE);
548  *    format_set_font_color(url_format, LXW_COLOR_BLUE);
549  *
550  * @endcode
551  *
552  * The usual web style URI's are supported: `%http://`, `%https://`, `%ftp://`
553  * and `mailto:` :
554  *
555  * @code
556  *     worksheet_write_url(worksheet, 0, 0, "ftp://www.python.org/",     url_format);
557  *     worksheet_write_url(worksheet, 1, 0, "http://www.python.org/",    url_format);
558  *     worksheet_write_url(worksheet, 2, 0, "https://www.python.org/",   url_format);
559  *     worksheet_write_url(worksheet, 3, 0, "mailto:jmcnamara@cpan.org", url_format);
560  *
561  * @endcode
562  *
563  * An Excel hyperlink is comprised of two elements: the displayed string and
564  * the non-displayed link. By default the displayed string is the same as the
565  * link. However, it is possible to overwrite it with any other
566  * `libxlsxwriter` type using the appropriate `worksheet_write_*()`
567  * function. The most common case is to overwrite the displayed link text with
568  * another string:
569  *
570  * @code
571  *  // Write a hyperlink but overwrite the displayed string.
572  *  worksheet_write_url   (worksheet, 2, 0, "http://libxlsxwriter.github.io", url_format);
573  *  worksheet_write_string(worksheet, 2, 0, "Read the documentation.",        url_format);
574  *
575  * @endcode
576  *
577  * @image html hyperlinks_short2.png
578  *
579  * Two local URIs are supported: `internal:` and `external:`. These are used
580  * for hyperlinks to internal worksheet references or external workbook and
581  * worksheet references:
582  *
583  * @code
584  *     worksheet_write_url(worksheet, 0, 0, "internal:Sheet2!A1",                url_format);
585  *     worksheet_write_url(worksheet, 1, 0, "internal:Sheet2!B2",                url_format);
586  *     worksheet_write_url(worksheet, 2, 0, "internal:Sheet2!A1:B2",             url_format);
587  *     worksheet_write_url(worksheet, 3, 0, "internal:'Sales Data'!A1",          url_format);
588  *     worksheet_write_url(worksheet, 4, 0, "external:c:\\temp\\foo.xlsx",       url_format);
589  *     worksheet_write_url(worksheet, 5, 0, "external:c:\\foo.xlsx#Sheet2!A1",   url_format);
590  *     worksheet_write_url(worksheet, 6, 0, "external:..\\foo.xlsx",             url_format);
591  *     worksheet_write_url(worksheet, 7, 0, "external:..\\foo.xlsx#Sheet2!A1",   url_format);
592  *     worksheet_write_url(worksheet, 8, 0, "external:\\\\NET\\share\\foo.xlsx", url_format);
593  *
594  * @endcode
595  *
596  * Worksheet references are typically of the form `Sheet1!A1`. You can also
597  * link to a worksheet range using the standard Excel notation:
598  * `Sheet1!A1:B2`.
599  *
600  * In external links the workbook and worksheet name must be separated by the
601  * `#` character:
602  *
603  * @code
604  *     worksheet_write_url(worksheet, 0, 0, "external:c:\\foo.xlsx#Sheet2!A1",   url_format);
605  * @endcode
606  *
607  * You can also link to a named range in the target worksheet: For example say
608  * you have a named range called `my_name` in the workbook `c:\temp\foo.xlsx`
609  * you could link to it as follows:
610  *
611  * @code
612  *     worksheet_write_url(worksheet, 0, 0, "external:c:\\temp\\foo.xlsx#my_name", url_format);
613  *
614  * @endcode
615  *
616  * Excel requires that worksheet names containing spaces or non alphanumeric
617  * characters are single quoted as follows:
618  *
619  * @code
620  *     worksheet_write_url(worksheet, 0, 0, "internal:'Sales Data'!A1", url_format);
621  * @endcode
622  *
623  * Links to network files are also supported. Network files normally begin
624  * with two back slashes as follows `\\NETWORK\etc`. In order to represent
625  * this in a C string literal the backslashes should be escaped:
626  * @code
627  *     worksheet_write_url(worksheet, 0, 0, "external:\\\\NET\\share\\foo.xlsx", url_format);
628  * @endcode
629  *
630  *
631  * Alternatively, you can use Windows style forward slashes. These are
632  * translated internally to backslashes:
633  *
634  * @code
635  *     worksheet_write_url(worksheet, 0, 0, "external:c:/temp/foo.xlsx",     url_format);
636  *     worksheet_write_url(worksheet, 1, 0, "external://NET/share/foo.xlsx", url_format);
637  *
638  * @endcode
639  *
640  *
641  * **Note:**
642  *
643  *    libxlsxwriter will escape the following characters in URLs as required
644  *    by Excel: `\s " < > \ [ ]  ^ { }` unless the URL already contains `%%xx`
645  *    style escapes. In which case it is assumed that the URL was escaped
646  *    correctly by the user and will by passed directly to Excel.
647  *
648  */
649 lxw_error worksheet_write_url(lxw_worksheet *worksheet,
650                               lxw_row_t row,
651                               lxw_col_t col, const char *url,
652                               lxw_format *format);
653 
654 /**
655  * @brief Write a formatted boolean worksheet cell.
656  *
657  * @param worksheet pointer to a lxw_worksheet instance to be updated.
658  * @param row       The zero indexed row number.
659  * @param col       The zero indexed column number.
660  * @param value     The boolean value to write to the cell.
661  * @param format    A pointer to a Format instance or NULL.
662  *
663  * @return A #lxw_error code.
664  *
665  * Write an Excel boolean to the cell specified by `row` and `column`:
666  *
667  * @code
668  *     worksheet_write_boolean(worksheet, 2, 2, 0, my_format);
669  * @endcode
670  *
671  */
672 lxw_error worksheet_write_boolean(lxw_worksheet *worksheet,
673                                   lxw_row_t row, lxw_col_t col,
674                                   int value, lxw_format *format);
675 
676 /**
677  * @brief Write a formatted blank worksheet cell.
678  *
679  * @param worksheet pointer to a lxw_worksheet instance to be updated.
680  * @param row       The zero indexed row number.
681  * @param col       The zero indexed column number.
682  * @param format    A pointer to a Format instance or NULL.
683  *
684  * @return A #lxw_error code.
685  *
686  * Write a blank cell specified by `row` and `column`:
687  *
688  * @code
689  *     worksheet_write_blank(worksheet, 1, 1, border_format);
690  * @endcode
691  *
692  * This function is used to add formatting to a cell which doesn't contain a
693  * string or number value.
694  *
695  * Excel differentiates between an "Empty" cell and a "Blank" cell. An Empty
696  * cell is a cell which doesn't contain data or formatting whilst a Blank cell
697  * doesn't contain data but does contain formatting. Excel stores Blank cells
698  * but ignores Empty cells.
699  *
700  * As such, if you write an empty cell without formatting it is ignored.
701  *
702  */
703 lxw_error worksheet_write_blank(lxw_worksheet *worksheet,
704                                 lxw_row_t row, lxw_col_t col,
705                                 lxw_format *format);
706 
707 /**
708  * @brief Write a formula to a worksheet cell with a user defined result.
709  *
710  * @param worksheet pointer to a lxw_worksheet instance to be updated.
711  * @param row       The zero indexed row number.
712  * @param col       The zero indexed column number.
713  * @param formula   Formula string to write to cell.
714  * @param format    A pointer to a Format instance or NULL.
715  * @param result    A user defined result for a formula.
716  *
717  * @return A #lxw_error code.
718  *
719  * The `%worksheet_write_formula_num()` function writes a formula or Excel
720  * function to the cell specified by `row` and `column` with a user defined
721  * result:
722  *
723  * @code
724  *     // Required as a workaround only.
725  *     worksheet_write_formula_num(worksheet, 0, 0, "=1 + 2", NULL, 3);
726  * @endcode
727  *
728  * Libxlsxwriter doesn't calculate the value of a formula and instead stores
729  * the value `0` as the formula result. It then sets a global flag in the XLSX
730  * file to say that all formulas and functions should be recalculated when the
731  * file is opened.
732  *
733  * This is the method recommended in the Excel documentation and in general it
734  * works fine with spreadsheet applications.
735  *
736  * However, applications that don't have a facility to calculate formulas,
737  * such as Excel Viewer, or some mobile applications will only display the `0`
738  * results.
739  *
740  * If required, the `%worksheet_write_formula_num()` function can be used to
741  * specify a formula and its result.
742  *
743  * This function is rarely required and is only provided for compatibility
744  * with some third party applications. For most applications the
745  * worksheet_write_formula() function is the recommended way of writing
746  * formulas.
747  *
748  */
749 lxw_error worksheet_write_formula_num(lxw_worksheet *worksheet,
750                                       lxw_row_t row,
751                                       lxw_col_t col,
752                                       const char *formula,
753                                       lxw_format *format, double result);
754 
755 /**
756  * @brief Set the properties for a row of cells.
757  *
758  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
759  * @param row       The zero indexed row number.
760  * @param height    The row height.
761  * @param format    A pointer to a Format instance or NULL.
762  *
763  * The `%worksheet_set_row()` function is used to change the default
764  * properties of a row. The most common use for this function is to change the
765  * height of a row:
766  *
767  * @code
768  *     // Set the height of Row 1 to 20.
769  *     worksheet_set_row(worksheet, 0, 20, NULL);
770  * @endcode
771  *
772  * The other common use for `%worksheet_set_row()` is to set the a @ref
773  * format.h "Format" for all cells in the row:
774  *
775  * @code
776  *     lxw_format *bold = workbook_add_format(workbook);
777  *     format_set_bold(bold);
778  *
779  *     // Set the header row to bold.
780  *     worksheet_set_row(worksheet, 0, 15, bold);
781  * @endcode
782  *
783  * If you wish to set the format of a row without changing the height you can
784  * pass the default row height of #LXW_DEF_ROW_HEIGHT = 15:
785  *
786  * @code
787  *     worksheet_set_row(worksheet, 0, LXW_DEF_ROW_HEIGHT, format);
788  *     worksheet_set_row(worksheet, 0, 15, format); // Same as above.
789  * @endcode
790  *
791  * The `format` parameter will be applied to any cells in the row that don't
792  * have a format. As with Excel the row format is overridden by an explicit
793  * cell format. For example:
794  *
795  * @code
796  *     // Row 1 has format1.
797  *     worksheet_set_row(worksheet, 0, 15, format1);
798  *
799  *     // Cell A1 in Row 1 defaults to format1.
800  *     worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
801  *
802  *     // Cell B1 in Row 1 keeps format2.
803  *     worksheet_write_string(worksheet, 0, 1, "Hello", format2);
804  * @endcode
805  *
806  */
807 lxw_error worksheet_set_row(lxw_worksheet *worksheet,
808                             lxw_row_t row, double height, lxw_format *format);
809 
810 /**
811  * @brief Set the properties for a row of cells.
812  *
813  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
814  * @param row       The zero indexed row number.
815  * @param height    The row height.
816  * @param format    A pointer to a Format instance or NULL.
817  * @param options   Optional row parameters: hidden, level, collapsed.
818  *
819  * The `%worksheet_set_row_opt()` function  is the same as
820  *  `worksheet_set_row()` with an additional `options` parameter.
821  *
822  * The `options` parameter is a #lxw_row_col_options struct. It has the
823  * following members but currently only the `hidden` property is supported:
824  *
825  * - `hidden`
826  * - `level`
827  * - `collapsed`
828  *
829  * The `"hidden"` option is used to hide a row. This can be used, for
830  * example, to hide intermediary steps in a complicated calculation:
831  *
832  * @code
833  *     lxw_row_col_options options = {.hidden = 1, .level = 0, .collapsed = 0};
834  *
835  *     // Hide the fourth row.
836  *     worksheet_set_row(worksheet, 3, 20, NULL, &options);
837  * @endcode
838  *
839  */
840 lxw_error worksheet_set_row_opt(lxw_worksheet *worksheet,
841                                 lxw_row_t row,
842                                 double height,
843                                 lxw_format *format,
844                                 lxw_row_col_options *options);
845 
846 /**
847  * @brief Set the properties for one or more columns of cells.
848  *
849  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
850  * @param first_col The zero indexed first column.
851  * @param last_col  The zero indexed last column.
852  * @param width     The width of the column(s).
853  * @param format    A pointer to a Format instance or NULL.
854  *
855  * The `%worksheet_set_column()` function can be used to change the default
856  * properties of a single column or a range of columns:
857  *
858  * @code
859  *     // Width of columns B:D set to 30.
860  *     worksheet_set_column(worksheet, 1, 3, 30, NULL);
861  *
862  * @endcode
863  *
864  * If `%worksheet_set_column()` is applied to a single column the value of
865  * `first_col` and `last_col` should be the same:
866  *
867  * @code
868  *     // Width of column B set to 30.
869  *     worksheet_set_column(worksheet, 1, 1, 30, NULL);
870  *
871  * @endcode
872  *
873  * It is also possible, and generally clearer, to specify a column range using
874  * the form of `COLS()` macro:
875  *
876  * @code
877  *     worksheet_set_column(worksheet, 4, 4, 20, NULL);
878  *     worksheet_set_column(worksheet, 5, 8, 30, NULL);
879  *
880  *     // Same as the examples above but clearer.
881  *     worksheet_set_column(worksheet, COLS("E:E"), 20, NULL);
882  *     worksheet_set_column(worksheet, COLS("F:H"), 30, NULL);
883  *
884  * @endcode
885  *
886  * The `width` parameter sets the column width in the same units used by Excel
887  * which is: the number of characters in the default font. The default width
888  * is 8.43 in the default font of Calibri 11. The actual relationship between
889  * a string width and a column width in Excel is complex. See the
890  * [following explanation of column widths](https://support.microsoft.com/en-us/kb/214123)
891  * from the Microsoft support documentation for more details.
892  *
893  * There is no way to specify "AutoFit" for a column in the Excel file
894  * format. This feature is only available at runtime from within Excel. It is
895  * possible to simulate "AutoFit" in your application by tracking the maximum
896  * width of the data in the column as your write it and then adjusting the
897  * column width at the end.
898  *
899  * As usual the @ref format.h `format` parameter is optional. If you wish to
900  * set the format without changing the width you can pass a default column
901  * width of #LXW_DEF_COL_WIDTH = 8.43:
902  *
903  * @code
904  *     lxw_format *bold = workbook_add_format(workbook);
905  *     format_set_bold(bold);
906  *
907  *     // Set the first column to bold.
908  *     worksheet_set_column(worksheet, 0, 0, LXW_DEF_COL_HEIGHT, bold);
909  * @endcode
910  *
911  * The `format` parameter will be applied to any cells in the column that
912  * don't have a format. For example:
913  *
914  * @code
915  *     // Column 1 has format1.
916  *     worksheet_set_column(worksheet, COLS("A:A"), 8.43, format1);
917  *
918  *     // Cell A1 in column 1 defaults to format1.
919  *     worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
920  *
921  *     // Cell A2 in column 1 keeps format2.
922  *     worksheet_write_string(worksheet, 1, 0, "Hello", format2);
923  * @endcode
924  *
925  * As in Excel a row format takes precedence over a default column format:
926  *
927  * @code
928  *     // Row 1 has format1.
929  *     worksheet_set_row(worksheet, 0, 15, format1);
930  *
931  *     // Col 1 has format2.
932  *     worksheet_set_column(worksheet, COLS("A:A"), 8.43, format2);
933  *
934  *     // Cell A1 defaults to format1, the row format.
935  *     worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
936  *
937  *    // Cell A2 keeps format2, the column format.
938  *     worksheet_write_string(worksheet, 1, 0, "Hello", NULL);
939  * @endcode
940  */
941 lxw_error worksheet_set_column(lxw_worksheet *worksheet,
942                                lxw_col_t first_col,
943                                lxw_col_t last_col,
944                                double width, lxw_format *format);
945 
946  /**
947   * @brief Set the properties for one or more columns of cells with options.
948   *
949   * @param worksheet Pointer to a lxw_worksheet instance to be updated.
950   * @param first_col The zero indexed first column.
951   * @param last_col  The zero indexed last column.
952   * @param width     The width of the column(s).
953   * @param format    A pointer to a Format instance or NULL.
954   * @param options   Optional row parameters: hidden, level, collapsed.
955   *
956   * The `%worksheet_set_column_opt()` function  is the same as
957   * `worksheet_set_column()` with an additional `options` parameter.
958   *
959   * The `options` parameter is a #lxw_row_col_options struct. It has the
960   * following members but currently only the `hidden` property is supported:
961   *
962   * - `hidden`
963   * - `level`
964   * - `collapsed`
965   *
966   * The `"hidden"` option is used to hide a column. This can be used, for
967   * example, to hide intermediary steps in a complicated calculation:
968   *
969   * @code
970   *     lxw_row_col_options options = {.hidden = 1, .level = 0, .collapsed = 0};
971   *
972   *     worksheet_set_column_opt(worksheet, COLS("A:A"), 8.43, NULL, &options);
973   * @endcode
974   *
975   */
976 lxw_error worksheet_set_column_opt(lxw_worksheet *worksheet,
977                                    lxw_col_t first_col,
978                                    lxw_col_t last_col,
979                                    double width,
980                                    lxw_format *format,
981                                    lxw_row_col_options *options);
982 
983 /**
984  * @brief Insert an image in a worksheet cell.
985  *
986  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
987  * @param row       The zero indexed row number.
988  * @param col       The zero indexed column number.
989  * @param filename  The image filename, with path if required.
990  *
991  * @return A #lxw_error code.
992  *
993  * This function can be used to insert a image into a worksheet. The image can
994  * be in PNG, JPEG or BMP format:
995  *
996  * @code
997  *     worksheet_insert_image(worksheet, 2, 1, "logo.png");
998  * @endcode
999  *
1000  * @image html insert_image.png
1001  *
1002  * The `worksheet_insert_image_opt()` function takes additional optional
1003  * parameters to position and scale the image, see below.
1004  *
1005  * **Note**:
1006  * The scaling of a image may be affected if is crosses a row that has its
1007  * default height changed due to a font that is larger than the default font
1008  * size or that has text wrapping turned on. To avoid this you should
1009  * explicitly set the height of the row using `worksheet_set_row()` if it
1010  * crosses an inserted image.
1011  *
1012  * BMP images are only supported for backward compatibility. In general it is
1013  * best to avoid BMP images since they aren't compressed. If used, BMP images
1014  * must be 24 bit, true color, bitmaps.
1015  */
1016 lxw_error worksheet_insert_image(lxw_worksheet *worksheet,
1017                                  lxw_row_t row, lxw_col_t col,
1018                                  const char *filename);
1019 
1020 /**
1021  * @brief Insert an image in a worksheet cell, with options.
1022  *
1023  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1024  * @param row       The zero indexed row number.
1025  * @param col       The zero indexed column number.
1026  * @param filename  The image filename, with path if required.
1027  * @param options   Optional image parameters.
1028  *
1029  * @return A #lxw_error code.
1030  *
1031  * The `%worksheet_insert_image_opt()` function is like
1032  * `worksheet_insert_image()` function except that it takes an optional
1033  * #lxw_image_options struct to scale and position the image:
1034  *
1035  * @code
1036  *    lxw_image_options options = {.x_offset = 30,  .y_offset = 10,
1037  *                                 .x_scale  = 0.5, .y_scale  = 0.5};
1038  *
1039  *    worksheet_insert_image_opt(worksheet, 2, 1, "logo.png", &options);
1040  *
1041  * @endcode
1042  *
1043  * @image html insert_image_opt.png
1044  *
1045  * @note See the notes about row scaling and BMP images in
1046  * `worksheet_insert_image()` above.
1047  */
1048 lxw_error worksheet_insert_image_opt(lxw_worksheet *worksheet,
1049                                      lxw_row_t row, lxw_col_t col,
1050                                      const char *filename,
1051                                      lxw_image_options *options);
1052 /**
1053  * @brief Insert a chart object into a worksheet.
1054  *
1055  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1056  * @param row       The zero indexed row number.
1057  * @param col       The zero indexed column number.
1058  * @param chart     A #lxw_chart object created via workbook_add_chart().
1059  *
1060  * @return A #lxw_error code.
1061  *
1062  * The `%worksheet_insert_chart()` can be used to insert a chart into a
1063  * worksheet. The chart object must be created first using the
1064  * `workbook_add_chart()` function and configured using the @ref chart.h
1065  * functions.
1066  *
1067  * @code
1068  *     // Create a chart object.
1069  *     lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
1070  *
1071  *     // Add a data series to the chart.
1072  *     chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$6");
1073  *
1074  *     // Insert the chart into the worksheet
1075  *     worksheet_insert_chart(worksheet, 0, 2, chart);
1076  * @endcode
1077  *
1078  * @image html chart_working.png
1079  *
1080  *
1081  * **Note:**
1082  *
1083  * A chart may only be inserted into a worksheet once. If several similar
1084  * charts are required then each one must be created separately with
1085  * `%worksheet_insert_chart()`.
1086  *
1087  */
1088 lxw_error worksheet_insert_chart(lxw_worksheet *worksheet,
1089                                  lxw_row_t row, lxw_col_t col,
1090                                  lxw_chart *chart);
1091 
1092 /**
1093  * @brief Insert a chart object into a worksheet, with options.
1094  *
1095  * @param worksheet    Pointer to a lxw_worksheet instance to be updated.
1096  * @param row          The zero indexed row number.
1097  * @param col          The zero indexed column number.
1098  * @param chart        A #lxw_chart object created via workbook_add_chart().
1099  * @param user_options Optional chart parameters.
1100  *
1101  * @return A #lxw_error code.
1102  *
1103  * The `%worksheet_insert_chart_opt()` function is like
1104  * `worksheet_insert_chart()` function except that it takes an optional
1105  * #lxw_image_options struct to scale and position the image of the chart:
1106  *
1107  * @code
1108  *    lxw_image_options options = {.x_offset = 30,  .y_offset = 10,
1109  *                                 .x_scale  = 0.5, .y_scale  = 0.75};
1110  *
1111  *    worksheet_insert_chart_opt(worksheet, 0, 2, chart, &options);
1112  *
1113  * @endcode
1114  *
1115  * @image html chart_line_opt.png
1116  *
1117  * The #lxw_image_options struct is the same struct used in
1118  * `worksheet_insert_image_opt()` to position and scale images.
1119  *
1120  */
1121 lxw_error worksheet_insert_chart_opt(lxw_worksheet *worksheet,
1122                                      lxw_row_t row, lxw_col_t col,
1123                                      lxw_chart *chart,
1124                                      lxw_image_options *user_options);
1125 
1126 /**
1127  * @brief Merge a range of cells.
1128  *
1129  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1130  * @param first_row The first row of the range. (All zero indexed.)
1131  * @param first_col The first column of the range.
1132  * @param last_row  The last row of the range.
1133  * @param last_col  The last col of the range.
1134  * @param string    String to write to the merged range.
1135  * @param format    A pointer to a Format instance or NULL.
1136  *
1137  * @return A #lxw_error code.
1138  *
1139  * The `%worksheet_merge_range()` function allows cells to be merged together
1140  * so that they act as a single area.
1141  *
1142  * Excel generally merges and centers cells at same time. To get similar
1143  * behavior with libxlsxwriter you need to apply a @ref format.h "Format"
1144  * object with the appropriate alignment:
1145  *
1146  * @code
1147  *     lxw_format *merge_format = workbook_add_format(workbook);
1148  *     format_set_align(merge_format, LXW_ALIGN_CENTER);
1149  *
1150  *     worksheet_merge_range(worksheet, 1, 1, 1, 3, "Merged Range", merge_format);
1151  *
1152  * @endcode
1153  *
1154  * It is possible to apply other formatting to the merged cells as well:
1155  *
1156  * @code
1157  *    format_set_align   (merge_format, LXW_ALIGN_CENTER);
1158  *    format_set_align   (merge_format, LXW_ALIGN_VERTICAL_CENTER);
1159  *    format_set_border  (merge_format, LXW_BORDER_DOUBLE);
1160  *    format_set_bold    (merge_format);
1161  *    format_set_bg_color(merge_format, 0xD7E4BC);
1162  *
1163  *    worksheet_merge_range(worksheet, 2, 1, 3, 3, "Merged Range", merge_format);
1164  *
1165  * @endcode
1166  *
1167  * @image html merge.png
1168  *
1169  * The `%worksheet_merge_range()` function writes a `char*` string using
1170  * `worksheet_write_string()`. In order to write other data types, such as a
1171  * number or a formula, you can overwrite the first cell with a call to one of
1172  * the other write functions. The same Format should be used as was used in
1173  * the merged range.
1174  *
1175  * @code
1176  *    // First write a range with a blank string.
1177  *    worksheet_merge_range (worksheet, 1, 1, 1, 3, "", format);
1178  *
1179  *    // Then overwrite the first cell with a number.
1180  *    worksheet_write_number(worksheet, 1, 1, 123, format);
1181  * @endcode
1182  *
1183  * @note Merged ranges generally don’t work in libxlsxwriter when the Workbook
1184  * #lxw_workbook_options `constant_memory` mode is enabled.
1185  */
1186 lxw_error worksheet_merge_range(lxw_worksheet *worksheet, lxw_row_t first_row,
1187                                 lxw_col_t first_col, lxw_row_t last_row,
1188                                 lxw_col_t last_col, const char *string,
1189                                 lxw_format *format);
1190 
1191 /**
1192  * @brief Set the autofilter area in the worksheet.
1193  *
1194  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1195  * @param first_row The first row of the range. (All zero indexed.)
1196  * @param first_col The first column of the range.
1197  * @param last_row  The last row of the range.
1198  * @param last_col  The last col of the range.
1199  *
1200  * @return A #lxw_error code.
1201  *
1202  * The `%worksheet_autofilter()` function allows an autofilter to be added to
1203  * a worksheet.
1204  *
1205  * An autofilter is a way of adding drop down lists to the headers of a 2D
1206  * range of worksheet data. This allows users to filter the data based on
1207  * simple criteria so that some data is shown and some is hidden.
1208  *
1209  * @image html autofilter.png
1210  *
1211  * To add an autofilter to a worksheet:
1212  *
1213  * @code
1214  *     worksheet_autofilter(worksheet, 0, 0, 50, 3);
1215  *
1216  *     // Same as above using the RANGE() macro.
1217  *     worksheet_autofilter(worksheet, RANGE("A1:D51"));
1218  * @endcode
1219  *
1220  * Note: it isn't currently possible to apply filter conditions to the
1221  * autofilter.
1222  */
1223 lxw_error worksheet_autofilter(lxw_worksheet *worksheet, lxw_row_t first_row,
1224                                lxw_col_t first_col, lxw_row_t last_row,
1225                                lxw_col_t last_col);
1226 
1227  /**
1228   * @brief Make a worksheet the active, i.e., visible worksheet.
1229   *
1230   * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1231   *
1232   * The `%worksheet_activate()` function is used to specify which worksheet is
1233   * initially visible in a multi-sheet workbook:
1234   *
1235   * @code
1236   *     lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
1237   *     lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
1238   *     lxw_worksheet *worksheet3 = workbook_add_worksheet(workbook, NULL);
1239   *
1240   *     worksheet_activate(worksheet3);
1241   * @endcode
1242   *
1243   * @image html worksheet_activate.png
1244   *
1245   * More than one worksheet can be selected via the `worksheet_select()`
1246   * function, see below, however only one worksheet can be active.
1247   *
1248   * The default active worksheet is the first worksheet.
1249   *
1250   */
1251 void worksheet_activate(lxw_worksheet *worksheet);
1252 
1253  /**
1254   * @brief Set a worksheet tab as selected.
1255   *
1256   * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1257   *
1258   * The `%worksheet_select()` function is used to indicate that a worksheet is
1259   * selected in a multi-sheet workbook:
1260   *
1261   * @code
1262   *     worksheet_activate(worksheet1);
1263   *     worksheet_select(worksheet2);
1264   *     worksheet_select(worksheet3);
1265   *
1266   * @endcode
1267   *
1268   * A selected worksheet has its tab highlighted. Selecting worksheets is a
1269   * way of grouping them together so that, for example, several worksheets
1270   * could be printed in one go. A worksheet that has been activated via the
1271   * `worksheet_activate()` function will also appear as selected.
1272   *
1273   */
1274 void worksheet_select(lxw_worksheet *worksheet);
1275 
1276 /**
1277  * @brief Hide the current worksheet.
1278  *
1279  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1280  *
1281  * The `%worksheet_hide()` function is used to hide a worksheet:
1282  *
1283  * @code
1284  *     worksheet_hide(worksheet2);
1285  * @endcode
1286  *
1287  * You may wish to hide a worksheet in order to avoid confusing a user with
1288  * intermediate data or calculations.
1289  *
1290  * @image html hide_sheet.png
1291  *
1292  * A hidden worksheet can not be activated or selected so this function is
1293  * mutually exclusive with the `worksheet_activate()` and `worksheet_select()`
1294  * functions. In addition, since the first worksheet will default to being the
1295  * active worksheet, you cannot hide the first worksheet without activating
1296  * another sheet:
1297  *
1298  * @code
1299  *     worksheet_activate(worksheet2);
1300  *     worksheet_hide(worksheet1);
1301  * @endcode
1302  */
1303 void worksheet_hide(lxw_worksheet *worksheet);
1304 
1305 /**
1306  * @brief Set current worksheet as the first visible sheet tab.
1307  *
1308  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1309  *
1310  * The `worksheet_activate()` function determines which worksheet is initially
1311  * selected.  However, if there are a large number of worksheets the selected
1312  * worksheet may not appear on the screen. To avoid this you can select the
1313  * leftmost visible worksheet tab using `%worksheet_set_first_sheet()`:
1314  *
1315  * @code
1316  *     worksheet_set_first_sheet(worksheet19); // First visible worksheet tab.
1317  *     worksheet_activate(worksheet20);        // First visible worksheet.
1318  * @endcode
1319  *
1320  * This function is not required very often. The default value is the first
1321  * worksheet.
1322  */
1323 void worksheet_set_first_sheet(lxw_worksheet *worksheet);
1324 
1325 /**
1326  * @brief Split and freeze a worksheet into panes.
1327  *
1328  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1329  * @param row       The cell row (zero indexed).
1330  * @param col       The cell column (zero indexed).
1331  *
1332  * The `%worksheet_freeze_panes()` function can be used to divide a worksheet
1333  * into horizontal or vertical regions known as panes and to "freeze" these
1334  * panes so that the splitter bars are not visible.
1335  *
1336  * The parameters `row` and `col` are used to specify the location of the
1337  * split. It should be noted that the split is specified at the top or left of
1338  * a cell and that the function uses zero based indexing. Therefore to freeze
1339  * the first row of a worksheet it is necessary to specify the split at row 2
1340  * (which is 1 as the zero-based index).
1341  *
1342  * You can set one of the `row` and `col` parameters as zero if you do not
1343  * want either a vertical or horizontal split.
1344  *
1345  * Examples:
1346  *
1347  * @code
1348  *     worksheet_freeze_panes(worksheet1, 1, 0); // Freeze the first row.
1349  *     worksheet_freeze_panes(worksheet2, 0, 1); // Freeze the first column.
1350  *     worksheet_freeze_panes(worksheet3, 1, 1); // Freeze first row/column.
1351  *
1352  * @endcode
1353  *
1354  */
1355 void worksheet_freeze_panes(lxw_worksheet *worksheet,
1356                             lxw_row_t row, lxw_col_t col);
1357 /**
1358  * @brief Split a worksheet into panes.
1359  *
1360  * @param worksheet  Pointer to a lxw_worksheet instance to be updated.
1361  * @param vertical   The position for the vertical split.
1362  * @param horizontal The position for the horizontal split.
1363  *
1364  * The `%worksheet_split_panes()` function can be used to divide a worksheet
1365  * into horizontal or vertical regions known as panes. This function is
1366  * different from the `worksheet_freeze_panes()` function in that the splits
1367  * between the panes will be visible to the user and each pane will have its
1368  * own scroll bars.
1369  *
1370  * The parameters `vertical` and `horizontal` are used to specify the vertical
1371  * and horizontal position of the split. The units for `vertical` and
1372  * `horizontal` are the same as those used by Excel to specify row height and
1373  * column width. However, the vertical and horizontal units are different from
1374  * each other. Therefore you must specify the `vertical` and `horizontal`
1375  * parameters in terms of the row heights and column widths that you have set
1376  * or the default values which are 15 for a row and 8.43 for a column.
1377  *
1378  * Examples:
1379  *
1380  * @code
1381  *     worksheet_split_panes(worksheet1, 15, 0);    // First row.
1382  *     worksheet_split_panes(worksheet2, 0,  8.43); // First column.
1383  *     worksheet_split_panes(worksheet3, 15, 8.43); // First row and column.
1384  *
1385  * @endcode
1386  *
1387  */
1388 void worksheet_split_panes(lxw_worksheet *worksheet,
1389                            double vertical, double horizontal);
1390 
1391 /* worksheet_freeze_panes() with infrequent options. Undocumented for now. */
1392 void worksheet_freeze_panes_opt(lxw_worksheet *worksheet,
1393                                 lxw_row_t first_row, lxw_col_t first_col,
1394                                 lxw_row_t top_row, lxw_col_t left_col,
1395                                 uint8_t type);
1396 
1397 /* worksheet_split_panes() with infrequent options. Undocumented for now. */
1398 void worksheet_split_panes_opt(lxw_worksheet *worksheet,
1399                                double vertical, double horizontal,
1400                                lxw_row_t top_row, lxw_col_t left_col);
1401 /**
1402  * @brief Set the selected cell or cells in a worksheet:
1403  *
1404  * @param worksheet   Pointer to a lxw_worksheet instance to be updated.
1405  * @param first_row   The first row of the range. (All zero indexed.)
1406  * @param first_col   The first column of the range.
1407  * @param last_row    The last row of the range.
1408  * @param last_col    The last col of the range.
1409  *
1410  *
1411  * The `%worksheet_set_selection()` function can be used to specify which cell
1412  * or range of cells is selected in a worksheet: The most common requirement
1413  * is to select a single cell, in which case the `first_` and `last_`
1414  * parameters should be the same.
1415  *
1416  * The active cell within a selected range is determined by the order in which
1417  * `first_` and `last_` are specified.
1418  *
1419  * Examples:
1420  *
1421  * @code
1422  *     worksheet_set_selection(worksheet1, 3, 3, 3, 3);     // Cell D4.
1423  *     worksheet_set_selection(worksheet2, 3, 3, 6, 6);     // Cells D4 to G7.
1424  *     worksheet_set_selection(worksheet3, 6, 6, 3, 3);     // Cells G7 to D4.
1425  *     worksheet_set_selection(worksheet5, RANGE("D4:G7")); // Using the RANGE macro.
1426  *
1427  * @endcode
1428  *
1429  */
1430 void worksheet_set_selection(lxw_worksheet *worksheet,
1431                              lxw_row_t first_row, lxw_col_t first_col,
1432                              lxw_row_t last_row, lxw_col_t last_col);
1433 
1434 /**
1435  * @brief Set the page orientation as landscape.
1436  *
1437  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1438  *
1439  * This function is used to set the orientation of a worksheet's printed page
1440  * to landscape:
1441  *
1442  * @code
1443  *     worksheet_set_landscape(worksheet);
1444  * @endcode
1445  */
1446 void worksheet_set_landscape(lxw_worksheet *worksheet);
1447 
1448 /**
1449  * @brief Set the page orientation as portrait.
1450  *
1451  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1452  *
1453  * This function is used to set the orientation of a worksheet's printed page
1454  * to portrait. The default worksheet orientation is portrait, so this
1455  * function isn't generally required:
1456  *
1457  * @code
1458  *     worksheet_set_portrait(worksheet);
1459  * @endcode
1460  */
1461 void worksheet_set_portrait(lxw_worksheet *worksheet);
1462 
1463 /**
1464  * @brief Set the page layout to page view mode.
1465  *
1466  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1467  *
1468  * This function is used to display the worksheet in "Page View/Layout" mode:
1469  *
1470  * @code
1471  *     worksheet_set_page_view(worksheet);
1472  * @endcode
1473  */
1474 void worksheet_set_page_view(lxw_worksheet *worksheet);
1475 
1476 /**
1477  * @brief Set the paper type for printing.
1478  *
1479  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1480  * @param paper_type The Excel paper format type.
1481  *
1482  * This function is used to set the paper format for the printed output of a
1483  * worksheet. The following paper styles are available:
1484  *
1485  *
1486  *   Index    | Paper format            | Paper size
1487  *   :------- | :---------------------- | :-------------------
1488  *   0        | Printer default         | Printer default
1489  *   1        | Letter                  | 8 1/2 x 11 in
1490  *   2        | Letter Small            | 8 1/2 x 11 in
1491  *   3        | Tabloid                 | 11 x 17 in
1492  *   4        | Ledger                  | 17 x 11 in
1493  *   5        | Legal                   | 8 1/2 x 14 in
1494  *   6        | Statement               | 5 1/2 x 8 1/2 in
1495  *   7        | Executive               | 7 1/4 x 10 1/2 in
1496  *   8        | A3                      | 297 x 420 mm
1497  *   9        | A4                      | 210 x 297 mm
1498  *   10       | A4 Small                | 210 x 297 mm
1499  *   11       | A5                      | 148 x 210 mm
1500  *   12       | B4                      | 250 x 354 mm
1501  *   13       | B5                      | 182 x 257 mm
1502  *   14       | Folio                   | 8 1/2 x 13 in
1503  *   15       | Quarto                  | 215 x 275 mm
1504  *   16       | ---                     | 10x14 in
1505  *   17       | ---                     | 11x17 in
1506  *   18       | Note                    | 8 1/2 x 11 in
1507  *   19       | Envelope 9              | 3 7/8 x 8 7/8
1508  *   20       | Envelope 10             | 4 1/8 x 9 1/2
1509  *   21       | Envelope 11             | 4 1/2 x 10 3/8
1510  *   22       | Envelope 12             | 4 3/4 x 11
1511  *   23       | Envelope 14             | 5 x 11 1/2
1512  *   24       | C size sheet            | ---
1513  *   25       | D size sheet            | ---
1514  *   26       | E size sheet            | ---
1515  *   27       | Envelope DL             | 110 x 220 mm
1516  *   28       | Envelope C3             | 324 x 458 mm
1517  *   29       | Envelope C4             | 229 x 324 mm
1518  *   30       | Envelope C5             | 162 x 229 mm
1519  *   31       | Envelope C6             | 114 x 162 mm
1520  *   32       | Envelope C65            | 114 x 229 mm
1521  *   33       | Envelope B4             | 250 x 353 mm
1522  *   34       | Envelope B5             | 176 x 250 mm
1523  *   35       | Envelope B6             | 176 x 125 mm
1524  *   36       | Envelope                | 110 x 230 mm
1525  *   37       | Monarch                 | 3.875 x 7.5 in
1526  *   38       | Envelope                | 3 5/8 x 6 1/2 in
1527  *   39       | Fanfold                 | 14 7/8 x 11 in
1528  *   40       | German Std Fanfold      | 8 1/2 x 12 in
1529  *   41       | German Legal Fanfold    | 8 1/2 x 13 in
1530  *
1531  * Note, it is likely that not all of these paper types will be available to
1532  * the end user since it will depend on the paper formats that the user's
1533  * printer supports. Therefore, it is best to stick to standard paper types:
1534  *
1535  * @code
1536  *     worksheet_set_paper(worksheet1, 1);  // US Letter
1537  *     worksheet_set_paper(worksheet2, 9);  // A4
1538  * @endcode
1539  *
1540  * If you do not specify a paper type the worksheet will print using the
1541  * printer's default paper style.
1542  */
1543 void worksheet_set_paper(lxw_worksheet *worksheet, uint8_t paper_type);
1544 
1545 /**
1546  * @brief Set the worksheet margins for the printed page.
1547  *
1548  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1549  * @param left    Left margin in inches.   Excel default is 0.7.
1550  * @param right   Right margin in inches.  Excel default is 0.7.
1551  * @param top     Top margin in inches.    Excel default is 0.75.
1552  * @param bottom  Bottom margin in inches. Excel default is 0.75.
1553  *
1554  * The `%worksheet_set_margins()` function is used to set the margins of the
1555  * worksheet when it is printed. The units are in inches. Specifying `-1` for
1556  * any parameter will give the default Excel value as shown above.
1557  *
1558  * @code
1559  *    worksheet_set_margins(worksheet, 1.3, 1.2, -1, -1);
1560  * @endcode
1561  *
1562  */
1563 void worksheet_set_margins(lxw_worksheet *worksheet, double left,
1564                            double right, double top, double bottom);
1565 
1566 /**
1567  * @brief Set the printed page header caption.
1568  *
1569  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1570  * @param string    The header string.
1571  *
1572  * @return A #lxw_error code.
1573  *
1574  * Headers and footers are generated using a string which is a combination of
1575  * plain text and control characters.
1576  *
1577  * The available control character are:
1578  *
1579  *
1580  *   | Control         | Category      | Description           |
1581  *   | --------------- | ------------- | --------------------- |
1582  *   | `&L`            | Justification | Left                  |
1583  *   | `&C`            |               | Center                |
1584  *   | `&R`            |               | Right                 |
1585  *   | `&P`            | Information   | Page number           |
1586  *   | `&N`            |               | Total number of pages |
1587  *   | `&D`            |               | Date                  |
1588  *   | `&T`            |               | Time                  |
1589  *   | `&F`            |               | File name             |
1590  *   | `&A`            |               | Worksheet name        |
1591  *   | `&Z`            |               | Workbook path         |
1592  *   | `&fontsize`     | Font          | Font size             |
1593  *   | `&"font,style"` |               | Font name and style   |
1594  *   | `&U`            |               | Single underline      |
1595  *   | `&E`            |               | Double underline      |
1596  *   | `&S`            |               | Strikethrough         |
1597  *   | `&X`            |               | Superscript           |
1598  *   | `&Y`            |               | Subscript             |
1599  *
1600  *
1601  * Text in headers and footers can be justified (aligned) to the left, center
1602  * and right by prefixing the text with the control characters `&L`, `&C` and
1603  * `&R`.
1604  *
1605  * For example (with ASCII art representation of the results):
1606  *
1607  * @code
1608  *     worksheet_set_header(worksheet, "&LHello");
1609  *
1610  *      ---------------------------------------------------------------
1611  *     |                                                               |
1612  *     | Hello                                                         |
1613  *     |                                                               |
1614  *
1615  *
1616  *     worksheet_set_header(worksheet, "&CHello");
1617  *
1618  *      ---------------------------------------------------------------
1619  *     |                                                               |
1620  *     |                          Hello                                |
1621  *     |                                                               |
1622  *
1623  *
1624  *     worksheet_set_header(worksheet, "&RHello");
1625  *
1626  *      ---------------------------------------------------------------
1627  *     |                                                               |
1628  *     |                                                         Hello |
1629  *     |                                                               |
1630  *
1631  *
1632  * @endcode
1633  *
1634  * For simple text, if you do not specify any justification the text will be
1635  * centered. However, you must prefix the text with `&C` if you specify a font
1636  * name or any other formatting:
1637  *
1638  * @code
1639  *     worksheet_set_header(worksheet, "Hello");
1640  *
1641  *      ---------------------------------------------------------------
1642  *     |                                                               |
1643  *     |                          Hello                                |
1644  *     |                                                               |
1645  *
1646  * @endcode
1647  *
1648  * You can have text in each of the justification regions:
1649  *
1650  * @code
1651  *     worksheet_set_header(worksheet, "&LCiao&CBello&RCielo");
1652  *
1653  *      ---------------------------------------------------------------
1654  *     |                                                               |
1655  *     | Ciao                     Bello                          Cielo |
1656  *     |                                                               |
1657  *
1658  * @endcode
1659  *
1660  * The information control characters act as variables that Excel will update
1661  * as the workbook or worksheet changes. Times and dates are in the users
1662  * default format:
1663  *
1664  * @code
1665  *     worksheet_set_header(worksheet, "&CPage &P of &N");
1666  *
1667  *      ---------------------------------------------------------------
1668  *     |                                                               |
1669  *     |                        Page 1 of 6                            |
1670  *     |                                                               |
1671  *
1672  *     worksheet_set_header(worksheet, "&CUpdated at &T");
1673  *
1674  *      ---------------------------------------------------------------
1675  *     |                                                               |
1676  *     |                    Updated at 12:30 PM                        |
1677  *     |                                                               |
1678  *
1679  * @endcode
1680  *
1681  * You can specify the font size of a section of the text by prefixing it with
1682  * the control character `&n` where `n` is the font size:
1683  *
1684  * @code
1685  *     worksheet_set_header(worksheet1, "&C&30Hello Big");
1686  *     worksheet_set_header(worksheet2, "&C&10Hello Small");
1687  *
1688  * @endcode
1689  *
1690  * You can specify the font of a section of the text by prefixing it with the
1691  * control sequence `&"font,style"` where `fontname` is a font name such as
1692  * Windows font descriptions: "Regular", "Italic", "Bold" or "Bold Italic":
1693  * "Courier New" or "Times New Roman" and `style` is one of the standard
1694  *
1695  * @code
1696  *     worksheet_set_header(worksheet1, "&C&\"Courier New,Italic\"Hello");
1697  *     worksheet_set_header(worksheet2, "&C&\"Courier New,Bold Italic\"Hello");
1698  *     worksheet_set_header(worksheet3, "&C&\"Times New Roman,Regular\"Hello");
1699  *
1700  * @endcode
1701  *
1702  * It is possible to combine all of these features together to create
1703  * sophisticated headers and footers. As an aid to setting up complicated
1704  * headers and footers you can record a page set-up as a macro in Excel and
1705  * look at the format strings that VBA produces. Remember however that VBA
1706  * uses two double quotes `""` to indicate a single double quote. For the last
1707  * example above the equivalent VBA code looks like this:
1708  *
1709  * @code
1710  *     .LeftHeader = ""
1711  *     .CenterHeader = "&""Times New Roman,Regular""Hello"
1712  *     .RightHeader = ""
1713  *
1714  * @endcode
1715  *
1716  * Alternatively you can inspect the header and footer strings in an Excel
1717  * file by unzipping it and grepping the XML sub-files. The following shows
1718  * how to do that using libxml's xmllint to format the XML for clarity:
1719  *
1720  * @code
1721  *
1722  *    $ unzip myfile.xlsm -d myfile
1723  *    $ xmllint --format `find myfile -name "*.xml" | xargs` | egrep "Header|Footer"
1724  *
1725  *      <headerFooter scaleWithDoc="0">
1726  *        <oddHeader>&amp;L&amp;P</oddHeader>
1727  *      </headerFooter>
1728  *
1729  * @endcode
1730  *
1731  * Note that in this case you need to unescape the Html. In the above example
1732  * the header string would be `&L&P`.
1733  *
1734  * To include a single literal ampersand `&` in a header or footer you should
1735  * use a double ampersand `&&`:
1736  *
1737  * @code
1738  *     worksheet_set_header(worksheet, "&CCuriouser && Curiouser - Attorneys at Law");
1739  * @endcode
1740  *
1741  * Note, the header or footer string must be less than 255 characters. Strings
1742  * longer than this will not be written.
1743  *
1744  */
1745 lxw_error worksheet_set_header(lxw_worksheet *worksheet, const char *string);
1746 
1747 /**
1748  * @brief Set the printed page footer caption.
1749  *
1750  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1751  * @param string    The footer string.
1752  *
1753  * @return A #lxw_error code.
1754  *
1755  * The syntax of this function is the same as worksheet_set_header().
1756  *
1757  */
1758 lxw_error worksheet_set_footer(lxw_worksheet *worksheet, const char *string);
1759 
1760 /**
1761  * @brief Set the printed page header caption with additional options.
1762  *
1763  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1764  * @param string    The header string.
1765  * @param options   Header options.
1766  *
1767  * @return A #lxw_error code.
1768  *
1769  * The syntax of this function is the same as worksheet_set_header() with an
1770  * additional parameter to specify options for the header.
1771  *
1772  * Currently, the only available option is the header margin:
1773  *
1774  * @code
1775  *
1776  *    lxw_header_footer_options header_options = { 0.2 };
1777  *
1778  *    worksheet_set_header_opt(worksheet, "Some text", &header_options);
1779  *
1780  * @endcode
1781  *
1782  */
1783 lxw_error worksheet_set_header_opt(lxw_worksheet *worksheet,
1784                                    const char *string,
1785                                    lxw_header_footer_options *options);
1786 
1787 /**
1788  * @brief Set the printed page footer caption with additional options.
1789  *
1790  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1791  * @param string    The footer string.
1792  * @param options   Footer options.
1793  *
1794  * @return A #lxw_error code.
1795  *
1796  * The syntax of this function is the same as worksheet_set_header_opt().
1797  *
1798  */
1799 lxw_error worksheet_set_footer_opt(lxw_worksheet *worksheet,
1800                                    const char *string,
1801                                    lxw_header_footer_options *options);
1802 
1803 /**
1804  * @brief Set the horizontal page breaks on a worksheet.
1805  *
1806  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1807  * @param breaks    Array of page breaks.
1808  *
1809  * @return A #lxw_error code.
1810  *
1811  * The `%worksheet_set_h_pagebreaks()` function adds horizontal page breaks to
1812  * a worksheet. A page break causes all the data that follows it to be printed
1813  * on the next page. Horizontal page breaks act between rows.
1814  *
1815  * The function takes an array of one or more page breaks. The type of the
1816  * array data is @ref lxw_row_t and the last element of the array must be 0:
1817  *
1818  * @code
1819  *    lxw_row_t breaks1[] = {20, 0}; // 1 page break. Zero indicates the end.
1820  *    lxw_row_t breaks2[] = {20, 40, 60, 80, 0};
1821  *
1822  *    worksheet_set_h_pagebreaks(worksheet1, breaks1);
1823  *    worksheet_set_h_pagebreaks(worksheet2, breaks2);
1824  * @endcode
1825  *
1826  * To create a page break between rows 20 and 21 you must specify the break at
1827  * row 21. However in zero index notation this is actually row 20:
1828  *
1829  * @code
1830  *    // Break between row 20 and 21.
1831  *    lxw_row_t breaks[] = {20, 0};
1832  *
1833  *    worksheet_set_h_pagebreaks(worksheet, breaks);
1834  * @endcode
1835  *
1836  * There is an Excel limitation of 1023 horizontal page breaks per worksheet.
1837  *
1838  * Note: If you specify the "fit to page" option via the
1839  * `worksheet_fit_to_pages()` function it will override all manual page
1840  * breaks.
1841  *
1842  */
1843 lxw_error worksheet_set_h_pagebreaks(lxw_worksheet *worksheet,
1844                                      lxw_row_t[] breaks);
1845 
1846 /**
1847  * @brief Set the vertical page breaks on a worksheet.
1848  *
1849  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1850  * @param breaks    Array of page breaks.
1851  *
1852  * @return A #lxw_error code.
1853  *
1854  * The `%worksheet_set_v_pagebreaks()` function adds vertical page breaks to a
1855  * worksheet. A page break causes all the data that follows it to be printed
1856  * on the next page. Vertical page breaks act between columns.
1857  *
1858  * The function takes an array of one or more page breaks. The type of the
1859  * array data is @ref lxw_col_t and the last element of the array must be 0:
1860  *
1861  * @code
1862  *    lxw_col_t breaks1[] = {20, 0}; // 1 page break. Zero indicates the end.
1863  *    lxw_col_t breaks2[] = {20, 40, 60, 80, 0};
1864  *
1865  *    worksheet_set_v_pagebreaks(worksheet1, breaks1);
1866  *    worksheet_set_v_pagebreaks(worksheet2, breaks2);
1867  * @endcode
1868  *
1869  * To create a page break between columns 20 and 21 you must specify the break
1870  * at column 21. However in zero index notation this is actually column 20:
1871  *
1872  * @code
1873  *    // Break between column 20 and 21.
1874  *    lxw_col_t breaks[] = {20, 0};
1875  *
1876  *    worksheet_set_v_pagebreaks(worksheet, breaks);
1877  * @endcode
1878  *
1879  * There is an Excel limitation of 1023 vertical page breaks per worksheet.
1880  *
1881  * Note: If you specify the "fit to page" option via the
1882  * `worksheet_fit_to_pages()` function it will override all manual page
1883  * breaks.
1884  *
1885  */
1886 lxw_error worksheet_set_v_pagebreaks(lxw_worksheet *worksheet,
1887                                      lxw_col_t[] breaks);
1888 
1889 /**
1890  * @brief Set the order in which pages are printed.
1891  *
1892  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1893  *
1894  * The `%worksheet_print_across()` function is used to change the default
1895  * print direction. This is referred to by Excel as the sheet "page order":
1896  *
1897  * @code
1898  *     worksheet_print_across(worksheet);
1899  * @endcode
1900  *
1901  * The default page order is shown below for a worksheet that extends over 4
1902  * pages. The order is called "down then across":
1903  *
1904  *     [1] [3]
1905  *     [2] [4]
1906  *
1907  * However, by using the `print_across` function the print order will be
1908  * changed to "across then down":
1909  *
1910  *     [1] [2]
1911  *     [3] [4]
1912  *
1913  */
1914 void worksheet_print_across(lxw_worksheet *worksheet);
1915 
1916 /**
1917  * @brief Set the worksheet zoom factor.
1918  *
1919  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1920  * @param scale     Worksheet zoom factor.
1921  *
1922  * Set the worksheet zoom factor in the range `10 <= zoom <= 400`:
1923  *
1924  * @code
1925  *     worksheet_set_zoom(worksheet1, 50);
1926  *     worksheet_set_zoom(worksheet2, 75);
1927  *     worksheet_set_zoom(worksheet3, 300);
1928  *     worksheet_set_zoom(worksheet4, 400);
1929  * @endcode
1930  *
1931  * The default zoom factor is 100. It isn't possible to set the zoom to
1932  * "Selection" because it is calculated by Excel at run-time.
1933  *
1934  * Note, `%worksheet_zoom()` does not affect the scale of the printed
1935  * page. For that you should use `worksheet_set_print_scale()`.
1936  */
1937 void worksheet_set_zoom(lxw_worksheet *worksheet, uint16_t scale);
1938 
1939 /**
1940  * @brief Set the option to display or hide gridlines on the screen and
1941  *        the printed page.
1942  *
1943  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1944  * @param option    Gridline option.
1945  *
1946  * Display or hide screen and print gridlines using one of the values of
1947  * @ref lxw_gridlines.
1948  *
1949  * @code
1950  *    worksheet_gridlines(worksheet1, LXW_HIDE_ALL_GRIDLINES);
1951  *
1952  *    worksheet_gridlines(worksheet2, LXW_SHOW_PRINT_GRIDLINES);
1953  * @endcode
1954  *
1955  * The Excel default is that the screen gridlines are on  and the printed
1956  * worksheet is off.
1957  *
1958  */
1959 void worksheet_gridlines(lxw_worksheet *worksheet, uint8_t option);
1960 
1961 /**
1962  * @brief Center the printed page horizontally.
1963  *
1964  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1965  *
1966  * Center the worksheet data horizontally between the margins on the printed
1967  * page:
1968  *
1969  * @code
1970  *     worksheet_center_horizontally(worksheet);
1971  * @endcode
1972  *
1973  */
1974 void worksheet_center_horizontally(lxw_worksheet *worksheet);
1975 
1976 /**
1977  * @brief Center the printed page vertically.
1978  *
1979  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1980  *
1981  * Center the worksheet data vertically between the margins on the printed
1982  * page:
1983  *
1984  * @code
1985  *     worksheet_center_vertically(worksheet);
1986  * @endcode
1987  *
1988  */
1989 void worksheet_center_vertically(lxw_worksheet *worksheet);
1990 
1991 /**
1992  * @brief Set the option to print the row and column headers on the printed
1993  *        page.
1994  *
1995  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
1996  *
1997  * When printing a worksheet from Excel the row and column headers (the row
1998  * numbers on the left and the column letters at the top) aren't printed by
1999  * default.
2000  *
2001  * This function sets the printer option to print these headers:
2002  *
2003  * @code
2004  *    worksheet_print_row_col_headers(worksheet);
2005  * @endcode
2006  *
2007  */
2008 void worksheet_print_row_col_headers(lxw_worksheet *worksheet);
2009 
2010 /**
2011  * @brief Set the number of rows to repeat at the top of each printed page.
2012  *
2013  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2014  * @param first_row First row of repeat range.
2015  * @param last_row  Last row of repeat range.
2016  *
2017  * @return A #lxw_error code.
2018  *
2019  * For large Excel documents it is often desirable to have the first row or
2020  * rows of the worksheet print out at the top of each page.
2021  *
2022  * This can be achieved by using this function. The parameters `first_row`
2023  * and `last_row` are zero based:
2024  *
2025  * @code
2026  *     worksheet_repeat_rows(worksheet, 0, 0); // Repeat the first row.
2027  *     worksheet_repeat_rows(worksheet, 0, 1); // Repeat the first two rows.
2028  * @endcode
2029  */
2030 lxw_error worksheet_repeat_rows(lxw_worksheet *worksheet, lxw_row_t first_row,
2031                                 lxw_row_t last_row);
2032 
2033 /**
2034  * @brief Set the number of columns to repeat at the top of each printed page.
2035  *
2036  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2037  * @param first_col First column of repeat range.
2038  * @param last_col  Last column of repeat range.
2039  *
2040  * @return A #lxw_error code.
2041  *
2042  * For large Excel documents it is often desirable to have the first column or
2043  * columns of the worksheet print out at the left of each page.
2044  *
2045  * This can be achieved by using this function. The parameters `first_col`
2046  * and `last_col` are zero based:
2047  *
2048  * @code
2049  *     worksheet_repeat_columns(worksheet, 0, 0); // Repeat the first col.
2050  *     worksheet_repeat_columns(worksheet, 0, 1); // Repeat the first two cols.
2051  * @endcode
2052  */
2053 lxw_error worksheet_repeat_columns(lxw_worksheet *worksheet,
2054                                    lxw_col_t first_col, lxw_col_t last_col);
2055 
2056 /**
2057  * @brief Set the print area for a worksheet.
2058  *
2059  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2060  * @param first_row The first row of the range. (All zero indexed.)
2061  * @param first_col The first column of the range.
2062  * @param last_row  The last row of the range.
2063  * @param last_col  The last col of the range.
2064  *
2065  * @return A #lxw_error code.
2066  *
2067  * This function is used to specify the area of the worksheet that will be
2068  * printed. The RANGE() macro is often convenient for this.
2069  *
2070  * @code
2071  *     worksheet_print_area(worksheet, 0, 0, 41, 10); // A1:K42.
2072  *
2073  *     // Same as:
2074  *     worksheet_print_area(worksheet, RANGE("A1:K42"));
2075  * @endcode
2076  *
2077  * In order to set a row or column range you must specify the entire range:
2078  *
2079  * @code
2080  *     worksheet_print_area(worksheet, RANGE("A1:H1048576")); // Same as A:H.
2081  * @endcode
2082  */
2083 lxw_error worksheet_print_area(lxw_worksheet *worksheet, lxw_row_t first_row,
2084                                lxw_col_t first_col, lxw_row_t last_row,
2085                                lxw_col_t last_col);
2086 /**
2087  * @brief Fit the printed area to a specific number of pages both vertically
2088  *        and horizontally.
2089  *
2090  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2091  * @param width     Number of pages horizontally.
2092  * @param height    Number of pages vertically.
2093  *
2094  * The `%worksheet_fit_to_pages()` function is used to fit the printed area to
2095  * a specific number of pages both vertically and horizontally. If the printed
2096  * area exceeds the specified number of pages it will be scaled down to
2097  * fit. This ensures that the printed area will always appear on the specified
2098  * number of pages even if the page size or margins change:
2099  *
2100  * @code
2101  *     worksheet_fit_to_pages(worksheet1, 1, 1); // Fit to 1x1 pages.
2102  *     worksheet_fit_to_pages(worksheet2, 2, 1); // Fit to 2x1 pages.
2103  *     worksheet_fit_to_pages(worksheet3, 1, 2); // Fit to 1x2 pages.
2104  * @endcode
2105  *
2106  * The print area can be defined using the `worksheet_print_area()` function
2107  * as described above.
2108  *
2109  * A common requirement is to fit the printed output to `n` pages wide but
2110  * have the height be as long as necessary. To achieve this set the `height`
2111  * to zero:
2112  *
2113  * @code
2114  *     // 1 page wide and as long as necessary.
2115  *     worksheet_fit_to_pages(worksheet, 1, 0);
2116  * @endcode
2117  *
2118  * **Note**:
2119  *
2120  * - Although it is valid to use both `%worksheet_fit_to_pages()` and
2121  *   `worksheet_set_print_scale()` on the same worksheet Excel only allows one
2122  *   of these options to be active at a time. The last function call made will
2123  *   set the active option.
2124  *
2125  * - The `%worksheet_fit_to_pages()` function will override any manual page
2126  *   breaks that are defined in the worksheet.
2127  *
2128  * - When using `%worksheet_fit_to_pages()` it may also be required to set the
2129  *   printer paper size using `worksheet_set_paper()` or else Excel will
2130  *   default to "US Letter".
2131  *
2132  */
2133 void worksheet_fit_to_pages(lxw_worksheet *worksheet, uint16_t width,
2134                             uint16_t height);
2135 
2136 /**
2137  * @brief Set the start page number when printing.
2138  *
2139  * @param worksheet  Pointer to a lxw_worksheet instance to be updated.
2140  * @param start_page Starting page number.
2141  *
2142  * The `%worksheet_set_start_page()` function is used to set the number of
2143  * the starting page when the worksheet is printed out:
2144  *
2145  * @code
2146  *     // Start print from page 2.
2147  *     worksheet_set_start_page(worksheet, 2);
2148  * @endcode
2149  */
2150 void worksheet_set_start_page(lxw_worksheet *worksheet, uint16_t start_page);
2151 
2152 /**
2153  * @brief Set the scale factor for the printed page.
2154  *
2155  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2156  * @param scale     Print scale of worksheet to be printed.
2157  *
2158  * This function sets the scale factor of the printed page. The Scale factor
2159  * must be in the range `10 <= scale <= 400`:
2160  *
2161  * @code
2162  *     worksheet_set_print_scale(worksheet1, 75);
2163  *     worksheet_set_print_scale(worksheet2, 400);
2164  * @endcode
2165  *
2166  * The default scale factor is 100. Note, `%worksheet_set_print_scale()` does
2167  * not affect the scale of the visible page in Excel. For that you should use
2168  * `worksheet_set_zoom()`.
2169  *
2170  * Note that although it is valid to use both `worksheet_fit_to_pages()` and
2171  * `%worksheet_set_print_scale()` on the same worksheet Excel only allows one
2172  * of these options to be active at a time. The last function call made will
2173  * set the active option.
2174  *
2175  */
2176 void worksheet_set_print_scale(lxw_worksheet *worksheet, uint16_t scale);
2177 
2178 /**
2179  * @brief Display the worksheet cells from right to left for some versions of
2180  *        Excel.
2181  *
2182  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2183  *
2184   * The `%worksheet_right_to_left()` function is used to change the default
2185  * direction of the worksheet from left-to-right, with the `A1` cell in the
2186  * top left, to right-to-left, with the `A1` cell in the top right.
2187  *
2188  * @code
2189  *     worksheet_right_to_left(worksheet1);
2190  * @endcode
2191  *
2192  * This is useful when creating Arabic, Hebrew or other near or far eastern
2193  * worksheets that use right-to-left as the default direction.
2194  */
2195 void worksheet_right_to_left(lxw_worksheet *worksheet);
2196 
2197 /**
2198  * @brief Hide zero values in worksheet cells.
2199  *
2200  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2201  *
2202  * The `%worksheet_hide_zero()` function is used to hide any zero values that
2203  * appear in cells:
2204  *
2205  * @code
2206  *     worksheet_hide_zero(worksheet1);
2207  * @endcode
2208  */
2209 void worksheet_hide_zero(lxw_worksheet *worksheet);
2210 
2211 /**
2212  * @brief Set the color of the worksheet tab.
2213  *
2214  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2215  * @param color     The tab color.
2216  *
2217  * The `%worksheet_set_tab_color()` function is used to change the color of the worksheet
2218  * tab:
2219  *
2220  * @code
2221  *      worksheet_set_tab_color(worksheet1, LXW_COLOR_RED);
2222  *      worksheet_set_tab_color(worksheet2, LXW_COLOR_GREEN);
2223  *      worksheet_set_tab_color(worksheet3, 0xFF9900); // Orange.
2224  * @endcode
2225  *
2226  * The color should be an RGB integer value, see @ref working_with_colors.
2227  */
2228 void worksheet_set_tab_color(lxw_worksheet *worksheet, lxw_color_t color);
2229 
2230 /**
2231  * @brief Protect elements of a worksheet from modification.
2232  *
2233  * @param worksheet Pointer to a lxw_worksheet instance to be updated.
2234  * @param password  A worksheet password.
2235  * @param options   Worksheet elements to protect.
2236  *
2237  * The `%worksheet_protect()` function protects worksheet elements from modification:
2238  *
2239  * @code
2240  *     worksheet_protect(worksheet, "Some Password", options);
2241  * @endcode
2242  *
2243  * The `password` and lxw_protection pointer are both optional:
2244  *
2245  * @code
2246  *     worksheet_protect(worksheet1, NULL,       NULL);
2247  *     worksheet_protect(worksheet2, NULL,       my_options);
2248  *     worksheet_protect(worksheet3, "password", NULL);
2249  *     worksheet_protect(worksheet4, "password", my_options);
2250  * @endcode
2251  *
2252  * Passing a `NULL` password is the same as turning on protection without a
2253  * password. Passing a `NULL` password and `NULL` options, or any other
2254  * combination has the effect of enabling a cell's `locked` and `hidden`
2255  * properties if they have been set.
2256  *
2257  * A *locked* cell cannot be edited and this property is on by default for all
2258  * cells. A *hidden* cell will display the results of a formula but not the
2259  * formula itself. These properties can be set using the format_set_unlocked()
2260  * and format_set_hidden() format functions.
2261  *
2262  * You can specify which worksheet elements you wish to protect by passing a
2263  * lxw_protection pointer in the `options` argument with any or all of the
2264  * following members set:
2265  *
2266  *     no_select_locked_cells
2267  *     no_select_unlocked_cells
2268  *     format_cells
2269  *     format_columns
2270  *     format_rows
2271  *     insert_columns
2272  *     insert_rows
2273  *     insert_hyperlinks
2274  *     delete_columns
2275  *     delete_rows
2276  *     sort
2277  *     autofilter
2278  *     pivot_tables
2279  *     scenarios
2280  *     objects
2281  *
2282  * All parameters are off by default. Individual elements can be protected as
2283  * follows:
2284  *
2285  * @code
2286  *     lxw_protection options = {
2287  *         .format_cells             = 1,
2288  *         .insert_hyperlinks        = 1,
2289  *         .insert_rows              = 1,
2290  *         .delete_rows              = 1,
2291  *         .insert_columns           = 1,
2292  *         .delete_columns           = 1,
2293  *     };
2294  *
2295  *     worksheet_protect(worksheet, NULL, &options);
2296  *
2297  * @endcode
2298  *
2299  * See also the format_set_unlocked() and format_set_hidden() format functions.
2300  *
2301  * **Note:** Worksheet level passwords in Excel offer **very** weak
2302  * protection. They don't encrypt your data and are very easy to
2303  * deactivate. Full workbook encryption is not supported by `libxlsxwriter`
2304  * since it requires a completely different file format and would take several
2305  * man months to implement.
2306  */
2307 void worksheet_protect(lxw_worksheet *worksheet, const char *password,
2308                        lxw_protection *options);
2309 
2310 /**
2311  * @brief Set the default row properties.
2312  *
2313  * @param worksheet        Pointer to a lxw_worksheet instance to be updated.
2314  * @param height           Default row height.
2315  * @param hide_unused_rows Hide unused cells.
2316  *
2317  * The `%worksheet_set_default_row()` function is used to set Excel default
2318  * row properties such as the default height and the option to hide unused
2319  * rows. These parameters are an optimization used by Excel to set row
2320  * properties without generating a very large file with an entry for each row.
2321  *
2322  * To set the default row height:
2323  *
2324  * @code
2325  *     worksheet_set_default_row(worksheet, 24, LXW_FALSE);
2326  *
2327  * @endcode
2328  *
2329  * To hide unused rows:
2330  *
2331  * @code
2332  *     worksheet_set_default_row(worksheet, 15, LXW_TRUE);
2333  * @endcode
2334  *
2335  * Note, in the previous case we use the default height #LXW_DEF_ROW_HEIGHT =
2336  * 15 so the the height remains unchanged.
2337  */
2338 void worksheet_set_default_row(lxw_worksheet *worksheet, double height,
2339                                uint8_t hide_unused_rows);
2340 
2341 lxw_worksheet *lxw_worksheet_new(lxw_worksheet_init_data *init_data);
2342 void lxw_worksheet_free(lxw_worksheet *worksheet);
2343 void lxw_worksheet_assemble_xml_file(lxw_worksheet *worksheet);
2344 void lxw_worksheet_write_single_row(lxw_worksheet *worksheet);
2345 
2346 void lxw_worksheet_prepare_image(lxw_worksheet *worksheet,
2347                                  uint16_t image_ref_id, uint16_t drawing_id,
2348                                  lxw_image_options *image_data);
2349 
2350 void lxw_worksheet_prepare_chart(lxw_worksheet *worksheet,
2351                                  uint16_t chart_ref_id, uint16_t drawing_id,
2352                                  lxw_image_options *image_data);
2353 
2354 lxw_row *lxw_worksheet_find_row(lxw_worksheet *worksheet, lxw_row_t row_num);
2355 lxw_cell *lxw_worksheet_find_cell(lxw_row *row, lxw_col_t col_num);
2356