xlsxwriter 0.0.3 → 0.0.4.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/xlsxwriter/libxlsxwriter/{LICENSE.txt → License.txt} +64 -3
- data/ext/xlsxwriter/libxlsxwriter/Makefile +42 -7
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/app.h +2 -2
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/chart.h +2481 -97
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/common.h +41 -2
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/core.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/format.h +5 -5
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/packager.h +8 -3
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/styles.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/utility.h +1 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/workbook.h +2 -2
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/worksheet.h +381 -1
- data/ext/xlsxwriter/libxlsxwriter/src/Makefile +25 -5
- data/ext/xlsxwriter/libxlsxwriter/src/app.c +17 -13
- data/ext/xlsxwriter/libxlsxwriter/src/chart.c +3903 -976
- data/ext/xlsxwriter/libxlsxwriter/src/content_types.c +18 -14
- data/ext/xlsxwriter/libxlsxwriter/src/core.c +9 -9
- data/ext/xlsxwriter/libxlsxwriter/src/format.c +2 -2
- data/ext/xlsxwriter/libxlsxwriter/src/packager.c +179 -95
- data/ext/xlsxwriter/libxlsxwriter/src/relationships.c +11 -8
- data/ext/xlsxwriter/libxlsxwriter/src/shared_strings.c +2 -0
- data/ext/xlsxwriter/libxlsxwriter/src/styles.c +10 -8
- data/ext/xlsxwriter/libxlsxwriter/src/utility.c +18 -1
- data/ext/xlsxwriter/libxlsxwriter/src/workbook.c +41 -25
- data/ext/xlsxwriter/libxlsxwriter/src/worksheet.c +672 -42
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/Makefile +6 -1
- data/lib/xlsxwriter/version.rb +1 -1
- data/lib/xlsxwriter/worksheet.rb +11 -5
- metadata +6 -6
@@ -72,24 +72,28 @@ lxw_content_types_free(lxw_content_types *content_types)
|
|
72
72
|
if (!content_types)
|
73
73
|
return;
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
if (content_types->default_types) {
|
76
|
+
while (!STAILQ_EMPTY(content_types->default_types)) {
|
77
|
+
default_type = STAILQ_FIRST(content_types->default_types);
|
78
|
+
STAILQ_REMOVE_HEAD(content_types->default_types, list_pointers);
|
79
|
+
free(default_type->key);
|
80
|
+
free(default_type->value);
|
81
|
+
free(default_type);
|
82
|
+
}
|
83
|
+
free(content_types->default_types);
|
81
84
|
}
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
if (content_types->overrides) {
|
87
|
+
while (!STAILQ_EMPTY(content_types->overrides)) {
|
88
|
+
override = STAILQ_FIRST(content_types->overrides);
|
89
|
+
STAILQ_REMOVE_HEAD(content_types->overrides, list_pointers);
|
90
|
+
free(override->key);
|
91
|
+
free(override->value);
|
92
|
+
free(override);
|
93
|
+
}
|
94
|
+
free(content_types->overrides);
|
89
95
|
}
|
90
96
|
|
91
|
-
free(content_types->default_types);
|
92
|
-
free(content_types->overrides);
|
93
97
|
free(content_types);
|
94
98
|
}
|
95
99
|
|
@@ -53,17 +53,17 @@ lxw_core_free(lxw_core *core)
|
|
53
53
|
* Convert a time_t struct to a ISO 8601 style "2010-01-01T00:00:00Z" date.
|
54
54
|
*/
|
55
55
|
static void
|
56
|
-
|
56
|
+
_datetime_to_iso8601_date(time_t *timer, char *str, size_t size)
|
57
57
|
{
|
58
|
-
struct tm *
|
58
|
+
struct tm *tmp_datetime;
|
59
59
|
time_t current_time = time(NULL);
|
60
60
|
|
61
61
|
if (*timer)
|
62
|
-
|
62
|
+
tmp_datetime = gmtime(timer);
|
63
63
|
else
|
64
|
-
|
64
|
+
tmp_datetime = gmtime(¤t_time);
|
65
65
|
|
66
|
-
strftime(str, size - 1, "%Y-%m-%dT%H:%M:%SZ",
|
66
|
+
strftime(str, size - 1, "%Y-%m-%dT%H:%M:%SZ", tmp_datetime);
|
67
67
|
}
|
68
68
|
|
69
69
|
/*****************************************************************************
|
@@ -144,8 +144,8 @@ _write_dcterms_created(lxw_core *self)
|
|
144
144
|
struct xml_attribute *attribute;
|
145
145
|
char datetime[LXW_ATTR_32];
|
146
146
|
|
147
|
-
|
148
|
-
|
147
|
+
_datetime_to_iso8601_date(&self->properties->created, datetime,
|
148
|
+
LXW_ATTR_32);
|
149
149
|
|
150
150
|
LXW_INIT_ATTRIBUTES();
|
151
151
|
LXW_PUSH_ATTRIBUTES_STR("xsi:type", "dcterms:W3CDTF");
|
@@ -166,8 +166,8 @@ _write_dcterms_modified(lxw_core *self)
|
|
166
166
|
struct xml_attribute *attribute;
|
167
167
|
char datetime[LXW_ATTR_32];
|
168
168
|
|
169
|
-
|
170
|
-
|
169
|
+
_datetime_to_iso8601_date(&self->properties->created, datetime,
|
170
|
+
LXW_ATTR_32);
|
171
171
|
|
172
172
|
LXW_INIT_ATTRIBUTES();
|
173
173
|
LXW_PUSH_ATTRIBUTES_STR("xsi:type", "dcterms:W3CDTF");
|
@@ -38,7 +38,7 @@ lxw_format_new()
|
|
38
38
|
format->font_index = 0;
|
39
39
|
format->has_font = LXW_FALSE;
|
40
40
|
format->has_dxf_font = LXW_FALSE;
|
41
|
-
format->font_size = 11;
|
41
|
+
format->font_size = 11.0;
|
42
42
|
format->bold = LXW_FALSE;
|
43
43
|
format->italic = LXW_FALSE;
|
44
44
|
format->font_color = LXW_COLOR_UNSET;
|
@@ -309,7 +309,7 @@ format_set_font_name(lxw_format *self, const char *font_name)
|
|
309
309
|
* Set the font_size property.
|
310
310
|
*/
|
311
311
|
void
|
312
|
-
format_set_font_size(lxw_format *self,
|
312
|
+
format_set_font_size(lxw_format *self, double size)
|
313
313
|
{
|
314
314
|
|
315
315
|
if (size >= LXW_MIN_FONT_SIZE && size <= LXW_MAX_FONT_SIZE)
|
@@ -12,8 +12,8 @@
|
|
12
12
|
#include "xlsxwriter/hash_table.h"
|
13
13
|
#include "xlsxwriter/utility.h"
|
14
14
|
|
15
|
-
STATIC
|
16
|
-
|
15
|
+
STATIC lxw_error _add_file_to_zip(lxw_packager *self, FILE * file,
|
16
|
+
const char *filename);
|
17
17
|
|
18
18
|
/*
|
19
19
|
* Forward declarations.
|
@@ -37,7 +37,12 @@ STATIC uint8_t _add_file_to_zip(lxw_packager *self, FILE * file,
|
|
37
37
|
#undef SLIST_ENTRY
|
38
38
|
|
39
39
|
#include <windows.h>
|
40
|
-
|
40
|
+
|
41
|
+
#ifdef USE_SYSTEM_MINIZIP
|
42
|
+
#include "minizip/iowin32.h"
|
43
|
+
#else
|
44
|
+
#include "../third_party/minizip/iowin32.h"
|
45
|
+
#endif
|
41
46
|
|
42
47
|
zipFile
|
43
48
|
_open_zipfile_win32(const char *filename)
|
@@ -132,11 +137,11 @@ lxw_packager_free(lxw_packager *packager)
|
|
132
137
|
/*
|
133
138
|
* Write the workbook.xml file.
|
134
139
|
*/
|
135
|
-
STATIC
|
140
|
+
STATIC lxw_error
|
136
141
|
_write_workbook_file(lxw_packager *self)
|
137
142
|
{
|
138
143
|
lxw_workbook *workbook = self->workbook;
|
139
|
-
|
144
|
+
lxw_error err;
|
140
145
|
|
141
146
|
workbook->file = lxw_tmpfile(self->tmpdir);
|
142
147
|
if (!workbook->file)
|
@@ -149,20 +154,20 @@ _write_workbook_file(lxw_packager *self)
|
|
149
154
|
|
150
155
|
fclose(workbook->file);
|
151
156
|
|
152
|
-
return
|
157
|
+
return LXW_NO_ERROR;
|
153
158
|
}
|
154
159
|
|
155
160
|
/*
|
156
161
|
* Write the worksheet files.
|
157
162
|
*/
|
158
|
-
STATIC
|
163
|
+
STATIC lxw_error
|
159
164
|
_write_worksheet_files(lxw_packager *self)
|
160
165
|
{
|
161
166
|
lxw_workbook *workbook = self->workbook;
|
162
167
|
lxw_worksheet *worksheet;
|
163
168
|
char sheetname[LXW_FILENAME_LENGTH] = { 0 };
|
164
169
|
uint16_t index = 1;
|
165
|
-
|
170
|
+
lxw_error err;
|
166
171
|
|
167
172
|
STAILQ_FOREACH(worksheet, workbook->worksheets, list_pointers) {
|
168
173
|
lxw_snprintf(sheetname, LXW_FILENAME_LENGTH,
|
@@ -183,19 +188,20 @@ _write_worksheet_files(lxw_packager *self)
|
|
183
188
|
fclose(worksheet->file);
|
184
189
|
}
|
185
190
|
|
186
|
-
return
|
191
|
+
return LXW_NO_ERROR;
|
187
192
|
}
|
188
193
|
|
189
194
|
/*
|
190
195
|
* Write the /xl/media/image?.xml files.
|
191
196
|
*/
|
192
|
-
STATIC
|
197
|
+
STATIC lxw_error
|
193
198
|
_write_image_files(lxw_packager *self)
|
194
199
|
{
|
195
200
|
lxw_workbook *workbook = self->workbook;
|
196
201
|
lxw_worksheet *worksheet;
|
197
202
|
lxw_image_options *image;
|
198
|
-
|
203
|
+
lxw_error err;
|
204
|
+
FILE *image_stream;
|
199
205
|
|
200
206
|
char filename[LXW_FILENAME_LENGTH] = { 0 };
|
201
207
|
uint16_t index = 1;
|
@@ -210,29 +216,36 @@ _write_image_files(lxw_packager *self)
|
|
210
216
|
lxw_snprintf(filename, LXW_FILENAME_LENGTH,
|
211
217
|
"xl/media/image%d.%s", index++, image->extension);
|
212
218
|
|
213
|
-
|
219
|
+
/* Check that the image file exists and can be opened. */
|
220
|
+
image_stream = fopen(image->filename, "rb");
|
221
|
+
if (!image_stream) {
|
222
|
+
LXW_WARN_FORMAT1("Error adding image to xlsx file: file "
|
223
|
+
"doesn't exist or can't be opened: %s.",
|
224
|
+
image->filename);
|
225
|
+
return LXW_ERROR_CREATING_TMPFILE;
|
226
|
+
}
|
214
227
|
|
215
|
-
err = _add_file_to_zip(self,
|
228
|
+
err = _add_file_to_zip(self, image_stream, filename);
|
216
229
|
RETURN_ON_ERROR(err);
|
217
230
|
|
218
|
-
fclose(
|
231
|
+
fclose(image_stream);
|
219
232
|
}
|
220
233
|
}
|
221
234
|
|
222
|
-
return
|
235
|
+
return LXW_NO_ERROR;
|
223
236
|
}
|
224
237
|
|
225
238
|
/*
|
226
239
|
* Write the chart files.
|
227
240
|
*/
|
228
|
-
STATIC
|
241
|
+
STATIC lxw_error
|
229
242
|
_write_chart_files(lxw_packager *self)
|
230
243
|
{
|
231
244
|
lxw_workbook *workbook = self->workbook;
|
232
245
|
lxw_chart *chart;
|
233
246
|
char sheetname[LXW_FILENAME_LENGTH] = { 0 };
|
234
247
|
uint16_t index = 1;
|
235
|
-
|
248
|
+
lxw_error err;
|
236
249
|
|
237
250
|
STAILQ_FOREACH(chart, workbook->ordered_charts, ordered_list_pointers) {
|
238
251
|
|
@@ -253,13 +266,13 @@ _write_chart_files(lxw_packager *self)
|
|
253
266
|
fclose(chart->file);
|
254
267
|
}
|
255
268
|
|
256
|
-
return
|
269
|
+
return LXW_NO_ERROR;
|
257
270
|
}
|
258
271
|
|
259
272
|
/*
|
260
273
|
* Write the drawing files.
|
261
274
|
*/
|
262
|
-
STATIC
|
275
|
+
STATIC lxw_error
|
263
276
|
_write_drawing_files(lxw_packager *self)
|
264
277
|
{
|
265
278
|
lxw_workbook *workbook = self->workbook;
|
@@ -267,7 +280,7 @@ _write_drawing_files(lxw_packager *self)
|
|
267
280
|
lxw_drawing *drawing;
|
268
281
|
char filename[LXW_FILENAME_LENGTH] = { 0 };
|
269
282
|
uint16_t index = 1;
|
270
|
-
|
283
|
+
lxw_error err;
|
271
284
|
|
272
285
|
STAILQ_FOREACH(worksheet, workbook->worksheets, list_pointers) {
|
273
286
|
drawing = worksheet->drawing;
|
@@ -290,21 +303,21 @@ _write_drawing_files(lxw_packager *self)
|
|
290
303
|
}
|
291
304
|
}
|
292
305
|
|
293
|
-
return
|
306
|
+
return LXW_NO_ERROR;
|
294
307
|
}
|
295
308
|
|
296
309
|
/*
|
297
310
|
* Write the sharedStrings.xml file.
|
298
311
|
*/
|
299
|
-
STATIC
|
312
|
+
STATIC lxw_error
|
300
313
|
_write_shared_strings_file(lxw_packager *self)
|
301
314
|
{
|
302
315
|
lxw_sst *sst = self->workbook->sst;
|
303
|
-
|
316
|
+
lxw_error err;
|
304
317
|
|
305
318
|
/* Skip the sharedStrings file if there are no shared strings. */
|
306
319
|
if (!sst->string_count)
|
307
|
-
return
|
320
|
+
return LXW_NO_ERROR;
|
308
321
|
|
309
322
|
sst->file = lxw_tmpfile(self->tmpdir);
|
310
323
|
if (!sst->file)
|
@@ -317,28 +330,36 @@ _write_shared_strings_file(lxw_packager *self)
|
|
317
330
|
|
318
331
|
fclose(sst->file);
|
319
332
|
|
320
|
-
return
|
333
|
+
return LXW_NO_ERROR;
|
321
334
|
}
|
322
335
|
|
323
336
|
/*
|
324
337
|
* Write the app.xml file.
|
325
338
|
*/
|
326
|
-
STATIC
|
339
|
+
STATIC lxw_error
|
327
340
|
_write_app_file(lxw_packager *self)
|
328
341
|
{
|
329
342
|
lxw_workbook *workbook = self->workbook;
|
330
343
|
lxw_worksheet *worksheet;
|
331
344
|
lxw_defined_name *defined_name;
|
332
|
-
lxw_app *app
|
345
|
+
lxw_app *app;
|
333
346
|
uint16_t named_range_count = 0;
|
334
347
|
char *autofilter;
|
335
348
|
char *has_range;
|
336
349
|
char number[LXW_ATTR_32] = { 0 };
|
337
|
-
|
350
|
+
lxw_error err = LXW_NO_ERROR;
|
351
|
+
|
352
|
+
app = lxw_app_new();
|
353
|
+
if (!app) {
|
354
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
355
|
+
goto mem_error;
|
356
|
+
}
|
338
357
|
|
339
358
|
app->file = lxw_tmpfile(self->tmpdir);
|
340
|
-
if (!app->file)
|
341
|
-
|
359
|
+
if (!app->file) {
|
360
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
361
|
+
goto mem_error;
|
362
|
+
}
|
342
363
|
|
343
364
|
lxw_snprintf(number, LXW_ATTR_32, "%d", self->workbook->num_sheets);
|
344
365
|
|
@@ -373,114 +394,144 @@ _write_app_file(lxw_packager *self)
|
|
373
394
|
lxw_app_assemble_xml_file(app);
|
374
395
|
|
375
396
|
err = _add_file_to_zip(self, app->file, "docProps/app.xml");
|
376
|
-
RETURN_ON_ERROR(err);
|
377
397
|
|
378
398
|
fclose(app->file);
|
379
399
|
|
400
|
+
mem_error:
|
380
401
|
lxw_app_free(app);
|
381
402
|
|
382
|
-
return
|
403
|
+
return err;
|
383
404
|
}
|
384
405
|
|
385
406
|
/*
|
386
407
|
* Write the core.xml file.
|
387
408
|
*/
|
388
|
-
STATIC
|
409
|
+
STATIC lxw_error
|
389
410
|
_write_core_file(lxw_packager *self)
|
390
411
|
{
|
412
|
+
lxw_error err = LXW_NO_ERROR;
|
391
413
|
lxw_core *core = lxw_core_new();
|
392
|
-
|
414
|
+
|
415
|
+
if (!core) {
|
416
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
417
|
+
goto mem_error;
|
418
|
+
}
|
393
419
|
|
394
420
|
core->file = lxw_tmpfile(self->tmpdir);
|
395
|
-
if (!core->file)
|
396
|
-
|
421
|
+
if (!core->file) {
|
422
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
423
|
+
goto mem_error;
|
424
|
+
}
|
397
425
|
|
398
426
|
core->properties = self->workbook->properties;
|
399
427
|
|
400
428
|
lxw_core_assemble_xml_file(core);
|
401
429
|
|
402
430
|
err = _add_file_to_zip(self, core->file, "docProps/core.xml");
|
403
|
-
RETURN_ON_ERROR(err);
|
404
431
|
|
405
432
|
fclose(core->file);
|
406
433
|
|
434
|
+
mem_error:
|
407
435
|
lxw_core_free(core);
|
408
436
|
|
409
|
-
return
|
437
|
+
return err;
|
410
438
|
}
|
411
439
|
|
412
440
|
/*
|
413
441
|
* Write the custom.xml file.
|
414
442
|
*/
|
415
|
-
STATIC
|
443
|
+
STATIC lxw_error
|
416
444
|
_write_custom_file(lxw_packager *self)
|
417
445
|
{
|
418
446
|
lxw_custom *custom;
|
419
|
-
|
447
|
+
lxw_error err = LXW_NO_ERROR;
|
420
448
|
|
421
449
|
if (STAILQ_EMPTY(self->workbook->custom_properties))
|
422
|
-
return
|
450
|
+
return LXW_NO_ERROR;
|
423
451
|
|
424
452
|
custom = lxw_custom_new();
|
453
|
+
if (!custom) {
|
454
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
455
|
+
goto mem_error;
|
456
|
+
}
|
425
457
|
|
426
458
|
custom->file = lxw_tmpfile(self->tmpdir);
|
427
|
-
if (!custom->file)
|
428
|
-
|
459
|
+
if (!custom->file) {
|
460
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
461
|
+
goto mem_error;
|
462
|
+
}
|
429
463
|
|
430
464
|
custom->custom_properties = self->workbook->custom_properties;
|
431
465
|
|
432
466
|
lxw_custom_assemble_xml_file(custom);
|
433
467
|
|
434
468
|
err = _add_file_to_zip(self, custom->file, "docProps/custom.xml");
|
435
|
-
RETURN_ON_ERROR(err);
|
436
469
|
|
437
470
|
fclose(custom->file);
|
438
471
|
|
472
|
+
mem_error:
|
439
473
|
lxw_custom_free(custom);
|
440
|
-
|
441
|
-
return 0;
|
474
|
+
return err;
|
442
475
|
}
|
443
476
|
|
444
477
|
/*
|
445
478
|
* Write the theme.xml file.
|
446
479
|
*/
|
447
|
-
STATIC
|
480
|
+
STATIC lxw_error
|
448
481
|
_write_theme_file(lxw_packager *self)
|
449
482
|
{
|
483
|
+
lxw_error err = LXW_NO_ERROR;
|
450
484
|
lxw_theme *theme = lxw_theme_new();
|
451
|
-
|
485
|
+
|
486
|
+
if (!theme) {
|
487
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
488
|
+
goto mem_error;
|
489
|
+
}
|
452
490
|
|
453
491
|
theme->file = lxw_tmpfile(self->tmpdir);
|
454
|
-
if (!theme->file)
|
455
|
-
|
492
|
+
if (!theme->file) {
|
493
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
494
|
+
goto mem_error;
|
495
|
+
}
|
456
496
|
|
457
497
|
lxw_theme_assemble_xml_file(theme);
|
458
498
|
|
459
499
|
err = _add_file_to_zip(self, theme->file, "xl/theme/theme1.xml");
|
460
|
-
RETURN_ON_ERROR(err);
|
461
500
|
|
462
501
|
fclose(theme->file);
|
463
502
|
|
503
|
+
mem_error:
|
464
504
|
lxw_theme_free(theme);
|
465
505
|
|
466
|
-
return
|
506
|
+
return err;
|
467
507
|
}
|
468
508
|
|
469
509
|
/*
|
470
510
|
* Write the styles.xml file.
|
471
511
|
*/
|
472
|
-
STATIC
|
512
|
+
STATIC lxw_error
|
473
513
|
_write_styles_file(lxw_packager *self)
|
474
514
|
{
|
475
515
|
lxw_styles *styles = lxw_styles_new();
|
476
516
|
lxw_hash_element *hash_element;
|
477
|
-
|
517
|
+
lxw_error err = LXW_NO_ERROR;
|
518
|
+
|
519
|
+
if (!styles) {
|
520
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
521
|
+
goto mem_error;
|
522
|
+
}
|
478
523
|
|
479
524
|
/* Copy the unique and in-use formats from the workbook to the styles
|
480
525
|
* xf_format list. */
|
481
526
|
LXW_FOREACH_ORDERED(hash_element, self->workbook->used_xf_formats) {
|
482
527
|
lxw_format *workbook_format = (lxw_format *) hash_element->value;
|
483
528
|
lxw_format *style_format = lxw_format_new();
|
529
|
+
|
530
|
+
if (!style_format) {
|
531
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
532
|
+
goto mem_error;
|
533
|
+
}
|
534
|
+
|
484
535
|
memcpy(style_format, workbook_format, sizeof(lxw_format));
|
485
536
|
STAILQ_INSERT_TAIL(styles->xf_formats, style_format, list_pointers);
|
486
537
|
}
|
@@ -492,25 +543,27 @@ _write_styles_file(lxw_packager *self)
|
|
492
543
|
styles->xf_count = self->workbook->used_xf_formats->unique_count;
|
493
544
|
|
494
545
|
styles->file = lxw_tmpfile(self->tmpdir);
|
495
|
-
if (!styles->file)
|
496
|
-
|
546
|
+
if (!styles->file) {
|
547
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
548
|
+
goto mem_error;
|
549
|
+
}
|
497
550
|
|
498
551
|
lxw_styles_assemble_xml_file(styles);
|
499
552
|
|
500
553
|
err = _add_file_to_zip(self, styles->file, "xl/styles.xml");
|
501
|
-
RETURN_ON_ERROR(err);
|
502
554
|
|
503
555
|
fclose(styles->file);
|
504
556
|
|
557
|
+
mem_error:
|
505
558
|
lxw_styles_free(styles);
|
506
559
|
|
507
|
-
return
|
560
|
+
return err;
|
508
561
|
}
|
509
562
|
|
510
563
|
/*
|
511
564
|
* Write the ContentTypes.xml file.
|
512
565
|
*/
|
513
|
-
STATIC
|
566
|
+
STATIC lxw_error
|
514
567
|
_write_content_types_file(lxw_packager *self)
|
515
568
|
{
|
516
569
|
lxw_content_types *content_types = lxw_content_types_new();
|
@@ -518,11 +571,18 @@ _write_content_types_file(lxw_packager *self)
|
|
518
571
|
lxw_worksheet *worksheet;
|
519
572
|
char filename[LXW_MAX_ATTRIBUTE_LENGTH] = { 0 };
|
520
573
|
uint16_t index = 1;
|
521
|
-
|
574
|
+
lxw_error err = LXW_NO_ERROR;
|
575
|
+
|
576
|
+
if (!content_types) {
|
577
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
578
|
+
goto mem_error;
|
579
|
+
}
|
522
580
|
|
523
581
|
content_types->file = lxw_tmpfile(self->tmpdir);
|
524
|
-
if (!content_types->file)
|
525
|
-
|
582
|
+
if (!content_types->file) {
|
583
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
584
|
+
goto mem_error;
|
585
|
+
}
|
526
586
|
|
527
587
|
if (workbook->has_png)
|
528
588
|
lxw_ct_add_default(content_types, "png", "image/png");
|
@@ -560,19 +620,19 @@ _write_content_types_file(lxw_packager *self)
|
|
560
620
|
lxw_content_types_assemble_xml_file(content_types);
|
561
621
|
|
562
622
|
err = _add_file_to_zip(self, content_types->file, "[Content_Types].xml");
|
563
|
-
RETURN_ON_ERROR(err);
|
564
623
|
|
565
624
|
fclose(content_types->file);
|
566
625
|
|
626
|
+
mem_error:
|
567
627
|
lxw_content_types_free(content_types);
|
568
628
|
|
569
|
-
return
|
629
|
+
return err;
|
570
630
|
}
|
571
631
|
|
572
632
|
/*
|
573
633
|
* Write the workbook .rels xml file.
|
574
634
|
*/
|
575
|
-
STATIC
|
635
|
+
STATIC lxw_error
|
576
636
|
_write_workbook_rels_file(lxw_packager *self)
|
577
637
|
{
|
578
638
|
lxw_relationships *rels = lxw_relationships_new();
|
@@ -580,11 +640,18 @@ _write_workbook_rels_file(lxw_packager *self)
|
|
580
640
|
lxw_worksheet *worksheet;
|
581
641
|
char sheetname[LXW_FILENAME_LENGTH] = { 0 };
|
582
642
|
uint16_t index = 1;
|
583
|
-
|
643
|
+
lxw_error err = LXW_NO_ERROR;
|
644
|
+
|
645
|
+
if (!rels) {
|
646
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
647
|
+
goto mem_error;
|
648
|
+
}
|
584
649
|
|
585
650
|
rels->file = lxw_tmpfile(self->tmpdir);
|
586
|
-
if (!rels->file)
|
587
|
-
|
651
|
+
if (!rels->file) {
|
652
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
653
|
+
goto mem_error;
|
654
|
+
}
|
588
655
|
|
589
656
|
STAILQ_FOREACH(worksheet, workbook->worksheets, list_pointers) {
|
590
657
|
lxw_snprintf(sheetname, LXW_FILENAME_LENGTH, "worksheets/sheet%d.xml",
|
@@ -602,19 +669,20 @@ _write_workbook_rels_file(lxw_packager *self)
|
|
602
669
|
lxw_relationships_assemble_xml_file(rels);
|
603
670
|
|
604
671
|
err = _add_file_to_zip(self, rels->file, "xl/_rels/workbook.xml.rels");
|
605
|
-
RETURN_ON_ERROR(err);
|
606
672
|
|
607
673
|
fclose(rels->file);
|
674
|
+
|
675
|
+
mem_error:
|
608
676
|
lxw_free_relationships(rels);
|
609
677
|
|
610
|
-
return
|
678
|
+
return err;
|
611
679
|
}
|
612
680
|
|
613
681
|
/*
|
614
682
|
* Write the worksheet .rels files for worksheets that contain links to
|
615
683
|
* external data such as hyperlinks or drawings.
|
616
684
|
*/
|
617
|
-
STATIC
|
685
|
+
STATIC lxw_error
|
618
686
|
_write_worksheet_rels_file(lxw_packager *self)
|
619
687
|
{
|
620
688
|
lxw_relationships *rels;
|
@@ -623,7 +691,7 @@ _write_worksheet_rels_file(lxw_packager *self)
|
|
623
691
|
lxw_worksheet *worksheet;
|
624
692
|
char sheetname[LXW_FILENAME_LENGTH] = { 0 };
|
625
693
|
uint16_t index = 0;
|
626
|
-
|
694
|
+
lxw_error err;
|
627
695
|
|
628
696
|
STAILQ_FOREACH(worksheet, workbook->worksheets, list_pointers) {
|
629
697
|
|
@@ -634,9 +702,12 @@ _write_worksheet_rels_file(lxw_packager *self)
|
|
634
702
|
continue;
|
635
703
|
|
636
704
|
rels = lxw_relationships_new();
|
705
|
+
|
637
706
|
rels->file = lxw_tmpfile(self->tmpdir);
|
638
|
-
if (!rels->file)
|
707
|
+
if (!rels->file) {
|
708
|
+
lxw_free_relationships(rels);
|
639
709
|
return LXW_ERROR_CREATING_TMPFILE;
|
710
|
+
}
|
640
711
|
|
641
712
|
STAILQ_FOREACH(rel, worksheet->external_hyperlinks, list_pointers) {
|
642
713
|
lxw_add_worksheet_relationship(rels, rel->type, rel->target,
|
@@ -654,20 +725,21 @@ _write_worksheet_rels_file(lxw_packager *self)
|
|
654
725
|
lxw_relationships_assemble_xml_file(rels);
|
655
726
|
|
656
727
|
err = _add_file_to_zip(self, rels->file, sheetname);
|
657
|
-
RETURN_ON_ERROR(err);
|
658
728
|
|
659
729
|
fclose(rels->file);
|
660
730
|
lxw_free_relationships(rels);
|
731
|
+
|
732
|
+
RETURN_ON_ERROR(err);
|
661
733
|
}
|
662
734
|
|
663
|
-
return
|
735
|
+
return LXW_NO_ERROR;
|
664
736
|
}
|
665
737
|
|
666
738
|
/*
|
667
739
|
* Write the drawing .rels files for worksheets that contain charts or
|
668
740
|
* drawings.
|
669
741
|
*/
|
670
|
-
STATIC
|
742
|
+
STATIC lxw_error
|
671
743
|
_write_drawing_rels_file(lxw_packager *self)
|
672
744
|
{
|
673
745
|
lxw_relationships *rels;
|
@@ -676,7 +748,7 @@ _write_drawing_rels_file(lxw_packager *self)
|
|
676
748
|
lxw_worksheet *worksheet;
|
677
749
|
char sheetname[LXW_FILENAME_LENGTH] = { 0 };
|
678
750
|
uint16_t index = 1;
|
679
|
-
|
751
|
+
lxw_error err;
|
680
752
|
|
681
753
|
STAILQ_FOREACH(worksheet, workbook->worksheets, list_pointers) {
|
682
754
|
|
@@ -684,9 +756,12 @@ _write_drawing_rels_file(lxw_packager *self)
|
|
684
756
|
continue;
|
685
757
|
|
686
758
|
rels = lxw_relationships_new();
|
759
|
+
|
687
760
|
rels->file = lxw_tmpfile(self->tmpdir);
|
688
|
-
if (!rels->file)
|
761
|
+
if (!rels->file) {
|
762
|
+
lxw_free_relationships(rels);
|
689
763
|
return LXW_ERROR_CREATING_TMPFILE;
|
764
|
+
}
|
690
765
|
|
691
766
|
STAILQ_FOREACH(rel, worksheet->drawing_links, list_pointers) {
|
692
767
|
lxw_add_worksheet_relationship(rels, rel->type, rel->target,
|
@@ -700,27 +775,35 @@ _write_drawing_rels_file(lxw_packager *self)
|
|
700
775
|
lxw_relationships_assemble_xml_file(rels);
|
701
776
|
|
702
777
|
err = _add_file_to_zip(self, rels->file, sheetname);
|
703
|
-
RETURN_ON_ERROR(err);
|
704
778
|
|
705
779
|
fclose(rels->file);
|
706
780
|
lxw_free_relationships(rels);
|
781
|
+
|
782
|
+
RETURN_ON_ERROR(err);
|
707
783
|
}
|
708
784
|
|
709
|
-
return
|
785
|
+
return LXW_NO_ERROR;
|
710
786
|
}
|
711
787
|
|
712
788
|
/*
|
713
789
|
* Write the _rels/.rels xml file.
|
714
790
|
*/
|
715
|
-
STATIC
|
791
|
+
STATIC lxw_error
|
716
792
|
_write_root_rels_file(lxw_packager *self)
|
717
793
|
{
|
718
794
|
lxw_relationships *rels = lxw_relationships_new();
|
719
|
-
|
795
|
+
lxw_error err = LXW_NO_ERROR;
|
796
|
+
|
797
|
+
if (!rels) {
|
798
|
+
err = LXW_ERROR_MEMORY_MALLOC_FAILED;
|
799
|
+
goto mem_error;
|
800
|
+
}
|
720
801
|
|
721
802
|
rels->file = lxw_tmpfile(self->tmpdir);
|
722
|
-
if (!rels->file)
|
723
|
-
|
803
|
+
if (!rels->file) {
|
804
|
+
err = LXW_ERROR_CREATING_TMPFILE;
|
805
|
+
goto mem_error;
|
806
|
+
}
|
724
807
|
|
725
808
|
lxw_add_document_relationship(rels, "/officeDocument", "xl/workbook.xml");
|
726
809
|
|
@@ -739,13 +822,13 @@ _write_root_rels_file(lxw_packager *self)
|
|
739
822
|
lxw_relationships_assemble_xml_file(rels);
|
740
823
|
|
741
824
|
err = _add_file_to_zip(self, rels->file, "_rels/.rels");
|
742
|
-
RETURN_ON_ERROR(err);
|
743
825
|
|
744
826
|
fclose(rels->file);
|
745
827
|
|
828
|
+
mem_error:
|
746
829
|
lxw_free_relationships(rels);
|
747
830
|
|
748
|
-
return
|
831
|
+
return err;
|
749
832
|
}
|
750
833
|
|
751
834
|
/*****************************************************************************
|
@@ -754,7 +837,7 @@ _write_root_rels_file(lxw_packager *self)
|
|
754
837
|
*
|
755
838
|
****************************************************************************/
|
756
839
|
|
757
|
-
STATIC
|
840
|
+
STATIC lxw_error
|
758
841
|
_add_file_to_zip(lxw_packager *self, FILE * file, const char *filename)
|
759
842
|
{
|
760
843
|
int16_t error = ZIP_OK;
|
@@ -809,16 +892,17 @@ _add_file_to_zip(lxw_packager *self, FILE * file, const char *filename)
|
|
809
892
|
}
|
810
893
|
}
|
811
894
|
|
812
|
-
return
|
895
|
+
return LXW_NO_ERROR;
|
813
896
|
}
|
814
897
|
|
815
898
|
/*
|
816
899
|
* Write the xml files that make up the XLXS OPC package.
|
817
900
|
*/
|
818
|
-
|
901
|
+
lxw_error
|
819
902
|
lxw_create_package(lxw_packager *self)
|
820
903
|
{
|
821
|
-
|
904
|
+
lxw_error error;
|
905
|
+
int8_t zip_error;
|
822
906
|
|
823
907
|
error = _write_worksheet_files(self);
|
824
908
|
RETURN_ON_ERROR(error);
|
@@ -863,15 +947,15 @@ lxw_create_package(lxw_packager *self)
|
|
863
947
|
RETURN_ON_ERROR(error);
|
864
948
|
|
865
949
|
error = _write_image_files(self);
|
866
|
-
RETURN_ON_ERROR(error)
|
950
|
+
RETURN_ON_ERROR(error);
|
867
951
|
|
868
952
|
error = _write_root_rels_file(self);
|
869
953
|
RETURN_ON_ERROR(error);
|
870
954
|
|
871
|
-
|
872
|
-
if (
|
873
|
-
RETURN_ON_ZIP_ERROR(
|
955
|
+
zip_error = zipClose(self->zipfile, NULL);
|
956
|
+
if (zip_error) {
|
957
|
+
RETURN_ON_ZIP_ERROR(zip_error, LXW_ERROR_ZIP_CLOSE);
|
874
958
|
}
|
875
959
|
|
876
|
-
return
|
960
|
+
return LXW_NO_ERROR;
|
877
961
|
}
|