fast_excel 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -2
  3. data/Makefile +14 -0
  4. data/README.md +7 -2
  5. data/Rakefile +10 -0
  6. data/extconf.rb +0 -0
  7. data/fast_excel.gemspec +3 -1
  8. data/lib/fast_excel/binding.rb +3 -7
  9. data/lib/rubygems_plugin.rb +3 -0
  10. data/libxlsxwriter/.gitignore +49 -0
  11. data/libxlsxwriter/.indent.pro +125 -0
  12. data/libxlsxwriter/.travis.yml +25 -0
  13. data/libxlsxwriter/CONTRIBUTING.md +226 -0
  14. data/libxlsxwriter/Changes.txt +557 -0
  15. data/libxlsxwriter/LICENSE.txt +89 -0
  16. data/libxlsxwriter/Makefile +156 -0
  17. data/libxlsxwriter/Readme.md +78 -0
  18. data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +30 -0
  19. data/libxlsxwriter/cocoapods/libxlsxwriter.modulemap +7 -0
  20. data/libxlsxwriter/include/xlsxwriter/app.h +79 -0
  21. data/libxlsxwriter/include/xlsxwriter/chart.h +3476 -0
  22. data/libxlsxwriter/include/xlsxwriter/common.h +372 -0
  23. data/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
  24. data/libxlsxwriter/include/xlsxwriter/core.h +51 -0
  25. data/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
  26. data/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
  27. data/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
  28. data/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
  29. data/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
  30. data/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
  31. data/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
  32. data/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
  33. data/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
  34. data/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +214 -0
  35. data/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
  36. data/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
  37. data/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
  38. data/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
  39. data/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
  40. data/libxlsxwriter/include/xlsxwriter/workbook.h +757 -0
  41. data/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
  42. data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
  43. data/libxlsxwriter/include/xlsxwriter.h +23 -0
  44. data/libxlsxwriter/lib/.gitignore +0 -0
  45. data/libxlsxwriter/libxlsxwriter.podspec +47 -0
  46. data/libxlsxwriter/src/Makefile +130 -0
  47. data/libxlsxwriter/src/app.c +443 -0
  48. data/libxlsxwriter/src/chart.c +6346 -0
  49. data/libxlsxwriter/src/content_types.c +345 -0
  50. data/libxlsxwriter/src/core.c +293 -0
  51. data/libxlsxwriter/src/custom.c +224 -0
  52. data/libxlsxwriter/src/drawing.c +746 -0
  53. data/libxlsxwriter/src/format.c +729 -0
  54. data/libxlsxwriter/src/hash_table.c +223 -0
  55. data/libxlsxwriter/src/packager.c +948 -0
  56. data/libxlsxwriter/src/relationships.c +245 -0
  57. data/libxlsxwriter/src/shared_strings.c +266 -0
  58. data/libxlsxwriter/src/styles.c +1088 -0
  59. data/libxlsxwriter/src/theme.c +348 -0
  60. data/libxlsxwriter/src/utility.c +515 -0
  61. data/libxlsxwriter/src/workbook.c +1930 -0
  62. data/libxlsxwriter/src/worksheet.c +5022 -0
  63. data/libxlsxwriter/src/xmlwriter.c +355 -0
  64. data/libxlsxwriter/third_party/minizip/Makefile +44 -0
  65. data/libxlsxwriter/third_party/minizip/Makefile.am +45 -0
  66. data/libxlsxwriter/third_party/minizip/Makefile.orig +25 -0
  67. data/libxlsxwriter/third_party/minizip/MiniZip64_Changes.txt +6 -0
  68. data/libxlsxwriter/third_party/minizip/MiniZip64_info.txt +74 -0
  69. data/libxlsxwriter/third_party/minizip/README.txt +5 -0
  70. data/libxlsxwriter/third_party/minizip/configure.ac +32 -0
  71. data/libxlsxwriter/third_party/minizip/crypt.h +131 -0
  72. data/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
  73. data/libxlsxwriter/third_party/minizip/ioapi.h +208 -0
  74. data/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
  75. data/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
  76. data/libxlsxwriter/third_party/minizip/make_vms.com +25 -0
  77. data/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
  78. data/libxlsxwriter/third_party/minizip/miniunzip.1 +63 -0
  79. data/libxlsxwriter/third_party/minizip/minizip.1 +46 -0
  80. data/libxlsxwriter/third_party/minizip/minizip.c +520 -0
  81. data/libxlsxwriter/third_party/minizip/minizip.pc.in +12 -0
  82. data/libxlsxwriter/third_party/minizip/mztools.c +291 -0
  83. data/libxlsxwriter/third_party/minizip/mztools.h +37 -0
  84. data/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
  85. data/libxlsxwriter/third_party/minizip/unzip.h +437 -0
  86. data/libxlsxwriter/third_party/minizip/zip.c +2007 -0
  87. data/libxlsxwriter/third_party/minizip/zip.h +367 -0
  88. data/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
  89. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
  90. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
  91. data/libxlsxwriter/version.txt +1 -0
  92. metadata +89 -6
  93. data/binaries/libxlsxwriter-alpine.so +0 -0
  94. data/binaries/libxlsxwriter-darwin.dylib +0 -0
  95. data/binaries/libxlsxwriter-glibc.so +0 -0
@@ -0,0 +1,757 @@
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 Gives default format for workbook, so you can edit it
382
+ * @return A lxw_worksheet object.
383
+ */
384
+ lxw_format *workbook_default_format(lxw_workbook *workbook);
385
+
386
+ /**
387
+ * @brief Create a new chart to be added to a worksheet:
388
+ *
389
+ * @param workbook Pointer to a lxw_workbook instance.
390
+ * @param chart_type The type of chart to be created. See #lxw_chart_type.
391
+ *
392
+ * @return A lxw_chart object.
393
+ *
394
+ * The `%workbook_add_chart()` function creates a new chart object that can
395
+ * be added to a worksheet:
396
+ *
397
+ * @code
398
+ * // Create a chart object.
399
+ * lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
400
+ *
401
+ * // Add data series to the chart.
402
+ * chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5");
403
+ * chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5");
404
+ * chart_add_series(chart, NULL, "Sheet1!$C$1:$C$5");
405
+ *
406
+ * // Insert the chart into the worksheet
407
+ * worksheet_insert_chart(worksheet, CELL("B7"), chart);
408
+ * @endcode
409
+ *
410
+ * The available chart types are defined in #lxw_chart_type. The types of
411
+ * charts that are supported are:
412
+ *
413
+ * | Chart type | Description |
414
+ * | :--------------------------------------- | :------------------------------------ |
415
+ * | #LXW_CHART_AREA | Area chart. |
416
+ * | #LXW_CHART_AREA_STACKED | Area chart - stacked. |
417
+ * | #LXW_CHART_AREA_STACKED_PERCENT | Area chart - percentage stacked. |
418
+ * | #LXW_CHART_BAR | Bar chart. |
419
+ * | #LXW_CHART_BAR_STACKED | Bar chart - stacked. |
420
+ * | #LXW_CHART_BAR_STACKED_PERCENT | Bar chart - percentage stacked. |
421
+ * | #LXW_CHART_COLUMN | Column chart. |
422
+ * | #LXW_CHART_COLUMN_STACKED | Column chart - stacked. |
423
+ * | #LXW_CHART_COLUMN_STACKED_PERCENT | Column chart - percentage stacked. |
424
+ * | #LXW_CHART_DOUGHNUT | Doughnut chart. |
425
+ * | #LXW_CHART_LINE | Line chart. |
426
+ * | #LXW_CHART_PIE | Pie chart. |
427
+ * | #LXW_CHART_SCATTER | Scatter chart. |
428
+ * | #LXW_CHART_SCATTER_STRAIGHT | Scatter chart - straight. |
429
+ * | #LXW_CHART_SCATTER_STRAIGHT_WITH_MARKERS | Scatter chart - straight with markers. |
430
+ * | #LXW_CHART_SCATTER_SMOOTH | Scatter chart - smooth. |
431
+ * | #LXW_CHART_SCATTER_SMOOTH_WITH_MARKERS | Scatter chart - smooth with markers. |
432
+ * | #LXW_CHART_RADAR | Radar chart. |
433
+ * | #LXW_CHART_RADAR_WITH_MARKERS | Radar chart - with markers. |
434
+ * | #LXW_CHART_RADAR_FILLED | Radar chart - filled. |
435
+ *
436
+ *
437
+ *
438
+ * See @ref chart.h for details.
439
+ */
440
+ lxw_chart *workbook_add_chart(lxw_workbook *workbook, uint8_t chart_type);
441
+
442
+ /**
443
+ * @brief Close the Workbook object and write the XLSX file.
444
+ *
445
+ * @param workbook Pointer to a lxw_workbook instance.
446
+ *
447
+ * @return A #lxw_error.
448
+ *
449
+ * The `%workbook_close()` function closes a Workbook object, writes the Excel
450
+ * file to disk, frees any memory allocated internally to the Workbook and
451
+ * frees the object itself.
452
+ *
453
+ * @code
454
+ * workbook_close(workbook);
455
+ * @endcode
456
+ *
457
+ * The `%workbook_close()` function returns any #lxw_error error codes
458
+ * encountered when creating the Excel file. The error code can be returned
459
+ * from the program main or the calling function:
460
+ *
461
+ * @code
462
+ * return workbook_close(workbook);
463
+ * @endcode
464
+ *
465
+ */
466
+ lxw_error workbook_close(lxw_workbook *workbook);
467
+
468
+ /**
469
+ * @brief Set the document properties such as Title, Author etc.
470
+ *
471
+ * @param workbook Pointer to a lxw_workbook instance.
472
+ * @param properties Document properties to set.
473
+ *
474
+ * @return A #lxw_error.
475
+ *
476
+ * The `%workbook_set_properties` function can be used to set the document
477
+ * properties of the Excel file created by `libxlsxwriter`. These properties
478
+ * are visible when you use the `Office Button -> Prepare -> Properties`
479
+ * option in Excel and are also available to external applications that read
480
+ * or index windows files.
481
+ *
482
+ * The properties that can be set are:
483
+ *
484
+ * - `title`
485
+ * - `subject`
486
+ * - `author`
487
+ * - `manager`
488
+ * - `company`
489
+ * - `category`
490
+ * - `keywords`
491
+ * - `comments`
492
+ * - `hyperlink_base`
493
+ *
494
+ * The properties are specified via a `lxw_doc_properties` struct. All the
495
+ * members are `char *` and they are all optional. An example of how to create
496
+ * and pass the properties is:
497
+ *
498
+ * @code
499
+ * // Create a properties structure and set some of the fields.
500
+ * lxw_doc_properties properties = {
501
+ * .title = "This is an example spreadsheet",
502
+ * .subject = "With document properties",
503
+ * .author = "John McNamara",
504
+ * .manager = "Dr. Heinz Doofenshmirtz",
505
+ * .company = "of Wolves",
506
+ * .category = "Example spreadsheets",
507
+ * .keywords = "Sample, Example, Properties",
508
+ * .comments = "Created with libxlsxwriter",
509
+ * .status = "Quo",
510
+ * };
511
+ *
512
+ * // Set the properties in the workbook.
513
+ * workbook_set_properties(workbook, &properties);
514
+ * @endcode
515
+ *
516
+ * @image html doc_properties.png
517
+ *
518
+ */
519
+ lxw_error workbook_set_properties(lxw_workbook *workbook,
520
+ lxw_doc_properties *properties);
521
+
522
+ /**
523
+ * @brief Set a custom document text property.
524
+ *
525
+ * @param workbook Pointer to a lxw_workbook instance.
526
+ * @param name The name of the custom property.
527
+ * @param value The value of the custom property.
528
+ *
529
+ * @return A #lxw_error.
530
+ *
531
+ * The `%workbook_set_custom_property_string()` function can be used to set one
532
+ * or more custom document text properties not covered by the standard
533
+ * properties in the `workbook_set_properties()` function above.
534
+ *
535
+ * For example:
536
+ *
537
+ * @code
538
+ * workbook_set_custom_property_string(workbook, "Checked by", "Eve");
539
+ * @endcode
540
+ *
541
+ * @image html custom_properties.png
542
+ *
543
+ * There are 4 `workbook_set_custom_property_string_*()` functions for each
544
+ * of the custom property types supported by Excel:
545
+ *
546
+ * - text/string: `workbook_set_custom_property_string()`
547
+ * - number: `workbook_set_custom_property_number()`
548
+ * - datetime: `workbook_set_custom_property_datetime()`
549
+ * - boolean: `workbook_set_custom_property_boolean()`
550
+ *
551
+ * **Note**: the name and value parameters are limited to 255 characters
552
+ * by Excel.
553
+ *
554
+ */
555
+ lxw_error workbook_set_custom_property_string(lxw_workbook *workbook,
556
+ const char *name,
557
+ const char *value);
558
+ /**
559
+ * @brief Set a custom document number property.
560
+ *
561
+ * @param workbook Pointer to a lxw_workbook instance.
562
+ * @param name The name of the custom property.
563
+ * @param value The value of the custom property.
564
+ *
565
+ * @return A #lxw_error.
566
+ *
567
+ * Set a custom document number property.
568
+ * See `workbook_set_custom_property_string()` above for details.
569
+ *
570
+ * @code
571
+ * workbook_set_custom_property_number(workbook, "Document number", 12345);
572
+ * @endcode
573
+ */
574
+ lxw_error workbook_set_custom_property_number(lxw_workbook *workbook,
575
+ const char *name, double value);
576
+
577
+ /* Undocumented since the user can use workbook_set_custom_property_number().
578
+ * Only implemented for file format completeness and testing.
579
+ */
580
+ lxw_error workbook_set_custom_property_integer(lxw_workbook *workbook,
581
+ const char *name,
582
+ int32_t value);
583
+
584
+ /**
585
+ * @brief Set a custom document boolean property.
586
+ *
587
+ * @param workbook Pointer to a lxw_workbook instance.
588
+ * @param name The name of the custom property.
589
+ * @param value The value of the custom property.
590
+ *
591
+ * @return A #lxw_error.
592
+ *
593
+ * Set a custom document boolean property.
594
+ * See `workbook_set_custom_property_string()` above for details.
595
+ *
596
+ * @code
597
+ * workbook_set_custom_property_boolean(workbook, "Has Review", 1);
598
+ * @endcode
599
+ */
600
+ lxw_error workbook_set_custom_property_boolean(lxw_workbook *workbook,
601
+ const char *name,
602
+ uint8_t value);
603
+ /**
604
+ * @brief Set a custom document date or time property.
605
+ *
606
+ * @param workbook Pointer to a lxw_workbook instance.
607
+ * @param name The name of the custom property.
608
+ * @param datetime The value of the custom property.
609
+ *
610
+ * @return A #lxw_error.
611
+ *
612
+ * Set a custom date or time number property.
613
+ * See `workbook_set_custom_property_string()` above for details.
614
+ *
615
+ * @code
616
+ * lxw_datetime datetime = {2016, 12, 1, 11, 55, 0.0};
617
+ *
618
+ * workbook_set_custom_property_datetime(workbook, "Date completed", &datetime);
619
+ * @endcode
620
+ */
621
+ lxw_error workbook_set_custom_property_datetime(lxw_workbook *workbook,
622
+ const char *name,
623
+ lxw_datetime *datetime);
624
+
625
+ /**
626
+ * @brief Create a defined name in the workbook to use as a variable.
627
+ *
628
+ * @param workbook Pointer to a lxw_workbook instance.
629
+ * @param name The defined name.
630
+ * @param formula The cell or range that the defined name refers to.
631
+ *
632
+ * @return A #lxw_error.
633
+ *
634
+ * This function is used to defined a name that can be used to represent a
635
+ * value, a single cell or a range of cells in a workbook: These defined names
636
+ * can then be used in formulas:
637
+ *
638
+ * @code
639
+ * workbook_define_name(workbook, "Exchange_rate", "=0.96");
640
+ * worksheet_write_formula(worksheet, 2, 1, "=Exchange_rate", NULL);
641
+ *
642
+ * @endcode
643
+ *
644
+ * @image html defined_name.png
645
+ *
646
+ * As in Excel a name defined like this is "global" to the workbook and can be
647
+ * referred to from any worksheet:
648
+ *
649
+ * @code
650
+ * // Global workbook name.
651
+ * workbook_define_name(workbook, "Sales", "=Sheet1!$G$1:$H$10");
652
+ * @endcode
653
+ *
654
+ * It is also possible to define a local/worksheet name by prefixing it with
655
+ * the sheet name using the syntax `'sheetname!definedname'`:
656
+ *
657
+ * @code
658
+ * // Local worksheet name.
659
+ * workbook_define_name(workbook, "Sheet2!Sales", "=Sheet2!$G$1:$G$10");
660
+ * @endcode
661
+ *
662
+ * If the sheet name contains spaces or special characters you must follow the
663
+ * Excel convention and enclose it in single quotes:
664
+ *
665
+ * @code
666
+ * workbook_define_name(workbook, "'New Data'!Sales", "=Sheet2!$G$1:$G$10");
667
+ * @endcode
668
+ *
669
+ * The rules for names in Excel are explained in the
670
+ * [Microsoft Office
671
+ documentation](http://office.microsoft.com/en-001/excel-help/define-and-use-names-in-formulas-HA010147120.aspx).
672
+ *
673
+ */
674
+ lxw_error workbook_define_name(lxw_workbook *workbook, const char *name,
675
+ const char *formula);
676
+
677
+ /**
678
+ * @brief Get a worksheet object from its name.
679
+ *
680
+ * @param workbook
681
+ * @param name
682
+ *
683
+ * @return A lxw_worksheet object.
684
+ *
685
+ * This function returns a lxw_worksheet object reference based on its name:
686
+ *
687
+ * @code
688
+ * worksheet = workbook_get_worksheet_by_name(workbook, "Sheet1");
689
+ * @endcode
690
+ *
691
+ */
692
+ lxw_worksheet *workbook_get_worksheet_by_name(lxw_workbook *workbook,
693
+ const char *name);
694
+
695
+ /**
696
+ * @brief Validate a worksheet name.
697
+ *
698
+ * @param workbook Pointer to a lxw_workbook instance.
699
+ * @param sheetname Worksheet name to validate.
700
+ *
701
+ * @return A #lxw_error.
702
+ *
703
+ * This function is used to validate a worksheet name according to the rules
704
+ * used by Excel:
705
+ *
706
+ * - The name is less than or equal to 31 UTF-8 characters.
707
+ * - The name doesn't contain any of the characters: ` [ ] : * ? / \ `
708
+ * - The name isn't already in use.
709
+ *
710
+ * @code
711
+ * lxw_error err = workbook_validate_worksheet_name(workbook, "Foglio");
712
+ * @endcode
713
+ *
714
+ * This function is called by `workbook_add_worksheet()` but it can be
715
+ * explicitly called by the user beforehand to ensure that the worksheet
716
+ * name is valid.
717
+ *
718
+ */
719
+ lxw_error workbook_validate_worksheet_name(lxw_workbook *workbook,
720
+ const char *sheetname);
721
+
722
+ void lxw_workbook_free(lxw_workbook *workbook);
723
+ void lxw_workbook_assemble_xml_file(lxw_workbook *workbook);
724
+ void lxw_workbook_set_default_xf_indices(lxw_workbook *workbook);
725
+
726
+ /* Declarations required for unit testing. */
727
+ #ifdef TESTING
728
+
729
+ STATIC void _workbook_xml_declaration(lxw_workbook *self);
730
+ STATIC void _write_workbook(lxw_workbook *self);
731
+ STATIC void _write_file_version(lxw_workbook *self);
732
+ STATIC void _write_workbook_pr(lxw_workbook *self);
733
+ STATIC void _write_book_views(lxw_workbook *self);
734
+ STATIC void _write_workbook_view(lxw_workbook *self);
735
+ STATIC void _write_sheet(lxw_workbook *self,
736
+ const char *name, uint32_t sheet_id, uint8_t hidden);
737
+ STATIC void _write_sheets(lxw_workbook *self);
738
+ STATIC void _write_calc_pr(lxw_workbook *self);
739
+
740
+ STATIC void _write_defined_name(lxw_workbook *self,
741
+ lxw_defined_name *define_name);
742
+ STATIC void _write_defined_names(lxw_workbook *self);
743
+
744
+ STATIC lxw_error _store_defined_name(lxw_workbook *self, const char *name,
745
+ const char *app_name,
746
+ const char *formula, int16_t index,
747
+ uint8_t hidden);
748
+
749
+ #endif /* TESTING */
750
+
751
+ /* *INDENT-OFF* */
752
+ #ifdef __cplusplus
753
+ }
754
+ #endif
755
+ /* *INDENT-ON* */
756
+
757
+ #endif /* __LXW_WORKBOOK_H__ */