xlsxwriter 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +40 -0
  3. data/ext/xlsxwriter/chart.c +105 -0
  4. data/ext/xlsxwriter/chart.h +27 -0
  5. data/ext/xlsxwriter/extconf.rb +14 -0
  6. data/ext/xlsxwriter/format.c +67 -0
  7. data/ext/xlsxwriter/format.h +9 -0
  8. data/ext/xlsxwriter/libxlsxwriter/LICENSE.txt +89 -0
  9. data/ext/xlsxwriter/libxlsxwriter/Makefile +141 -0
  10. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter.h +23 -0
  11. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/app.h +79 -0
  12. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/chart.h +1093 -0
  13. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/common.h +336 -0
  14. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
  15. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/core.h +51 -0
  16. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
  17. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
  18. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
  19. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
  20. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
  21. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
  22. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
  23. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
  24. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
  25. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +215 -0
  26. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
  27. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
  28. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
  29. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
  30. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
  31. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/workbook.h +751 -0
  32. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
  33. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
  34. data/ext/xlsxwriter/libxlsxwriter/lib/.gitignore +0 -0
  35. data/ext/xlsxwriter/libxlsxwriter/src/Makefile +125 -0
  36. data/ext/xlsxwriter/libxlsxwriter/src/app.c +439 -0
  37. data/ext/xlsxwriter/libxlsxwriter/src/chart.c +3420 -0
  38. data/ext/xlsxwriter/libxlsxwriter/src/content_types.c +341 -0
  39. data/ext/xlsxwriter/libxlsxwriter/src/core.c +293 -0
  40. data/ext/xlsxwriter/libxlsxwriter/src/custom.c +224 -0
  41. data/ext/xlsxwriter/libxlsxwriter/src/drawing.c +746 -0
  42. data/ext/xlsxwriter/libxlsxwriter/src/format.c +728 -0
  43. data/ext/xlsxwriter/libxlsxwriter/src/hash_table.c +223 -0
  44. data/ext/xlsxwriter/libxlsxwriter/src/packager.c +877 -0
  45. data/ext/xlsxwriter/libxlsxwriter/src/relationships.c +242 -0
  46. data/ext/xlsxwriter/libxlsxwriter/src/shared_strings.c +264 -0
  47. data/ext/xlsxwriter/libxlsxwriter/src/styles.c +1086 -0
  48. data/ext/xlsxwriter/libxlsxwriter/src/theme.c +348 -0
  49. data/ext/xlsxwriter/libxlsxwriter/src/utility.c +512 -0
  50. data/ext/xlsxwriter/libxlsxwriter/src/workbook.c +1895 -0
  51. data/ext/xlsxwriter/libxlsxwriter/src/worksheet.c +4992 -0
  52. data/ext/xlsxwriter/libxlsxwriter/src/xmlwriter.c +355 -0
  53. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/Makefile +44 -0
  54. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/crypt.h +131 -0
  55. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
  56. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.h +209 -0
  57. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
  58. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
  59. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
  60. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/minizip.c +520 -0
  61. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.c +291 -0
  62. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.h +37 -0
  63. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
  64. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.h +437 -0
  65. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.c +2007 -0
  66. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.h +367 -0
  67. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
  68. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
  69. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
  70. data/ext/xlsxwriter/workbook.c +257 -0
  71. data/ext/xlsxwriter/workbook.h +42 -0
  72. data/ext/xlsxwriter/workbook_properties.c +103 -0
  73. data/ext/xlsxwriter/workbook_properties.h +10 -0
  74. data/ext/xlsxwriter/worksheet.c +1064 -0
  75. data/ext/xlsxwriter/worksheet.h +74 -0
  76. data/ext/xlsxwriter/xlsxwriter.c +239 -0
  77. data/lib/xlsxwriter.rb +6 -0
  78. data/lib/xlsxwriter/version.rb +3 -0
  79. data/lib/xlsxwriter/worksheet.rb +72 -0
  80. data/test/run-test.rb +11 -0
  81. data/test/support/xlsx_comparable.rb +109 -0
  82. data/test/test-array-formula.rb +33 -0
  83. data/test/test-autofilter.rb +70 -0
  84. data/test/test-chart-area.rb +25 -0
  85. data/test/test-data.rb +65 -0
  86. data/test/test-default-row.rb +25 -0
  87. data/test/test-defined-name.rb +46 -0
  88. data/test/test-escapes.rb +33 -0
  89. data/test/test-fit-to-pages.rb +21 -0
  90. data/test/test-formatting.rb +137 -0
  91. data/test/test-gridlines.rb +15 -0
  92. data/test/test-hyperlink.rb +67 -0
  93. data/test/test-image.rb +84 -0
  94. data/test/test-merge-range.rb +18 -0
  95. data/test/test-misc.rb +29 -0
  96. data/test/test-optimize.rb +32 -0
  97. data/test/test-page-breaks.rb +13 -0
  98. data/test/test-page-setup.rb +28 -0
  99. data/test/test-panes.rb +45 -0
  100. data/test/test-print-area.rb +19 -0
  101. data/test/test-print-options.rb +61 -0
  102. data/test/test-print-scale.rb +12 -0
  103. data/test/test-properties.rb +51 -0
  104. data/test/test-protect.rb +27 -0
  105. data/test/test-repeat.rb +23 -0
  106. data/test/test-row-col-format.rb +35 -0
  107. data/test/test-set-selection.rb +13 -0
  108. data/test/test-set-start-page.rb +13 -0
  109. data/test/test-simple.rb +62 -0
  110. data/test/test-types.rb +17 -0
  111. data/test/xlsx-func-testcase.rb +36 -0
  112. metadata +228 -0
@@ -0,0 +1,751 @@
1
+ /*
2
+ * libxlsxwriter
3
+ *
4
+ * Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
5
+ */
6
+
7
+ /**
8
+ * @page workbook_page The Workbook object
9
+ *
10
+ * The Workbook is the main object exposed by the libxlsxwriter library. It
11
+ * represents the entire spreadsheet as you see it in Excel and internally it
12
+ * represents the Excel file as it is written on disk.
13
+ *
14
+ * See @ref workbook.h for full details of the functionality.
15
+ *
16
+ * @file workbook.h
17
+ *
18
+ * @brief Functions related to creating an Excel xlsx workbook.
19
+ *
20
+ * The Workbook is the main object exposed by the libxlsxwriter library. It
21
+ * represents the entire spreadsheet as you see it in Excel and internally it
22
+ * represents the Excel file as it is written on disk.
23
+ *
24
+ * @code
25
+ * #include "xlsxwriter.h"
26
+ *
27
+ * int main() {
28
+ *
29
+ * lxw_workbook *workbook = workbook_new("filename.xlsx");
30
+ * lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
31
+ *
32
+ * worksheet_write_string(worksheet, 0, 0, "Hello Excel", NULL);
33
+ *
34
+ * return workbook_close(workbook);
35
+ * }
36
+ * @endcode
37
+ *
38
+ * @image html workbook01.png
39
+ *
40
+ */
41
+ #ifndef __LXW_WORKBOOK_H__
42
+ #define __LXW_WORKBOOK_H__
43
+
44
+ #include <stdint.h>
45
+ #include <stdio.h>
46
+ #include <errno.h>
47
+
48
+ #include "worksheet.h"
49
+ #include "chart.h"
50
+ #include "shared_strings.h"
51
+ #include "hash_table.h"
52
+ #include "common.h"
53
+
54
+ #define LXW_DEFINED_NAME_LENGTH 128
55
+
56
+ /* Define the tree.h RB structs for the red-black head types. */
57
+ RB_HEAD(lxw_worksheet_names, lxw_worksheet_name);
58
+
59
+ /* Define the queue.h structs for the workbook lists. */
60
+ STAILQ_HEAD(lxw_worksheets, lxw_worksheet);
61
+ STAILQ_HEAD(lxw_charts, lxw_chart);
62
+ TAILQ_HEAD(lxw_defined_names, lxw_defined_name);
63
+
64
+ /* Struct to represent a worksheet name/pointer pair. */
65
+ typedef struct lxw_worksheet_name {
66
+ const char *name;
67
+ lxw_worksheet *worksheet;
68
+
69
+ RB_ENTRY (lxw_worksheet_name) tree_pointers;
70
+ } lxw_worksheet_name;
71
+
72
+ /* Wrapper around RB_GENERATE_STATIC from tree.h to avoid unused function
73
+ * warnings and to avoid portability issues with the _unused attribute. */
74
+ #define LXW_RB_GENERATE_NAMES(name, type, field, cmp) \
75
+ RB_GENERATE_INSERT_COLOR(name, type, field, static) \
76
+ RB_GENERATE_REMOVE_COLOR(name, type, field, static) \
77
+ RB_GENERATE_INSERT(name, type, field, cmp, static) \
78
+ RB_GENERATE_REMOVE(name, type, field, static) \
79
+ RB_GENERATE_FIND(name, type, field, cmp, static) \
80
+ RB_GENERATE_NEXT(name, type, field, static) \
81
+ RB_GENERATE_MINMAX(name, type, field, static) \
82
+ /* Add unused struct to allow adding a semicolon */ \
83
+ struct lxw_rb_generate_names{int unused;}
84
+
85
+ /**
86
+ * @brief Macro to loop over all the worksheets in a workbook.
87
+ *
88
+ * This macro allows you to loop over all the worksheets that have been
89
+ * added to a workbook. You must provide a lxw_worksheet pointer and
90
+ * a pointer to the lxw_workbook:
91
+ *
92
+ * @code
93
+ * lxw_workbook *workbook = workbook_new("test.xlsx");
94
+ *
95
+ * lxw_worksheet *worksheet; // Generic worksheet pointer.
96
+ *
97
+ * // Worksheet objects used in the program.
98
+ * lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
99
+ * lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
100
+ * lxw_worksheet *worksheet3 = workbook_add_worksheet(workbook, NULL);
101
+ *
102
+ * // Iterate over the 3 worksheets and perform the same operation on each.
103
+ * LXW_FOREACH_WORKSHEET(worksheet, workbook) {
104
+ * worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
105
+ * }
106
+ * @endcode
107
+ */
108
+ #define LXW_FOREACH_WORKSHEET(worksheet, workbook) \
109
+ STAILQ_FOREACH((worksheet), (workbook)->worksheets, list_pointers)
110
+
111
+ /* Struct to represent a defined name. */
112
+ typedef struct lxw_defined_name {
113
+ int16_t index;
114
+ uint8_t hidden;
115
+ char name[LXW_DEFINED_NAME_LENGTH];
116
+ char app_name[LXW_DEFINED_NAME_LENGTH];
117
+ char formula[LXW_DEFINED_NAME_LENGTH];
118
+ char normalised_name[LXW_DEFINED_NAME_LENGTH];
119
+ char normalised_sheetname[LXW_DEFINED_NAME_LENGTH];
120
+
121
+ /* List pointers for queue.h. */
122
+ TAILQ_ENTRY (lxw_defined_name) list_pointers;
123
+ } lxw_defined_name;
124
+
125
+ /**
126
+ * Workbook document properties.
127
+ */
128
+ typedef struct lxw_doc_properties {
129
+ /** The title of the Excel Document. */
130
+ char *title;
131
+
132
+ /** The subject of the Excel Document. */
133
+ char *subject;
134
+
135
+ /** The author of the Excel Document. */
136
+ char *author;
137
+
138
+ /** The manager field of the Excel Document. */
139
+ char *manager;
140
+
141
+ /** The company field of the Excel Document. */
142
+ char *company;
143
+
144
+ /** The category of the Excel Document. */
145
+ char *category;
146
+
147
+ /** The keywords of the Excel Document. */
148
+ char *keywords;
149
+
150
+ /** The comment field of the Excel Document. */
151
+ char *comments;
152
+
153
+ /** The status of the Excel Document. */
154
+ char *status;
155
+
156
+ /** The hyperlink base url of the Excel Document. */
157
+ char *hyperlink_base;
158
+
159
+ time_t created;
160
+
161
+ } lxw_doc_properties;
162
+
163
+ /**
164
+ * @brief Workbook options.
165
+ *
166
+ * Optional parameters when creating a new Workbook object via
167
+ * workbook_new_opt().
168
+ *
169
+ * The following properties are supported:
170
+ *
171
+ * - `constant_memory`: Reduces the amount of data stored in memory so that
172
+ * large files can be written efficiently.
173
+ *
174
+ * @note In this mode a row of data is written and then discarded when a
175
+ * cell in a new row is added via one of the `worksheet_write_*()`
176
+ * functions. Therefore, once this option is active, data should be written in
177
+ * sequential row order. For this reason the `worksheet_merge_range()`
178
+ * doesn't work in this mode. See also @ref ww_mem_constant.
179
+ *
180
+ * - `tmpdir`: libxlsxwriter stores workbook data in temporary files prior
181
+ * to assembling the final XLSX file. The temporary files are created in the
182
+ * system's temp directory. If the default temporary directory isn't
183
+ * accessible to your application, or doesn't contain enough space, you can
184
+ * specify an alternative location using the `tempdir` option.
185
+ */
186
+ typedef struct lxw_workbook_options {
187
+ /** Optimize the workbook to use constant memory for worksheets */
188
+ uint8_t constant_memory;
189
+
190
+ /** Directory to use for the temporary files created by libxlsxwriter. */
191
+ char *tmpdir;
192
+ } lxw_workbook_options;
193
+
194
+ /**
195
+ * @brief Struct to represent an Excel workbook.
196
+ *
197
+ * The members of the lxw_workbook struct aren't modified directly. Instead
198
+ * the workbook properties are set by calling the functions shown in
199
+ * workbook.h.
200
+ */
201
+ typedef struct lxw_workbook {
202
+
203
+ FILE *file;
204
+ struct lxw_worksheets *worksheets;
205
+ struct lxw_worksheet_names *worksheet_names;
206
+ struct lxw_charts *charts;
207
+ struct lxw_charts *ordered_charts;
208
+ struct lxw_formats *formats;
209
+ struct lxw_defined_names *defined_names;
210
+ lxw_sst *sst;
211
+ lxw_doc_properties *properties;
212
+ struct lxw_custom_properties *custom_properties;
213
+
214
+ char *filename;
215
+ lxw_workbook_options options;
216
+
217
+ uint16_t num_sheets;
218
+ uint16_t first_sheet;
219
+ uint16_t active_sheet;
220
+ uint16_t num_xf_formats;
221
+ uint16_t num_format_count;
222
+ uint16_t drawing_count;
223
+
224
+ uint16_t font_count;
225
+ uint16_t border_count;
226
+ uint16_t fill_count;
227
+ uint8_t optimize;
228
+
229
+ uint8_t has_png;
230
+ uint8_t has_jpeg;
231
+ uint8_t has_bmp;
232
+
233
+ lxw_hash_table *used_xf_formats;
234
+
235
+ } lxw_workbook;
236
+
237
+
238
+ /* *INDENT-OFF* */
239
+ #ifdef __cplusplus
240
+ extern "C" {
241
+ #endif
242
+ /* *INDENT-ON* */
243
+
244
+ /**
245
+ * @brief Create a new workbook object.
246
+ *
247
+ * @param filename The name of the new Excel file to create.
248
+ *
249
+ * @return A lxw_workbook instance.
250
+ *
251
+ * The `%workbook_new()` constructor is used to create a new Excel workbook
252
+ * with a given filename:
253
+ *
254
+ * @code
255
+ * lxw_workbook *workbook = workbook_new("filename.xlsx");
256
+ * @endcode
257
+ *
258
+ * When specifying a filename it is recommended that you use an `.xlsx`
259
+ * extension or Excel will generate a warning when opening the file.
260
+ *
261
+ */
262
+ lxw_workbook *workbook_new(const char *filename);
263
+
264
+ /**
265
+ * @brief Create a new workbook object, and set the workbook options.
266
+ *
267
+ * @param filename The name of the new Excel file to create.
268
+ * @param options Workbook options.
269
+ *
270
+ * @return A lxw_workbook instance.
271
+ *
272
+ * This function is the same as the `workbook_new()` constructor but allows
273
+ * additional options to be set.
274
+ *
275
+ * @code
276
+ * lxw_workbook_options options = {.constant_memory = 1,
277
+ * .tmpdir = "C:\\Temp"};
278
+ *
279
+ * lxw_workbook *workbook = workbook_new_opt("filename.xlsx", &options);
280
+ * @endcode
281
+ *
282
+ * The options that can be set via #lxw_workbook_options are:
283
+ *
284
+ * - `constant_memory`: Reduces the amount of data stored in memory so that
285
+ * large files can be written efficiently.
286
+ *
287
+ * @note In this mode a row of data is written and then discarded when a
288
+ * cell in a new row is added via one of the `worksheet_write_*()`
289
+ * functions. Therefore, once this option is active, data should be written in
290
+ * sequential row order. For this reason the `worksheet_merge_range()`
291
+ * doesn't work in this mode. See also @ref ww_mem_constant.
292
+ *
293
+ * - `tmpdir`: libxlsxwriter stores workbook data in temporary files prior
294
+ * to assembling the final XLSX file. The temporary files are created in the
295
+ * system's temp directory. If the default temporary directory isn't
296
+ * accessible to your application, or doesn't contain enough space, you can
297
+ * specify an alternative location using the `tempdir` option.*
298
+ *
299
+ * See @ref working_with_memory for more details.
300
+ *
301
+ */
302
+ lxw_workbook *workbook_new_opt(const char *filename,
303
+ lxw_workbook_options *options);
304
+
305
+ /* Deprecated function name for backwards compatibility. */
306
+ lxw_workbook *new_workbook(const char *filename);
307
+
308
+ /* Deprecated function name for backwards compatibility. */
309
+ lxw_workbook *new_workbook_opt(const char *filename,
310
+ lxw_workbook_options *options);
311
+
312
+ /**
313
+ * @brief Add a new worksheet to a workbook.
314
+ *
315
+ * @param workbook Pointer to a lxw_workbook instance.
316
+ * @param sheetname Optional worksheet name, defaults to Sheet1, etc.
317
+ *
318
+ * @return A lxw_worksheet object.
319
+ *
320
+ * The `%workbook_add_worksheet()` function adds a new worksheet to a workbook:
321
+ *
322
+ * At least one worksheet should be added to a new workbook: The @ref
323
+ * worksheet.h "Worksheet" object is used to write data and configure a
324
+ * worksheet in the workbook.
325
+ *
326
+ * The `sheetname` parameter is optional. If it is `NULL` the default
327
+ * Excel convention will be followed, i.e. Sheet1, Sheet2, etc.:
328
+ *
329
+ * @code
330
+ * worksheet = workbook_add_worksheet(workbook, NULL ); // Sheet1
331
+ * worksheet = workbook_add_worksheet(workbook, "Foglio2"); // Foglio2
332
+ * worksheet = workbook_add_worksheet(workbook, "Data"); // Data
333
+ * worksheet = workbook_add_worksheet(workbook, NULL ); // Sheet4
334
+ *
335
+ * @endcode
336
+ *
337
+ * @image html workbook02.png
338
+ *
339
+ * The worksheet name must be a valid Excel worksheet name, i.e. it must be
340
+ * less than 32 character and it cannot contain any of the characters:
341
+ *
342
+ * / \ [ ] : * ?
343
+ *
344
+ * In addition, you cannot use the same, case insensitive, `sheetname` for more
345
+ * than one worksheet.
346
+ *
347
+ */
348
+ lxw_worksheet *workbook_add_worksheet(lxw_workbook *workbook,
349
+ const char *sheetname);
350
+
351
+ /**
352
+ * @brief Create a new @ref format.h "Format" object to formats cells in
353
+ * worksheets.
354
+ *
355
+ * @param workbook Pointer to a lxw_workbook instance.
356
+ *
357
+ * @return A lxw_format instance.
358
+ *
359
+ * The `workbook_add_format()` function can be used to create new @ref
360
+ * format.h "Format" objects which are used to apply formatting to a cell.
361
+ *
362
+ * @code
363
+ * // Create the Format.
364
+ * lxw_format *format = workbook_add_format(workbook);
365
+ *
366
+ * // Set some of the format properties.
367
+ * format_set_bold(format);
368
+ * format_set_font_color(format, LXW_COLOR_RED);
369
+ *
370
+ * // Use the format to change the text format in a cell.
371
+ * worksheet_write_string(worksheet, 0, 0, "Hello", format);
372
+ * @endcode
373
+ *
374
+ * See @ref format.h "the Format object" and @ref working_with_formats
375
+ * sections for more details about Format properties and how to set them.
376
+ *
377
+ */
378
+ lxw_format *workbook_add_format(lxw_workbook *workbook);
379
+
380
+ /**
381
+ * @brief Create a new chart to be added to a worksheet:
382
+ *
383
+ * @param workbook Pointer to a lxw_workbook instance.
384
+ * @param chart_type The type of chart to be created. See #lxw_chart_type.
385
+ *
386
+ * @return A lxw_chart object.
387
+ *
388
+ * The `%workbook_add_chart()` function creates a new chart object that can
389
+ * be added to a worksheet:
390
+ *
391
+ * @code
392
+ * // Create a chart object.
393
+ * lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
394
+ *
395
+ * // Add data series to the chart.
396
+ * chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5");
397
+ * chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5");
398
+ * chart_add_series(chart, NULL, "Sheet1!$C$1:$C$5");
399
+ *
400
+ * // Insert the chart into the worksheet
401
+ * worksheet_insert_chart(worksheet, CELL("B7"), chart);
402
+ * @endcode
403
+ *
404
+ * The available chart types are defined in #lxw_chart_type. The types of
405
+ * charts that are supported are:
406
+ *
407
+ * | Chart type | Description |
408
+ * | :--------------------------------------- | :------------------------------------ |
409
+ * | #LXW_CHART_AREA | Area chart. |
410
+ * | #LXW_CHART_AREA_STACKED | Area chart - stacked. |
411
+ * | #LXW_CHART_AREA_STACKED_PERCENT | Area chart - percentage stacked. |
412
+ * | #LXW_CHART_BAR | Bar chart. |
413
+ * | #LXW_CHART_BAR_STACKED | Bar chart - stacked. |
414
+ * | #LXW_CHART_BAR_STACKED_PERCENT | Bar chart - percentage stacked. |
415
+ * | #LXW_CHART_COLUMN | Column chart. |
416
+ * | #LXW_CHART_COLUMN_STACKED | Column chart - stacked. |
417
+ * | #LXW_CHART_COLUMN_STACKED_PERCENT | Column chart - percentage stacked. |
418
+ * | #LXW_CHART_DOUGHNUT | Doughnut chart. |
419
+ * | #LXW_CHART_LINE | Line chart. |
420
+ * | #LXW_CHART_PIE | Pie chart. |
421
+ * | #LXW_CHART_SCATTER | Scatter chart. |
422
+ * | #LXW_CHART_SCATTER_STRAIGHT | Scatter chart - straight. |
423
+ * | #LXW_CHART_SCATTER_STRAIGHT_WITH_MARKERS | Scatter chart - straight with markers. |
424
+ * | #LXW_CHART_SCATTER_SMOOTH | Scatter chart - smooth. |
425
+ * | #LXW_CHART_SCATTER_SMOOTH_WITH_MARKERS | Scatter chart - smooth with markers. |
426
+ * | #LXW_CHART_RADAR | Radar chart. |
427
+ * | #LXW_CHART_RADAR_WITH_MARKERS | Radar chart - with markers. |
428
+ * | #LXW_CHART_RADAR_FILLED | Radar chart - filled. |
429
+ *
430
+ *
431
+ *
432
+ * See @ref chart.h for details.
433
+ */
434
+ lxw_chart *workbook_add_chart(lxw_workbook *workbook, uint8_t chart_type);
435
+
436
+ /**
437
+ * @brief Close the Workbook object and write the XLSX file.
438
+ *
439
+ * @param workbook Pointer to a lxw_workbook instance.
440
+ *
441
+ * @return A #lxw_error.
442
+ *
443
+ * The `%workbook_close()` function closes a Workbook object, writes the Excel
444
+ * file to disk, frees any memory allocated internally to the Workbook and
445
+ * frees the object itself.
446
+ *
447
+ * @code
448
+ * workbook_close(workbook);
449
+ * @endcode
450
+ *
451
+ * The `%workbook_close()` function returns any #lxw_error error codes
452
+ * encountered when creating the Excel file. The error code can be returned
453
+ * from the program main or the calling function:
454
+ *
455
+ * @code
456
+ * return workbook_close(workbook);
457
+ * @endcode
458
+ *
459
+ */
460
+ lxw_error workbook_close(lxw_workbook *workbook);
461
+
462
+ /**
463
+ * @brief Set the document properties such as Title, Author etc.
464
+ *
465
+ * @param workbook Pointer to a lxw_workbook instance.
466
+ * @param properties Document properties to set.
467
+ *
468
+ * @return A #lxw_error.
469
+ *
470
+ * The `%workbook_set_properties` function can be used to set the document
471
+ * properties of the Excel file created by `libxlsxwriter`. These properties
472
+ * are visible when you use the `Office Button -> Prepare -> Properties`
473
+ * option in Excel and are also available to external applications that read
474
+ * or index windows files.
475
+ *
476
+ * The properties that can be set are:
477
+ *
478
+ * - `title`
479
+ * - `subject`
480
+ * - `author`
481
+ * - `manager`
482
+ * - `company`
483
+ * - `category`
484
+ * - `keywords`
485
+ * - `comments`
486
+ * - `hyperlink_base`
487
+ *
488
+ * The properties are specified via a `lxw_doc_properties` struct. All the
489
+ * members are `char *` and they are all optional. An example of how to create
490
+ * and pass the properties is:
491
+ *
492
+ * @code
493
+ * // Create a properties structure and set some of the fields.
494
+ * lxw_doc_properties properties = {
495
+ * .title = "This is an example spreadsheet",
496
+ * .subject = "With document properties",
497
+ * .author = "John McNamara",
498
+ * .manager = "Dr. Heinz Doofenshmirtz",
499
+ * .company = "of Wolves",
500
+ * .category = "Example spreadsheets",
501
+ * .keywords = "Sample, Example, Properties",
502
+ * .comments = "Created with libxlsxwriter",
503
+ * .status = "Quo",
504
+ * };
505
+ *
506
+ * // Set the properties in the workbook.
507
+ * workbook_set_properties(workbook, &properties);
508
+ * @endcode
509
+ *
510
+ * @image html doc_properties.png
511
+ *
512
+ */
513
+ lxw_error workbook_set_properties(lxw_workbook *workbook,
514
+ lxw_doc_properties *properties);
515
+
516
+ /**
517
+ * @brief Set a custom document text property.
518
+ *
519
+ * @param workbook Pointer to a lxw_workbook instance.
520
+ * @param name The name of the custom property.
521
+ * @param value The value of the custom property.
522
+ *
523
+ * @return A #lxw_error.
524
+ *
525
+ * The `%workbook_set_custom_property_string()` function can be used to set one
526
+ * or more custom document text properties not covered by the standard
527
+ * properties in the `workbook_set_properties()` function above.
528
+ *
529
+ * For example:
530
+ *
531
+ * @code
532
+ * workbook_set_custom_property_string(workbook, "Checked by", "Eve");
533
+ * @endcode
534
+ *
535
+ * @image html custom_properties.png
536
+ *
537
+ * There are 4 `workbook_set_custom_property_string_*()` functions for each
538
+ * of the custom property types supported by Excel:
539
+ *
540
+ * - text/string: `workbook_set_custom_property_string()`
541
+ * - number: `workbook_set_custom_property_number()`
542
+ * - datetime: `workbook_set_custom_property_datetime()`
543
+ * - boolean: `workbook_set_custom_property_boolean()`
544
+ *
545
+ * **Note**: the name and value parameters are limited to 255 characters
546
+ * by Excel.
547
+ *
548
+ */
549
+ lxw_error workbook_set_custom_property_string(lxw_workbook *workbook,
550
+ const char *name,
551
+ const char *value);
552
+ /**
553
+ * @brief Set a custom document number property.
554
+ *
555
+ * @param workbook Pointer to a lxw_workbook instance.
556
+ * @param name The name of the custom property.
557
+ * @param value The value of the custom property.
558
+ *
559
+ * @return A #lxw_error.
560
+ *
561
+ * Set a custom document number property.
562
+ * See `workbook_set_custom_property_string()` above for details.
563
+ *
564
+ * @code
565
+ * workbook_set_custom_property_number(workbook, "Document number", 12345);
566
+ * @endcode
567
+ */
568
+ lxw_error workbook_set_custom_property_number(lxw_workbook *workbook,
569
+ const char *name, double value);
570
+
571
+ /* Undocumented since the user can use workbook_set_custom_property_number().
572
+ * Only implemented for file format completeness and testing.
573
+ */
574
+ lxw_error workbook_set_custom_property_integer(lxw_workbook *workbook,
575
+ const char *name,
576
+ int32_t value);
577
+
578
+ /**
579
+ * @brief Set a custom document boolean property.
580
+ *
581
+ * @param workbook Pointer to a lxw_workbook instance.
582
+ * @param name The name of the custom property.
583
+ * @param value The value of the custom property.
584
+ *
585
+ * @return A #lxw_error.
586
+ *
587
+ * Set a custom document boolean property.
588
+ * See `workbook_set_custom_property_string()` above for details.
589
+ *
590
+ * @code
591
+ * workbook_set_custom_property_boolean(workbook, "Has Review", 1);
592
+ * @endcode
593
+ */
594
+ lxw_error workbook_set_custom_property_boolean(lxw_workbook *workbook,
595
+ const char *name,
596
+ uint8_t value);
597
+ /**
598
+ * @brief Set a custom document date or time property.
599
+ *
600
+ * @param workbook Pointer to a lxw_workbook instance.
601
+ * @param name The name of the custom property.
602
+ * @param datetime The value of the custom property.
603
+ *
604
+ * @return A #lxw_error.
605
+ *
606
+ * Set a custom date or time number property.
607
+ * See `workbook_set_custom_property_string()` above for details.
608
+ *
609
+ * @code
610
+ * lxw_datetime datetime = {2016, 12, 1, 11, 55, 0.0};
611
+ *
612
+ * workbook_set_custom_property_datetime(workbook, "Date completed", &datetime);
613
+ * @endcode
614
+ */
615
+ lxw_error workbook_set_custom_property_datetime(lxw_workbook *workbook,
616
+ const char *name,
617
+ lxw_datetime *datetime);
618
+
619
+ /**
620
+ * @brief Create a defined name in the workbook to use as a variable.
621
+ *
622
+ * @param workbook Pointer to a lxw_workbook instance.
623
+ * @param name The defined name.
624
+ * @param formula The cell or range that the defined name refers to.
625
+ *
626
+ * @return A #lxw_error.
627
+ *
628
+ * This function is used to defined a name that can be used to represent a
629
+ * value, a single cell or a range of cells in a workbook: These defined names
630
+ * can then be used in formulas:
631
+ *
632
+ * @code
633
+ * workbook_define_name(workbook, "Exchange_rate", "=0.96");
634
+ * worksheet_write_formula(worksheet, 2, 1, "=Exchange_rate", NULL);
635
+ *
636
+ * @endcode
637
+ *
638
+ * @image html defined_name.png
639
+ *
640
+ * As in Excel a name defined like this is "global" to the workbook and can be
641
+ * referred to from any worksheet:
642
+ *
643
+ * @code
644
+ * // Global workbook name.
645
+ * workbook_define_name(workbook, "Sales", "=Sheet1!$G$1:$H$10");
646
+ * @endcode
647
+ *
648
+ * It is also possible to define a local/worksheet name by prefixing it with
649
+ * the sheet name using the syntax `'sheetname!definedname'`:
650
+ *
651
+ * @code
652
+ * // Local worksheet name.
653
+ * workbook_define_name(workbook, "Sheet2!Sales", "=Sheet2!$G$1:$G$10");
654
+ * @endcode
655
+ *
656
+ * If the sheet name contains spaces or special characters you must follow the
657
+ * Excel convention and enclose it in single quotes:
658
+ *
659
+ * @code
660
+ * workbook_define_name(workbook, "'New Data'!Sales", "=Sheet2!$G$1:$G$10");
661
+ * @endcode
662
+ *
663
+ * The rules for names in Excel are explained in the
664
+ * [Microsoft Office
665
+ documentation](http://office.microsoft.com/en-001/excel-help/define-and-use-names-in-formulas-HA010147120.aspx).
666
+ *
667
+ */
668
+ lxw_error workbook_define_name(lxw_workbook *workbook, const char *name,
669
+ const char *formula);
670
+
671
+ /**
672
+ * @brief Get a worksheet object from its name.
673
+ *
674
+ * @param workbook
675
+ * @param name
676
+ *
677
+ * @return A lxw_worksheet object.
678
+ *
679
+ * This function returns a lxw_worksheet object reference based on its name:
680
+ *
681
+ * @code
682
+ * worksheet = workbook_get_worksheet_by_name(workbook, "Sheet1");
683
+ * @endcode
684
+ *
685
+ */
686
+ lxw_worksheet *workbook_get_worksheet_by_name(lxw_workbook *workbook,
687
+ const char *name);
688
+
689
+ /**
690
+ * @brief Validate a worksheet name.
691
+ *
692
+ * @param workbook Pointer to a lxw_workbook instance.
693
+ * @param sheetname Worksheet name to validate.
694
+ *
695
+ * @return A #lxw_error.
696
+ *
697
+ * This function is used to validate a worksheet name according to the rules
698
+ * used by Excel:
699
+ *
700
+ * - The name is less than or equal to 31 UTF-8 characters.
701
+ * - The name doesn't contain any of the characters: ` [ ] : * ? / \ `
702
+ * - The name isn't already in use.
703
+ *
704
+ * @code
705
+ * lxw_error err = workbook_validate_worksheet_name(workbook, "Foglio");
706
+ * @endcode
707
+ *
708
+ * This function is called by `workbook_add_worksheet()` but it can be
709
+ * explicitly called by the user beforehand to ensure that the worksheet
710
+ * name is valid.
711
+ *
712
+ */
713
+ lxw_error workbook_validate_worksheet_name(lxw_workbook *workbook,
714
+ const char *sheetname);
715
+
716
+ void lxw_workbook_free(lxw_workbook *workbook);
717
+ void lxw_workbook_assemble_xml_file(lxw_workbook *workbook);
718
+ void lxw_workbook_set_default_xf_indices(lxw_workbook *workbook);
719
+
720
+ /* Declarations required for unit testing. */
721
+ #ifdef TESTING
722
+
723
+ STATIC void _workbook_xml_declaration(lxw_workbook *self);
724
+ STATIC void _write_workbook(lxw_workbook *self);
725
+ STATIC void _write_file_version(lxw_workbook *self);
726
+ STATIC void _write_workbook_pr(lxw_workbook *self);
727
+ STATIC void _write_book_views(lxw_workbook *self);
728
+ STATIC void _write_workbook_view(lxw_workbook *self);
729
+ STATIC void _write_sheet(lxw_workbook *self,
730
+ const char *name, uint32_t sheet_id, uint8_t hidden);
731
+ STATIC void _write_sheets(lxw_workbook *self);
732
+ STATIC void _write_calc_pr(lxw_workbook *self);
733
+
734
+ STATIC void _write_defined_name(lxw_workbook *self,
735
+ lxw_defined_name *define_name);
736
+ STATIC void _write_defined_names(lxw_workbook *self);
737
+
738
+ STATIC lxw_error _store_defined_name(lxw_workbook *self, const char *name,
739
+ const char *app_name,
740
+ const char *formula, int16_t index,
741
+ uint8_t hidden);
742
+
743
+ #endif /* TESTING */
744
+
745
+ /* *INDENT-OFF* */
746
+ #ifdef __cplusplus
747
+ }
748
+ #endif
749
+ /* *INDENT-ON* */
750
+
751
+ #endif /* __LXW_WORKBOOK_H__ */