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,178 @@
1
+ /*
2
+ * libxlsxwriter
3
+ *
4
+ * Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
5
+ *
6
+ * xmlwriter - A libxlsxwriter library for creating Excel XLSX
7
+ * XML files.
8
+ *
9
+ * The xmlwriter library is used to create the XML sub-components files
10
+ * in the Excel XLSX file format.
11
+ *
12
+ * This library is used in preference to a more generic XML library to allow
13
+ * for customization and optimization for the XLSX file format.
14
+ *
15
+ * The xmlwriter functions are only used internally and do not need to be
16
+ * called directly by the end user.
17
+ *
18
+ */
19
+ #ifndef __XMLWRITER_H__
20
+ #define __XMLWRITER_H__
21
+
22
+ #include <stdio.h>
23
+ #include <stdlib.h>
24
+ #include <stdint.h>
25
+ #include "common.h"
26
+
27
+ #define LXW_MAX_ATTRIBUTE_LENGTH 256
28
+ #define LXW_ATTR_32 32
29
+
30
+ #define LXW_ATTRIBUTE_COPY(dst, src) \
31
+ do{ \
32
+ strncpy(dst, src, LXW_MAX_ATTRIBUTE_LENGTH -1); \
33
+ dst[LXW_MAX_ATTRIBUTE_LENGTH - 1] = '\0'; \
34
+ } while (0)
35
+
36
+
37
+ /* *INDENT-OFF* */
38
+ #ifdef __cplusplus
39
+ extern "C" {
40
+ #endif
41
+ /* *INDENT-ON* */
42
+
43
+ /* Attribute used in XML elements. */
44
+ struct xml_attribute {
45
+ char key[LXW_MAX_ATTRIBUTE_LENGTH];
46
+ char value[LXW_MAX_ATTRIBUTE_LENGTH];
47
+
48
+ /* Make the struct a queue.h list element. */
49
+ STAILQ_ENTRY (xml_attribute) list_entries;
50
+ };
51
+
52
+ /* Use queue.h macros to define the xml_attribute_list type. */
53
+ STAILQ_HEAD(xml_attribute_list, xml_attribute);
54
+
55
+ /* Create a new attribute struct to add to a xml_attribute_list. */
56
+ struct xml_attribute *lxw_new_attribute_str(const char *key,
57
+ const char *value);
58
+ struct xml_attribute *lxw_new_attribute_int(const char *key, uint32_t value);
59
+ struct xml_attribute *lxw_new_attribute_dbl(const char *key, double value);
60
+
61
+ /* Macro to initialize the xml_attribute_list pointers. */
62
+ #define LXW_INIT_ATTRIBUTES() \
63
+ STAILQ_INIT(&attributes)
64
+
65
+ /* Macro to add attribute string elements to xml_attribute_list. */
66
+ #define LXW_PUSH_ATTRIBUTES_STR(key, value) \
67
+ do { \
68
+ attribute = lxw_new_attribute_str((key), (value)); \
69
+ STAILQ_INSERT_TAIL(&attributes, attribute, list_entries); \
70
+ } while (0)
71
+
72
+ /* Macro to add attribute int values to xml_attribute_list. */
73
+ #define LXW_PUSH_ATTRIBUTES_INT(key, value) \
74
+ do { \
75
+ attribute = lxw_new_attribute_int((key), (value)); \
76
+ STAILQ_INSERT_TAIL(&attributes, attribute, list_entries); \
77
+ } while (0)
78
+
79
+ /* Macro to add attribute double values to xml_attribute_list. */
80
+ #define LXW_PUSH_ATTRIBUTES_DBL(key, value) \
81
+ do { \
82
+ attribute = lxw_new_attribute_dbl((key), (value)); \
83
+ STAILQ_INSERT_TAIL(&attributes, attribute, list_entries); \
84
+ } while (0)
85
+
86
+ /* Macro to free xml_attribute_list and attribute. */
87
+ #define LXW_FREE_ATTRIBUTES() \
88
+ while (!STAILQ_EMPTY(&attributes)) { \
89
+ attribute = STAILQ_FIRST(&attributes); \
90
+ STAILQ_REMOVE_HEAD(&attributes, list_entries); \
91
+ free(attribute); \
92
+ }
93
+
94
+ /**
95
+ * Create the XML declaration in an XML file.
96
+ *
97
+ * @param xmlfile A FILE pointer to the output XML file.
98
+ */
99
+ void lxw_xml_declaration(FILE * xmlfile);
100
+
101
+ /**
102
+ * Write an XML start tag with optional attributes.
103
+ *
104
+ * @param xmlfile A FILE pointer to the output XML file.
105
+ * @param tag The XML tag to write.
106
+ * @param attributes An optional list of attributes to add to the tag.
107
+ */
108
+ void lxw_xml_start_tag(FILE * xmlfile,
109
+ const char *tag,
110
+ struct xml_attribute_list *attributes);
111
+
112
+ /**
113
+ * Write an XML start tag with optional un-encoded attributes.
114
+ * This is a minor optimization for attributes that don't need encoding.
115
+ *
116
+ * @param xmlfile A FILE pointer to the output XML file.
117
+ * @param tag The XML tag to write.
118
+ * @param attributes An optional list of attributes to add to the tag.
119
+ */
120
+ void lxw_xml_start_tag_unencoded(FILE * xmlfile,
121
+ const char *tag,
122
+ struct xml_attribute_list *attributes);
123
+
124
+ /**
125
+ * Write an XML end tag.
126
+ *
127
+ * @param xmlfile A FILE pointer to the output XML file.
128
+ * @param tag The XML tag to write.
129
+ */
130
+ void lxw_xml_end_tag(FILE * xmlfile, const char *tag);
131
+
132
+ /**
133
+ * Write an XML empty tag with optional attributes.
134
+ *
135
+ * @param xmlfile A FILE pointer to the output XML file.
136
+ * @param tag The XML tag to write.
137
+ * @param attributes An optional list of attributes to add to the tag.
138
+ */
139
+ void lxw_xml_empty_tag(FILE * xmlfile,
140
+ const char *tag,
141
+ struct xml_attribute_list *attributes);
142
+
143
+ /**
144
+ * Write an XML empty tag with optional un-encoded attributes.
145
+ * This is a minor optimization for attributes that don't need encoding.
146
+ *
147
+ * @param xmlfile A FILE pointer to the output XML file.
148
+ * @param tag The XML tag to write.
149
+ * @param attributes An optional list of attributes to add to the tag.
150
+ */
151
+ void lxw_xml_empty_tag_unencoded(FILE * xmlfile,
152
+ const char *tag,
153
+ struct xml_attribute_list *attributes);
154
+
155
+ /**
156
+ * Write an XML element containing data and optional attributes.
157
+ *
158
+ * @param xmlfile A FILE pointer to the output XML file.
159
+ * @param tag The XML tag to write.
160
+ * @param data The data section of the XML element.
161
+ * @param attributes An optional list of attributes to add to the tag.
162
+ */
163
+ void lxw_xml_data_element(FILE * xmlfile,
164
+ const char *tag,
165
+ const char *data,
166
+ struct xml_attribute_list *attributes);
167
+
168
+ char *lxw_escape_control_characters(const char *string);
169
+
170
+ char *lxw_escape_data(const char *data);
171
+
172
+ /* *INDENT-OFF* */
173
+ #ifdef __cplusplus
174
+ }
175
+ #endif
176
+ /* *INDENT-ON* */
177
+
178
+ #endif /* __XMLWRITER_H__ */
@@ -0,0 +1,125 @@
1
+ ###############################################################################
2
+ #
3
+ # Makefile for libxlsxwriter library.
4
+ #
5
+ # Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
6
+ #
7
+
8
+ # Keep the output quiet by default.
9
+ Q=@
10
+ ifdef V
11
+ Q=
12
+ endif
13
+
14
+ # Directory variables.
15
+ OBJS_DIR = .
16
+ INC_DIR = ../include
17
+
18
+ # The minizip directory.
19
+ MINIZIP_DIR = ../third_party/minizip
20
+
21
+
22
+ ifdef USE_STANDARD_TMPFILE
23
+ # Use standard/C tmpfile().
24
+ CFLAGS += -DUSE_STANDARD_TMPFILE
25
+ else
26
+ # Use tmpfileplus (the default).
27
+ TMPFILEPLUS_DIR = ../third_party/tmpfileplus
28
+ TMPFILEPLUS_OBJ = $(TMPFILEPLUS_DIR)/tmpfileplus.o
29
+ TMPFILEPLUS_SO = $(TMPFILEPLUS_DIR)/tmpfileplus.so
30
+ endif
31
+
32
+ # Flags passed to compiler.
33
+ CFLAGS += -g -O3 -Wall -Wextra -pedantic -ansi
34
+
35
+ # Library names.
36
+ LIBXLSXWRITER_A = libxlsxwriter.a
37
+ LIBXLSXWRITER_SO = libxlsxwriter.so
38
+
39
+ # Library with additional non-static functions for testing.
40
+ LIBXLSXWRITER_TO = libxlsxwriter_test.a
41
+
42
+ # Flags passed to static linker.
43
+ ARFLAGS = rc
44
+
45
+ # Flags passed to dynamic linker.
46
+ FPIC = -fPIC
47
+ SOFLAGS = -shared $(FPIC)
48
+
49
+ # Get Env/OS name.
50
+ UNAME := $(shell uname)
51
+
52
+ # Change make options on OS X.
53
+ ifeq ($(UNAME), Darwin)
54
+ LIBXLSXWRITER_SO = libxlsxwriter.dylib
55
+ SOFLAGS = -dynamiclib $(FPIC) -install_name /usr/lib/$(LIBXLSXWRITER_SO)
56
+ endif
57
+
58
+ # Check for MinGW/MinGW64/Cygwin environments.
59
+ ifneq (,$(findstring MINGW, $(UNAME)))
60
+ MING_LIKE = y
61
+ endif
62
+ ifneq (,$(findstring MSYS, $(UNAME)))
63
+ MING_LIKE = y
64
+ endif
65
+ ifneq (,$(findstring CYGWIN, $(UNAME)))
66
+ MING_LIKE = y
67
+ endif
68
+
69
+ # Change make options on MinGW/MinGW64/Cygwin.
70
+ ifdef MING_LIKE
71
+ LIBXLSXWRITER_SO = libxlsxwriter.dll
72
+ FPIC =
73
+ CC = gcc
74
+ CFLAGS += -Wno-char-subscripts -Wno-long-long
75
+ endif
76
+
77
+ # Headers as dependecies.
78
+ HDRS = $(wildcard ../include/xlsxwriter/*.h)
79
+
80
+ # Ojects to compile.
81
+ SRCS = $(wildcard *.c)
82
+ OBJS = $(patsubst %.c,%.o,$(SRCS))
83
+ SOBJS = $(patsubst %.c,%.so,$(SRCS))
84
+ TOBJS = $(patsubst %.c,%.to,$(SRCS))
85
+ # End of OBJS
86
+
87
+ # Build the object files and the libraries.
88
+ all : $(LIBXLSXWRITER_A) $(LIBXLSXWRITER_SO)
89
+ $(Q)cp $(LIBXLSXWRITER_A) $(LIBXLSXWRITER_SO) ../lib
90
+
91
+ test_lib : libxlsxwriter_test.a
92
+
93
+ # The static library.
94
+ $(LIBXLSXWRITER_A) : $(OBJS)
95
+ $(Q)$(AR) $(ARFLAGS) $@ $(MINIZIP_DIR)/ioapi.o $(MINIZIP_DIR)/zip.o $(TMPFILEPLUS_OBJ) $^
96
+
97
+ # The dynamic library.
98
+ ifeq ($(findstring m32,$(CFLAGS)),m32)
99
+ ARCH = -m32
100
+ endif
101
+
102
+ $(LIBXLSXWRITER_SO) : $(SOBJS)
103
+ $(Q)$(CC) $(SOFLAGS) $(ARCH) -o $@ $(MINIZIP_DIR)/ioapi.so $(MINIZIP_DIR)/zip.so $(TMPFILEPLUS_SO) $^ -lz
104
+
105
+ # The test library.
106
+ $(LIBXLSXWRITER_TO) : $(TOBJS)
107
+ $(Q)$(AR) $(ARFLAGS) $@ $(MINIZIP_DIR)/ioapi.o $(MINIZIP_DIR)/zip.o $(TMPFILEPLUS_OBJ) $^
108
+
109
+ # Minimal target for quick compile without creating the libs.
110
+ test_compile : $(OBJS)
111
+
112
+ # Targets for the object files.
113
+ %.o : %.c $(HDRS)
114
+ $(Q)$(CC) -I$(INC_DIR) $(CFLAGS) $(CXXFLAGS) -c $<
115
+
116
+ %.so : %.c $(HDRS)
117
+ $(Q)$(CC) $(FPIC) -I$(INC_DIR) $(CFLAGS) $(CXXFLAGS) -c $< -o $@
118
+
119
+ %.to : %.c $(HDRS)
120
+ $(Q)$(CC) -g -O0 -DTESTING -I$(INC_DIR) $(CFLAGS) $(CXXFLAGS) -c $< -o $@
121
+
122
+
123
+ # Clean up any temp/build files.
124
+ clean :
125
+ $(Q)rm -f *.o *.a *.so *.to *.dylib *.dll
@@ -0,0 +1,439 @@
1
+ /*****************************************************************************
2
+ * app - A library for creating Excel XLSX app files.
3
+ *
4
+ * Used in conjunction with the libxlsxwriter library.
5
+ *
6
+ * Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
7
+ *
8
+ */
9
+
10
+ #include "xlsxwriter/xmlwriter.h"
11
+ #include "xlsxwriter/app.h"
12
+ #include "xlsxwriter/utility.h"
13
+
14
+ /*
15
+ * Forward declarations.
16
+ */
17
+
18
+ /*****************************************************************************
19
+ *
20
+ * Private functions.
21
+ *
22
+ ****************************************************************************/
23
+
24
+ /*
25
+ * Create a new app object.
26
+ */
27
+ lxw_app *
28
+ lxw_app_new()
29
+ {
30
+ lxw_app *app = calloc(1, sizeof(lxw_app));
31
+ GOTO_LABEL_ON_MEM_ERROR(app, mem_error);
32
+
33
+ app->heading_pairs = calloc(1, sizeof(struct lxw_heading_pairs));
34
+ GOTO_LABEL_ON_MEM_ERROR(app->heading_pairs, mem_error);
35
+ STAILQ_INIT(app->heading_pairs);
36
+
37
+ app->part_names = calloc(1, sizeof(struct lxw_part_names));
38
+ GOTO_LABEL_ON_MEM_ERROR(app->part_names, mem_error);
39
+ STAILQ_INIT(app->part_names);
40
+
41
+ return app;
42
+
43
+ mem_error:
44
+ lxw_app_free(app);
45
+ return NULL;
46
+ }
47
+
48
+ /*
49
+ * Free a app object.
50
+ */
51
+ void
52
+ lxw_app_free(lxw_app *app)
53
+ {
54
+ lxw_heading_pair *heading_pair;
55
+ lxw_part_name *part_name;
56
+
57
+ if (!app)
58
+ return;
59
+
60
+ /* Free the lists in the App object. */
61
+ while (!STAILQ_EMPTY(app->heading_pairs)) {
62
+ heading_pair = STAILQ_FIRST(app->heading_pairs);
63
+ STAILQ_REMOVE_HEAD(app->heading_pairs, list_pointers);
64
+ free(heading_pair->key);
65
+ free(heading_pair->value);
66
+ free(heading_pair);
67
+ }
68
+
69
+ while (!STAILQ_EMPTY(app->part_names)) {
70
+ part_name = STAILQ_FIRST(app->part_names);
71
+ STAILQ_REMOVE_HEAD(app->part_names, list_pointers);
72
+ free(part_name->name);
73
+ free(part_name);
74
+ }
75
+
76
+ free(app->heading_pairs);
77
+ free(app->part_names);
78
+ free(app);
79
+ }
80
+
81
+ /*****************************************************************************
82
+ *
83
+ * XML functions.
84
+ *
85
+ ****************************************************************************/
86
+
87
+ /*
88
+ * Write the XML declaration.
89
+ */
90
+ STATIC void
91
+ _app_xml_declaration(lxw_app *self)
92
+ {
93
+ lxw_xml_declaration(self->file);
94
+ }
95
+
96
+ /*
97
+ * Write the <Properties> element.
98
+ */
99
+ STATIC void
100
+ _write_properties(lxw_app *self)
101
+ {
102
+ struct xml_attribute_list attributes;
103
+ struct xml_attribute *attribute;
104
+ char xmlns[] = LXW_SCHEMA_OFFICEDOC "/extended-properties";
105
+ char xmlns_vt[] = LXW_SCHEMA_OFFICEDOC "/docPropsVTypes";
106
+
107
+ LXW_INIT_ATTRIBUTES();
108
+ LXW_PUSH_ATTRIBUTES_STR("xmlns", xmlns);
109
+ LXW_PUSH_ATTRIBUTES_STR("xmlns:vt", xmlns_vt);
110
+
111
+ lxw_xml_start_tag(self->file, "Properties", &attributes);
112
+
113
+ LXW_FREE_ATTRIBUTES();
114
+ }
115
+
116
+ /*
117
+ * Write the <Application> element.
118
+ */
119
+ STATIC void
120
+ _write_application(lxw_app *self)
121
+ {
122
+ lxw_xml_data_element(self->file, "Application", "Microsoft Excel", NULL);
123
+ }
124
+
125
+ /*
126
+ * Write the <DocSecurity> element.
127
+ */
128
+ STATIC void
129
+ _write_doc_security(lxw_app *self)
130
+ {
131
+ lxw_xml_data_element(self->file, "DocSecurity", "0", NULL);
132
+ }
133
+
134
+ /*
135
+ * Write the <ScaleCrop> element.
136
+ */
137
+ STATIC void
138
+ _write_scale_crop(lxw_app *self)
139
+ {
140
+ lxw_xml_data_element(self->file, "ScaleCrop", "false", NULL);
141
+ }
142
+
143
+ /*
144
+ * Write the <vt:lpstr> element.
145
+ */
146
+ STATIC void
147
+ _write_vt_lpstr(lxw_app *self, const char *str)
148
+ {
149
+ lxw_xml_data_element(self->file, "vt:lpstr", str, NULL);
150
+ }
151
+
152
+ /*
153
+ * Write the <vt:i4> element.
154
+ */
155
+ STATIC void
156
+ _write_vt_i4(lxw_app *self, const char *value)
157
+ {
158
+ lxw_xml_data_element(self->file, "vt:i4", value, NULL);
159
+ }
160
+
161
+ /*
162
+ * Write the <vt:variant> element.
163
+ */
164
+ STATIC void
165
+ _write_vt_variant(lxw_app *self, const char *key, const char *value)
166
+ {
167
+ /* Write the vt:lpstr element. */
168
+ lxw_xml_start_tag(self->file, "vt:variant", NULL);
169
+ _write_vt_lpstr(self, key);
170
+ lxw_xml_end_tag(self->file, "vt:variant");
171
+
172
+ /* Write the vt:i4 element. */
173
+ lxw_xml_start_tag(self->file, "vt:variant", NULL);
174
+ _write_vt_i4(self, value);
175
+ lxw_xml_end_tag(self->file, "vt:variant");
176
+ }
177
+
178
+ /*
179
+ * Write the <vt:vector> element for the heading pairs.
180
+ */
181
+ STATIC void
182
+ _write_vt_vector_heading_pairs(lxw_app *self)
183
+ {
184
+ struct xml_attribute_list attributes;
185
+ struct xml_attribute *attribute;
186
+ lxw_heading_pair *heading_pair;
187
+
188
+ LXW_INIT_ATTRIBUTES();
189
+ LXW_PUSH_ATTRIBUTES_INT("size", self->num_heading_pairs * 2);
190
+ LXW_PUSH_ATTRIBUTES_STR("baseType", "variant");
191
+
192
+ lxw_xml_start_tag(self->file, "vt:vector", &attributes);
193
+
194
+ STAILQ_FOREACH(heading_pair, self->heading_pairs, list_pointers) {
195
+ _write_vt_variant(self, heading_pair->key, heading_pair->value);
196
+ }
197
+
198
+ lxw_xml_end_tag(self->file, "vt:vector");
199
+
200
+ LXW_FREE_ATTRIBUTES();
201
+ }
202
+
203
+ /*
204
+ * Write the <vt:vector> element for the named parts.
205
+ */
206
+ STATIC void
207
+ _write_vt_vector_lpstr_named_parts(lxw_app *self)
208
+ {
209
+ struct xml_attribute_list attributes;
210
+ struct xml_attribute *attribute;
211
+ lxw_part_name *part_name;
212
+
213
+ LXW_INIT_ATTRIBUTES();
214
+ LXW_PUSH_ATTRIBUTES_INT("size", self->num_part_names);
215
+ LXW_PUSH_ATTRIBUTES_STR("baseType", "lpstr");
216
+
217
+ lxw_xml_start_tag(self->file, "vt:vector", &attributes);
218
+
219
+ STAILQ_FOREACH(part_name, self->part_names, list_pointers) {
220
+ _write_vt_lpstr(self, part_name->name);
221
+ }
222
+
223
+ lxw_xml_end_tag(self->file, "vt:vector");
224
+
225
+ LXW_FREE_ATTRIBUTES();
226
+ }
227
+
228
+ /*
229
+ * Write the <HeadingPairs> element.
230
+ */
231
+ STATIC void
232
+ _write_heading_pairs(lxw_app *self)
233
+ {
234
+ lxw_xml_start_tag(self->file, "HeadingPairs", NULL);
235
+
236
+ /* Write the vt:vector element. */
237
+ _write_vt_vector_heading_pairs(self);
238
+
239
+ lxw_xml_end_tag(self->file, "HeadingPairs");
240
+ }
241
+
242
+ /*
243
+ * Write the <TitlesOfParts> element.
244
+ */
245
+ STATIC void
246
+ _write_titles_of_parts(lxw_app *self)
247
+ {
248
+ lxw_xml_start_tag(self->file, "TitlesOfParts", NULL);
249
+
250
+ /* Write the vt:vector element. */
251
+ _write_vt_vector_lpstr_named_parts(self);
252
+
253
+ lxw_xml_end_tag(self->file, "TitlesOfParts");
254
+ }
255
+
256
+ /*
257
+ * Write the <Manager> element.
258
+ */
259
+ STATIC void
260
+ _write_manager(lxw_app *self)
261
+ {
262
+ lxw_doc_properties *properties = self->properties;
263
+
264
+ if (!properties)
265
+ return;
266
+
267
+ if (properties->manager)
268
+ lxw_xml_data_element(self->file, "Manager", properties->manager,
269
+ NULL);
270
+ }
271
+
272
+ /*
273
+ * Write the <Company> element.
274
+ */
275
+ STATIC void
276
+ _write_company(lxw_app *self)
277
+ {
278
+ lxw_doc_properties *properties = self->properties;
279
+
280
+ if (properties && properties->company)
281
+ lxw_xml_data_element(self->file, "Company", properties->company,
282
+ NULL);
283
+ else
284
+ lxw_xml_data_element(self->file, "Company", "", NULL);
285
+ }
286
+
287
+ /*
288
+ * Write the <LinksUpToDate> element.
289
+ */
290
+ STATIC void
291
+ _write_links_up_to_date(lxw_app *self)
292
+ {
293
+ lxw_xml_data_element(self->file, "LinksUpToDate", "false", NULL);
294
+ }
295
+
296
+ /*
297
+ * Write the <SharedDoc> element.
298
+ */
299
+ STATIC void
300
+ _write_shared_doc(lxw_app *self)
301
+ {
302
+ lxw_xml_data_element(self->file, "SharedDoc", "false", NULL);
303
+ }
304
+
305
+ /*
306
+ * Write the <HyperlinkBase> element.
307
+ */
308
+ STATIC void
309
+ _write_hyperlink_base(lxw_app *self)
310
+ {
311
+ lxw_doc_properties *properties = self->properties;
312
+
313
+ if (!properties)
314
+ return;
315
+
316
+ if (properties->hyperlink_base)
317
+ lxw_xml_data_element(self->file, "HyperlinkBase",
318
+ properties->hyperlink_base, NULL);
319
+ }
320
+
321
+ /*
322
+ * Write the <HyperlinksChanged> element.
323
+ */
324
+ STATIC void
325
+ _write_hyperlinks_changed(lxw_app *self)
326
+ {
327
+ lxw_xml_data_element(self->file, "HyperlinksChanged", "false", NULL);
328
+ }
329
+
330
+ /*
331
+ * Write the <AppVersion> element.
332
+ */
333
+ STATIC void
334
+ _write_app_version(lxw_app *self)
335
+ {
336
+ lxw_xml_data_element(self->file, "AppVersion", "12.0000", NULL);
337
+ }
338
+
339
+ /*****************************************************************************
340
+ *
341
+ * XML file assembly functions.
342
+ *
343
+ ****************************************************************************/
344
+
345
+ /*
346
+ * Assemble and write the XML file.
347
+ */
348
+ void
349
+ lxw_app_assemble_xml_file(lxw_app *self)
350
+ {
351
+
352
+ /* Write the XML declaration. */
353
+ _app_xml_declaration(self);
354
+
355
+ _write_properties(self);
356
+ _write_application(self);
357
+ _write_doc_security(self);
358
+ _write_scale_crop(self);
359
+ _write_heading_pairs(self);
360
+ _write_titles_of_parts(self);
361
+ _write_manager(self);
362
+ _write_company(self);
363
+ _write_links_up_to_date(self);
364
+ _write_shared_doc(self);
365
+ _write_hyperlink_base(self);
366
+ _write_hyperlinks_changed(self);
367
+ _write_app_version(self);
368
+
369
+ lxw_xml_end_tag(self->file, "Properties");
370
+ }
371
+
372
+ /*****************************************************************************
373
+ *
374
+ * Public functions.
375
+ *
376
+ ****************************************************************************/
377
+
378
+ /*
379
+ * Add the name of a workbook Part such as 'Sheet1' or 'Print_Titles'.
380
+ */
381
+ void
382
+ lxw_app_add_part_name(lxw_app *self, const char *name)
383
+ {
384
+ lxw_part_name *part_name;
385
+
386
+ if (!name)
387
+ return;
388
+
389
+ part_name = calloc(1, sizeof(lxw_part_name));
390
+ GOTO_LABEL_ON_MEM_ERROR(part_name, mem_error);
391
+
392
+ part_name->name = lxw_strdup(name);
393
+ GOTO_LABEL_ON_MEM_ERROR(part_name->name, mem_error);
394
+
395
+ STAILQ_INSERT_TAIL(self->part_names, part_name, list_pointers);
396
+ self->num_part_names++;
397
+
398
+ return;
399
+
400
+ mem_error:
401
+ if (part_name) {
402
+ free(part_name->name);
403
+ free(part_name);
404
+ }
405
+ }
406
+
407
+ /*
408
+ * Add the name of a workbook Heading Pair such as 'Worksheets', 'Charts' or
409
+ * 'Named Ranges'.
410
+ */
411
+ void
412
+ lxw_app_add_heading_pair(lxw_app *self, const char *key, const char *value)
413
+ {
414
+ lxw_heading_pair *heading_pair;
415
+
416
+ if (!key || !value)
417
+ return;
418
+
419
+ heading_pair = calloc(1, sizeof(lxw_heading_pair));
420
+ GOTO_LABEL_ON_MEM_ERROR(heading_pair, mem_error);
421
+
422
+ heading_pair->key = lxw_strdup(key);
423
+ GOTO_LABEL_ON_MEM_ERROR(heading_pair->key, mem_error);
424
+
425
+ heading_pair->value = lxw_strdup(value);
426
+ GOTO_LABEL_ON_MEM_ERROR(heading_pair->value, mem_error);
427
+
428
+ STAILQ_INSERT_TAIL(self->heading_pairs, heading_pair, list_pointers);
429
+ self->num_heading_pairs++;
430
+
431
+ return;
432
+
433
+ mem_error:
434
+ if (heading_pair) {
435
+ free(heading_pair->key);
436
+ free(heading_pair->value);
437
+ free(heading_pair);
438
+ }
439
+ }