fast_excel 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.dockerignore +2 -0
- data/.gitignore +3 -0
- data/.travis.yml +18 -6
- data/CHANGELOG.md +14 -1
- data/Dockerfile.test +16 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +21 -21
- data/Makefile +13 -2
- data/README.md +148 -38
- data/Rakefile +2 -0
- data/examples/example.rb +3 -3
- data/examples/example_filters.rb +36 -0
- data/examples/example_formula.rb +1 -3
- data/examples/example_hyperlink.rb +20 -0
- data/fast_excel.gemspec +1 -1
- data/lib/fast_excel.rb +36 -12
- data/lib/fast_excel/binding.rb +31 -21
- data/lib/fast_excel/binding/chart.rb +20 -1
- data/lib/fast_excel/binding/workbook.rb +10 -2
- data/lib/fast_excel/binding/worksheet.rb +44 -27
- data/libxlsxwriter/.gitignore +1 -0
- data/libxlsxwriter/.indent.pro +5 -0
- data/libxlsxwriter/CMakeLists.txt +1 -11
- data/libxlsxwriter/CONTRIBUTING.md +1 -1
- data/libxlsxwriter/Changes.txt +84 -0
- data/libxlsxwriter/LICENSE.txt +1 -1
- data/libxlsxwriter/Makefile +7 -5
- data/libxlsxwriter/Readme.md +1 -1
- data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +1 -0
- data/libxlsxwriter/include/xlsxwriter.h +2 -2
- data/libxlsxwriter/include/xlsxwriter/app.h +2 -2
- data/libxlsxwriter/include/xlsxwriter/chart.h +56 -6
- data/libxlsxwriter/include/xlsxwriter/chartsheet.h +544 -0
- data/libxlsxwriter/include/xlsxwriter/common.h +27 -6
- data/libxlsxwriter/include/xlsxwriter/content_types.h +5 -2
- data/libxlsxwriter/include/xlsxwriter/core.h +2 -2
- data/libxlsxwriter/include/xlsxwriter/custom.h +2 -2
- data/libxlsxwriter/include/xlsxwriter/drawing.h +3 -2
- data/libxlsxwriter/include/xlsxwriter/format.h +3 -3
- data/libxlsxwriter/include/xlsxwriter/hash_table.h +1 -1
- data/libxlsxwriter/include/xlsxwriter/packager.h +13 -8
- data/libxlsxwriter/include/xlsxwriter/relationships.h +2 -2
- data/libxlsxwriter/include/xlsxwriter/shared_strings.h +5 -3
- data/libxlsxwriter/include/xlsxwriter/styles.h +9 -4
- data/libxlsxwriter/include/xlsxwriter/theme.h +2 -2
- data/libxlsxwriter/include/xlsxwriter/utility.h +26 -2
- data/libxlsxwriter/include/xlsxwriter/workbook.h +232 -55
- data/libxlsxwriter/include/xlsxwriter/worksheet.h +264 -53
- data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +3 -1
- data/libxlsxwriter/libxlsxwriter.podspec +1 -1
- data/libxlsxwriter/src/Makefile +3 -3
- data/libxlsxwriter/src/app.c +2 -2
- data/libxlsxwriter/src/chart.c +41 -5
- data/libxlsxwriter/src/chartsheet.c +508 -0
- data/libxlsxwriter/src/content_types.c +12 -4
- data/libxlsxwriter/src/core.c +2 -2
- data/libxlsxwriter/src/custom.c +2 -2
- data/libxlsxwriter/src/drawing.c +114 -17
- data/libxlsxwriter/src/format.c +3 -3
- data/libxlsxwriter/src/hash_table.c +1 -1
- data/libxlsxwriter/src/packager.c +369 -65
- data/libxlsxwriter/src/relationships.c +2 -2
- data/libxlsxwriter/src/shared_strings.c +18 -4
- data/libxlsxwriter/src/styles.c +56 -9
- data/libxlsxwriter/src/theme.c +2 -2
- data/libxlsxwriter/src/utility.c +53 -6
- data/libxlsxwriter/src/workbook.c +372 -56
- data/libxlsxwriter/src/worksheet.c +425 -76
- data/libxlsxwriter/src/xmlwriter.c +17 -8
- data/libxlsxwriter/third_party/minizip/ioapi.c +10 -0
- data/libxlsxwriter/third_party/minizip/zip.c +2 -0
- data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +2 -2
- data/libxlsxwriter/version.txt +1 -1
- data/test/tmpfile_test.rb +1 -0
- data/test/validations_test.rb +26 -6
- data/test/worksheet_test.rb +43 -0
- metadata +9 -6
- data/libxlsxwriter/.drone.yml +0 -27
- data/libxlsxwriter/appveyor.yml +0 -65
- data/libxlsxwriter/cmake/FindZLIB.cmake +0 -123
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* libxlsxwriter
|
3
3
|
*
|
4
|
-
* Copyright 2014-
|
4
|
+
* Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
5
5
|
*
|
6
6
|
* xmlwriter - A libxlsxwriter library for creating Excel XLSX
|
7
7
|
* XML files.
|
@@ -165,6 +165,8 @@ void lxw_xml_data_element(FILE * xmlfile,
|
|
165
165
|
const char *data,
|
166
166
|
struct xml_attribute_list *attributes);
|
167
167
|
|
168
|
+
void lxw_xml_rich_si_element(FILE * xmlfile, const char *string);
|
169
|
+
|
168
170
|
char *lxw_escape_control_characters(const char *string);
|
169
171
|
|
170
172
|
char *lxw_escape_data(const char *data);
|
data/libxlsxwriter/src/Makefile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Makefile for libxlsxwriter library.
|
4
4
|
#
|
5
|
-
# Copyright 2014-
|
5
|
+
# Copyright 2014-2019, John McNamara, jmcnamara@cpan.org
|
6
6
|
#
|
7
7
|
|
8
8
|
# Keep the output quiet by default.
|
@@ -130,7 +130,7 @@ ARCH = -m32
|
|
130
130
|
endif
|
131
131
|
|
132
132
|
$(LIBXLSXWRITER_SO) : $(SOBJS)
|
133
|
-
$(Q)$(CC) $(SOFLAGS) $(ARCH) -o $@ $(MINIZIP_SO) $(TMPFILEPLUS_SO) $^ $(LIBS)
|
133
|
+
$(Q)$(CC) $(LDFLAGS) $(SOFLAGS) $(ARCH) -o $@ $(MINIZIP_SO) $(TMPFILEPLUS_SO) $^ $(LIBS)
|
134
134
|
|
135
135
|
# The test library.
|
136
136
|
$(LIBXLSXWRITER_TO) : $(TOBJS)
|
@@ -144,7 +144,7 @@ test_compile : $(OBJS)
|
|
144
144
|
$(Q)$(CC) -I$(INC_DIR) $(CFLAGS) $(CXXFLAGS) -c $<
|
145
145
|
|
146
146
|
%.so : %.c $(HDRS)
|
147
|
-
$(Q)$(CC) $(FPIC) -I$(INC_DIR) $(CFLAGS) $(CXXFLAGS) -c $< -o $@
|
147
|
+
$(Q)$(CC) $(FPIC) -I$(INC_DIR) $(LDFLAGS) $(CFLAGS) $(CXXFLAGS) -c $< -o $@
|
148
148
|
|
149
149
|
%.to : %.c $(HDRS)
|
150
150
|
$(Q)$(CC) -g -O3 -DTESTING -I$(INC_DIR) $(CFLAGS) $(CXXFLAGS) -c $< -o $@
|
data/libxlsxwriter/src/app.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
*
|
4
4
|
* Used in conjunction with the libxlsxwriter library.
|
5
5
|
*
|
6
|
-
* Copyright 2014-
|
6
|
+
* Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
7
7
|
*
|
8
8
|
*/
|
9
9
|
|
@@ -25,7 +25,7 @@
|
|
25
25
|
* Create a new app object.
|
26
26
|
*/
|
27
27
|
lxw_app *
|
28
|
-
lxw_app_new()
|
28
|
+
lxw_app_new(void)
|
29
29
|
{
|
30
30
|
lxw_app *app = calloc(1, sizeof(lxw_app));
|
31
31
|
GOTO_LABEL_ON_MEM_ERROR(app, mem_error);
|
data/libxlsxwriter/src/chart.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
*
|
4
4
|
* Used in conjunction with the libxlsxwriter library.
|
5
5
|
*
|
6
|
-
* Copyright 2014-
|
6
|
+
* Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
7
7
|
*
|
8
8
|
*/
|
9
9
|
|
@@ -573,6 +573,15 @@ _chart_xml_declaration(lxw_chart *self)
|
|
573
573
|
lxw_xml_declaration(self->file);
|
574
574
|
}
|
575
575
|
|
576
|
+
/*
|
577
|
+
* Write the <c:protection> element.
|
578
|
+
*/
|
579
|
+
STATIC void
|
580
|
+
_chart_write_protection(lxw_chart *self)
|
581
|
+
{
|
582
|
+
lxw_xml_empty_tag(self->file, "c:protection", NULL);
|
583
|
+
}
|
584
|
+
|
576
585
|
/*
|
577
586
|
* Write the <c:chartSpace> element.
|
578
587
|
*/
|
@@ -3201,13 +3210,19 @@ _chart_write_auto(lxw_chart *self)
|
|
3201
3210
|
* Write the <c:lblAlgn> element.
|
3202
3211
|
*/
|
3203
3212
|
STATIC void
|
3204
|
-
_chart_write_label_align(lxw_chart *self)
|
3213
|
+
_chart_write_label_align(lxw_chart *self, lxw_chart_axis *axis)
|
3205
3214
|
{
|
3206
3215
|
struct xml_attribute_list attributes;
|
3207
3216
|
struct xml_attribute *attribute;
|
3208
3217
|
|
3209
3218
|
LXW_INIT_ATTRIBUTES();
|
3210
|
-
|
3219
|
+
|
3220
|
+
if (axis->label_align == LXW_CHART_AXIS_LABEL_ALIGN_LEFT)
|
3221
|
+
LXW_PUSH_ATTRIBUTES_STR("val", "l");
|
3222
|
+
else if (axis->label_align == LXW_CHART_AXIS_LABEL_ALIGN_RIGHT)
|
3223
|
+
LXW_PUSH_ATTRIBUTES_STR("val", "r");
|
3224
|
+
else
|
3225
|
+
LXW_PUSH_ATTRIBUTES_STR("val", "ctr");
|
3211
3226
|
|
3212
3227
|
lxw_xml_empty_tag(self->file, "c:lblAlgn", &attributes);
|
3213
3228
|
|
@@ -3585,6 +3600,9 @@ _chart_write_legend(lxw_chart *self)
|
|
3585
3600
|
case LXW_CHART_LEGEND_BOTTOM:
|
3586
3601
|
_chart_write_legend_pos(self, "b");
|
3587
3602
|
break;
|
3603
|
+
case LXW_CHART_LEGEND_TOP_RIGHT:
|
3604
|
+
_chart_write_legend_pos(self, "tr");
|
3605
|
+
break;
|
3588
3606
|
case LXW_CHART_LEGEND_OVERLAY_RIGHT:
|
3589
3607
|
_chart_write_legend_pos(self, "r");
|
3590
3608
|
has_overlay = LXW_TRUE;
|
@@ -3593,6 +3611,10 @@ _chart_write_legend(lxw_chart *self)
|
|
3593
3611
|
_chart_write_legend_pos(self, "l");
|
3594
3612
|
has_overlay = LXW_TRUE;
|
3595
3613
|
break;
|
3614
|
+
case LXW_CHART_LEGEND_OVERLAY_TOP_RIGHT:
|
3615
|
+
_chart_write_legend_pos(self, "tr");
|
3616
|
+
has_overlay = LXW_TRUE;
|
3617
|
+
break;
|
3596
3618
|
default:
|
3597
3619
|
_chart_write_legend_pos(self, "r");
|
3598
3620
|
}
|
@@ -4091,7 +4113,7 @@ _chart_write_cat_axis(lxw_chart *self)
|
|
4091
4113
|
_chart_write_auto(self);
|
4092
4114
|
|
4093
4115
|
/* Write the c:lblAlgn element. */
|
4094
|
-
_chart_write_label_align(self);
|
4116
|
+
_chart_write_label_align(self, self->x_axis);
|
4095
4117
|
|
4096
4118
|
/* Write the c:lblOffset element. */
|
4097
4119
|
_chart_write_label_offset(self);
|
@@ -4928,6 +4950,10 @@ lxw_chart_assemble_xml_file(lxw_chart *self)
|
|
4928
4950
|
/* Write the c:style element. */
|
4929
4951
|
_chart_write_style(self);
|
4930
4952
|
|
4953
|
+
/* Write the c:protection element. */
|
4954
|
+
if (self->is_protected)
|
4955
|
+
_chart_write_protection(self);
|
4956
|
+
|
4931
4957
|
/* Write the c:chart element. */
|
4932
4958
|
_chart_write_chart(self);
|
4933
4959
|
|
@@ -4936,7 +4962,8 @@ lxw_chart_assemble_xml_file(lxw_chart *self)
|
|
4936
4962
|
self->chartarea_pattern);
|
4937
4963
|
|
4938
4964
|
/* Write the c:printSettings element. */
|
4939
|
-
|
4965
|
+
if (!self->is_chartsheet)
|
4966
|
+
_chart_write_print_settings(self);
|
4940
4967
|
|
4941
4968
|
lxw_xml_end_tag(self->file, "c:chartSpace");
|
4942
4969
|
}
|
@@ -6040,6 +6067,15 @@ chart_axis_minor_gridlines_set_line(lxw_chart_axis *axis,
|
|
6040
6067
|
axis->minor_gridlines.visible = LXW_TRUE;
|
6041
6068
|
}
|
6042
6069
|
|
6070
|
+
/*
|
6071
|
+
* Set the chart axis label alignment.
|
6072
|
+
*/
|
6073
|
+
void
|
6074
|
+
chart_axis_set_label_align(lxw_chart_axis *axis, uint8_t align)
|
6075
|
+
{
|
6076
|
+
axis->label_align = align;
|
6077
|
+
}
|
6078
|
+
|
6043
6079
|
/*
|
6044
6080
|
* Set the chart title.
|
6045
6081
|
*/
|
@@ -0,0 +1,508 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
* chartsheet - A library for creating Excel XLSX chartsheet files.
|
3
|
+
*
|
4
|
+
* Used in conjunction with the libxlsxwriter library.
|
5
|
+
*
|
6
|
+
* Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include "xlsxwriter/xmlwriter.h"
|
11
|
+
#include "xlsxwriter/chartsheet.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 chartsheet object.
|
26
|
+
*/
|
27
|
+
lxw_chartsheet *
|
28
|
+
lxw_chartsheet_new(lxw_worksheet_init_data *init_data)
|
29
|
+
{
|
30
|
+
lxw_chartsheet *chartsheet = calloc(1, sizeof(lxw_chartsheet));
|
31
|
+
GOTO_LABEL_ON_MEM_ERROR(chartsheet, mem_error);
|
32
|
+
|
33
|
+
/* Use an embedded worksheet instance to write XML records that are
|
34
|
+
* shared with worksheet.c. */
|
35
|
+
chartsheet->worksheet = lxw_worksheet_new(NULL);
|
36
|
+
GOTO_LABEL_ON_MEM_ERROR(chartsheet->worksheet, mem_error);
|
37
|
+
|
38
|
+
if (init_data) {
|
39
|
+
chartsheet->name = init_data->name;
|
40
|
+
chartsheet->quoted_name = init_data->quoted_name;
|
41
|
+
chartsheet->tmpdir = init_data->tmpdir;
|
42
|
+
chartsheet->index = init_data->index;
|
43
|
+
chartsheet->hidden = init_data->hidden;
|
44
|
+
chartsheet->active_sheet = init_data->active_sheet;
|
45
|
+
chartsheet->first_sheet = init_data->first_sheet;
|
46
|
+
}
|
47
|
+
|
48
|
+
chartsheet->worksheet->is_chartsheet = LXW_TRUE;
|
49
|
+
chartsheet->worksheet->zoom_scale_normal = LXW_FALSE;
|
50
|
+
chartsheet->worksheet->orientation = LXW_LANDSCAPE;
|
51
|
+
|
52
|
+
return chartsheet;
|
53
|
+
|
54
|
+
mem_error:
|
55
|
+
lxw_chartsheet_free(chartsheet);
|
56
|
+
return NULL;
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* Free a chartsheet object.
|
61
|
+
*/
|
62
|
+
void
|
63
|
+
lxw_chartsheet_free(lxw_chartsheet *chartsheet)
|
64
|
+
{
|
65
|
+
if (!chartsheet)
|
66
|
+
return;
|
67
|
+
|
68
|
+
lxw_worksheet_free(chartsheet->worksheet);
|
69
|
+
free(chartsheet->name);
|
70
|
+
free(chartsheet->quoted_name);
|
71
|
+
free(chartsheet);
|
72
|
+
}
|
73
|
+
|
74
|
+
/*****************************************************************************
|
75
|
+
*
|
76
|
+
* XML functions.
|
77
|
+
*
|
78
|
+
****************************************************************************/
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Write the XML declaration.
|
82
|
+
*/
|
83
|
+
STATIC void
|
84
|
+
_chartsheet_xml_declaration(lxw_chartsheet *self)
|
85
|
+
{
|
86
|
+
lxw_xml_declaration(self->file);
|
87
|
+
}
|
88
|
+
|
89
|
+
/*
|
90
|
+
* Write the <chartsheet> element.
|
91
|
+
*/
|
92
|
+
STATIC void
|
93
|
+
_chartsheet_write_chartsheet(lxw_chartsheet *self)
|
94
|
+
{
|
95
|
+
struct xml_attribute_list attributes;
|
96
|
+
struct xml_attribute *attribute;
|
97
|
+
char xmlns[] = "http://schemas.openxmlformats.org/"
|
98
|
+
"spreadsheetml/2006/main";
|
99
|
+
char xmlns_r[] = "http://schemas.openxmlformats.org/"
|
100
|
+
"officeDocument/2006/relationships";
|
101
|
+
|
102
|
+
LXW_INIT_ATTRIBUTES();
|
103
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns", xmlns);
|
104
|
+
LXW_PUSH_ATTRIBUTES_STR("xmlns:r", xmlns_r);
|
105
|
+
|
106
|
+
lxw_xml_start_tag(self->file, "chartsheet", &attributes);
|
107
|
+
LXW_FREE_ATTRIBUTES();
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* Write the <sheetPr> element.
|
112
|
+
*/
|
113
|
+
STATIC void
|
114
|
+
_chartsheet_write_sheet_pr(lxw_chartsheet *self)
|
115
|
+
{
|
116
|
+
lxw_worksheet_write_sheet_pr(self->worksheet);
|
117
|
+
}
|
118
|
+
|
119
|
+
/*
|
120
|
+
* Write the <sheetViews> element.
|
121
|
+
*/
|
122
|
+
STATIC void
|
123
|
+
_chartsheet_write_sheet_views(lxw_chartsheet *self)
|
124
|
+
{
|
125
|
+
lxw_worksheet_write_sheet_views(self->worksheet);
|
126
|
+
}
|
127
|
+
|
128
|
+
/*
|
129
|
+
* Write the <pageMargins> element.
|
130
|
+
*/
|
131
|
+
STATIC void
|
132
|
+
_chartsheet_write_page_margins(lxw_chartsheet *self)
|
133
|
+
{
|
134
|
+
lxw_worksheet_write_page_margins(self->worksheet);
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* Write the <drawing> elements.
|
139
|
+
*/
|
140
|
+
STATIC void
|
141
|
+
_chartsheet_write_drawings(lxw_chartsheet *self)
|
142
|
+
{
|
143
|
+
lxw_worksheet_write_drawings(self->worksheet);
|
144
|
+
}
|
145
|
+
|
146
|
+
/*
|
147
|
+
* Write the <sheetProtection> element.
|
148
|
+
*/
|
149
|
+
STATIC void
|
150
|
+
_chartsheet_write_sheet_protection(lxw_chartsheet *self)
|
151
|
+
{
|
152
|
+
lxw_worksheet_write_sheet_protection(self->worksheet, &self->protection);
|
153
|
+
}
|
154
|
+
|
155
|
+
/*
|
156
|
+
* Write the <pageSetup> element.
|
157
|
+
*/
|
158
|
+
STATIC void
|
159
|
+
_chartsheet_write_page_setup(lxw_chartsheet *self)
|
160
|
+
{
|
161
|
+
lxw_worksheet_write_page_setup(self->worksheet);
|
162
|
+
}
|
163
|
+
|
164
|
+
/*
|
165
|
+
* Write the <headerFooter> element.
|
166
|
+
*/
|
167
|
+
STATIC void
|
168
|
+
_chartsheet_write_header_footer(lxw_chartsheet *self)
|
169
|
+
{
|
170
|
+
lxw_worksheet_write_header_footer(self->worksheet);
|
171
|
+
}
|
172
|
+
|
173
|
+
/*****************************************************************************
|
174
|
+
*
|
175
|
+
* XML file assembly functions.
|
176
|
+
*
|
177
|
+
****************************************************************************/
|
178
|
+
|
179
|
+
/*
|
180
|
+
* Assemble and write the XML file.
|
181
|
+
*/
|
182
|
+
void
|
183
|
+
lxw_chartsheet_assemble_xml_file(lxw_chartsheet *self)
|
184
|
+
{
|
185
|
+
/* Set the embedded worksheet filehandle to the same as the chartsheet. */
|
186
|
+
self->worksheet->file = self->file;
|
187
|
+
|
188
|
+
/* Write the XML declaration. */
|
189
|
+
_chartsheet_xml_declaration(self);
|
190
|
+
|
191
|
+
/* Write the chartsheet element. */
|
192
|
+
_chartsheet_write_chartsheet(self);
|
193
|
+
|
194
|
+
/* Write the sheetPr element. */
|
195
|
+
_chartsheet_write_sheet_pr(self);
|
196
|
+
|
197
|
+
/* Write the sheetViews element. */
|
198
|
+
_chartsheet_write_sheet_views(self);
|
199
|
+
|
200
|
+
/* Write the sheetProtection element. */
|
201
|
+
_chartsheet_write_sheet_protection(self);
|
202
|
+
|
203
|
+
/* Write the pageMargins element. */
|
204
|
+
_chartsheet_write_page_margins(self);
|
205
|
+
|
206
|
+
/* Write the chartsheet page setup. */
|
207
|
+
_chartsheet_write_page_setup(self);
|
208
|
+
|
209
|
+
/* Write the headerFooter element. */
|
210
|
+
_chartsheet_write_header_footer(self);
|
211
|
+
|
212
|
+
/* Write the drawing element. */
|
213
|
+
_chartsheet_write_drawings(self);
|
214
|
+
|
215
|
+
lxw_xml_end_tag(self->file, "chartsheet");
|
216
|
+
}
|
217
|
+
|
218
|
+
/*****************************************************************************
|
219
|
+
*
|
220
|
+
* Public functions.
|
221
|
+
*
|
222
|
+
****************************************************************************/
|
223
|
+
/*
|
224
|
+
* Set a chartsheet chart, with options.
|
225
|
+
*/
|
226
|
+
lxw_error
|
227
|
+
chartsheet_set_chart_opt(lxw_chartsheet *self,
|
228
|
+
lxw_chart *chart, lxw_image_options *user_options)
|
229
|
+
{
|
230
|
+
lxw_image_options *options;
|
231
|
+
lxw_chart_series *series;
|
232
|
+
|
233
|
+
if (!chart) {
|
234
|
+
LXW_WARN("chartsheet_set_chart()/_opt(): chart must be non-NULL.");
|
235
|
+
return LXW_ERROR_NULL_PARAMETER_IGNORED;
|
236
|
+
}
|
237
|
+
|
238
|
+
/* Check that the chart isn't being used more than once. */
|
239
|
+
if (chart->in_use) {
|
240
|
+
LXW_WARN("chartsheet_set_chart()/_opt(): the same chart object "
|
241
|
+
"cannot be set for a chartsheet more than once.");
|
242
|
+
|
243
|
+
return LXW_ERROR_PARAMETER_VALIDATION;
|
244
|
+
}
|
245
|
+
|
246
|
+
/* Check that the chart has a data series. */
|
247
|
+
if (STAILQ_EMPTY(chart->series_list)) {
|
248
|
+
LXW_WARN("chartsheet_set_chart()/_opt(): chart must have a series.");
|
249
|
+
|
250
|
+
return LXW_ERROR_PARAMETER_VALIDATION;
|
251
|
+
}
|
252
|
+
|
253
|
+
/* Check that the chart has a 'values' series. */
|
254
|
+
STAILQ_FOREACH(series, chart->series_list, list_pointers) {
|
255
|
+
if (!series->values->formula && !series->values->sheetname) {
|
256
|
+
LXW_WARN("chartsheet_set_chart()/_opt(): chart must have a "
|
257
|
+
"'values' series.");
|
258
|
+
|
259
|
+
return LXW_ERROR_PARAMETER_VALIDATION;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
/* Create a new object to hold the chart image options. */
|
264
|
+
options = calloc(1, sizeof(lxw_image_options));
|
265
|
+
RETURN_ON_MEM_ERROR(options, LXW_ERROR_MEMORY_MALLOC_FAILED);
|
266
|
+
|
267
|
+
if (user_options) {
|
268
|
+
options->x_offset = user_options->x_offset;
|
269
|
+
options->y_offset = user_options->y_offset;
|
270
|
+
options->x_scale = user_options->x_scale;
|
271
|
+
options->y_scale = user_options->y_scale;
|
272
|
+
}
|
273
|
+
|
274
|
+
/* TODO. Read defaults from chart. */
|
275
|
+
options->width = 480;
|
276
|
+
options->height = 288;
|
277
|
+
|
278
|
+
if (!options->x_scale)
|
279
|
+
options->x_scale = 1;
|
280
|
+
|
281
|
+
if (!options->y_scale)
|
282
|
+
options->y_scale = 1;
|
283
|
+
|
284
|
+
/* Store chart references so they can be ordered in the workbook. */
|
285
|
+
options->chart = chart;
|
286
|
+
|
287
|
+
/* Store the chart data in the embedded worksheet. */
|
288
|
+
STAILQ_INSERT_TAIL(self->worksheet->chart_data, options, list_pointers);
|
289
|
+
|
290
|
+
chart->in_use = LXW_TRUE;
|
291
|
+
chart->is_chartsheet = LXW_TRUE;
|
292
|
+
|
293
|
+
chart->is_protected = self->is_protected;
|
294
|
+
|
295
|
+
self->chart = chart;
|
296
|
+
|
297
|
+
return LXW_NO_ERROR;
|
298
|
+
}
|
299
|
+
|
300
|
+
/*
|
301
|
+
* Set a chartsheet charts.
|
302
|
+
*/
|
303
|
+
lxw_error
|
304
|
+
chartsheet_set_chart(lxw_chartsheet *self, lxw_chart *chart)
|
305
|
+
{
|
306
|
+
return chartsheet_set_chart_opt(self, chart, NULL);
|
307
|
+
}
|
308
|
+
|
309
|
+
/*
|
310
|
+
* Set this chartsheet as a selected worksheet, i.e. the worksheet has its tab
|
311
|
+
* highlighted.
|
312
|
+
*/
|
313
|
+
void
|
314
|
+
chartsheet_select(lxw_chartsheet *self)
|
315
|
+
{
|
316
|
+
self->selected = LXW_TRUE;
|
317
|
+
|
318
|
+
/* Selected worksheet can't be hidden. */
|
319
|
+
self->hidden = LXW_FALSE;
|
320
|
+
}
|
321
|
+
|
322
|
+
/*
|
323
|
+
* Set this chartsheet as the active worksheet, i.e. the worksheet that is
|
324
|
+
* displayed when the workbook is opened. Also set it as selected.
|
325
|
+
*/
|
326
|
+
void
|
327
|
+
chartsheet_activate(lxw_chartsheet *self)
|
328
|
+
{
|
329
|
+
self->worksheet->selected = LXW_TRUE;
|
330
|
+
self->worksheet->active = LXW_TRUE;
|
331
|
+
|
332
|
+
/* Active worksheet can't be hidden. */
|
333
|
+
self->worksheet->hidden = LXW_FALSE;
|
334
|
+
|
335
|
+
*self->active_sheet = self->index;
|
336
|
+
}
|
337
|
+
|
338
|
+
/*
|
339
|
+
* Set this chartsheet as the first visible sheet. This is necessary
|
340
|
+
* when there are a large number of worksheets and the activated
|
341
|
+
* worksheet is not visible on the screen.
|
342
|
+
*/
|
343
|
+
void
|
344
|
+
chartsheet_set_first_sheet(lxw_chartsheet *self)
|
345
|
+
{
|
346
|
+
/* Active worksheet can't be hidden. */
|
347
|
+
self->hidden = LXW_FALSE;
|
348
|
+
|
349
|
+
*self->first_sheet = self->index;
|
350
|
+
}
|
351
|
+
|
352
|
+
/*
|
353
|
+
* Hide this chartsheet.
|
354
|
+
*/
|
355
|
+
void
|
356
|
+
chartsheet_hide(lxw_chartsheet *self)
|
357
|
+
{
|
358
|
+
self->hidden = LXW_TRUE;
|
359
|
+
|
360
|
+
/* A hidden worksheet shouldn't be active or selected. */
|
361
|
+
self->selected = LXW_FALSE;
|
362
|
+
|
363
|
+
/* If this is active_sheet or first_sheet reset the workbook value. */
|
364
|
+
if (*self->first_sheet == self->index)
|
365
|
+
*self->first_sheet = 0;
|
366
|
+
|
367
|
+
if (*self->active_sheet == self->index)
|
368
|
+
*self->active_sheet = 0;
|
369
|
+
}
|
370
|
+
|
371
|
+
/*
|
372
|
+
* Set the color of the chartsheet tab.
|
373
|
+
*/
|
374
|
+
void
|
375
|
+
chartsheet_set_tab_color(lxw_chartsheet *self, lxw_color_t color)
|
376
|
+
{
|
377
|
+
self->worksheet->tab_color = color;
|
378
|
+
}
|
379
|
+
|
380
|
+
/*
|
381
|
+
* Set the chartsheet protection flags to prevent modification of chartsheet
|
382
|
+
* objects.
|
383
|
+
*/
|
384
|
+
void
|
385
|
+
chartsheet_protect(lxw_chartsheet *self, const char *password,
|
386
|
+
lxw_protection *options)
|
387
|
+
{
|
388
|
+
struct lxw_protection *protect = &self->protection;
|
389
|
+
|
390
|
+
/* Copy any user parameters to the internal structure. */
|
391
|
+
if (options) {
|
392
|
+
protect->objects = options->no_objects;
|
393
|
+
protect->no_content = options->no_content;
|
394
|
+
}
|
395
|
+
else {
|
396
|
+
protect->objects = LXW_FALSE;
|
397
|
+
protect->no_content = LXW_FALSE;
|
398
|
+
}
|
399
|
+
|
400
|
+
if (password) {
|
401
|
+
uint16_t hash = lxw_hash_password(password);
|
402
|
+
lxw_snprintf(protect->hash, 5, "%X", hash);
|
403
|
+
}
|
404
|
+
else {
|
405
|
+
if (protect->objects && protect->no_content)
|
406
|
+
return;
|
407
|
+
}
|
408
|
+
|
409
|
+
protect->no_sheet = LXW_TRUE;
|
410
|
+
protect->scenarios = LXW_TRUE;
|
411
|
+
protect->is_configured = LXW_TRUE;
|
412
|
+
|
413
|
+
if (self->chart)
|
414
|
+
self->chart->is_protected = LXW_TRUE;
|
415
|
+
else
|
416
|
+
self->is_protected = LXW_TRUE;
|
417
|
+
}
|
418
|
+
|
419
|
+
/*
|
420
|
+
* Set the chartsheet zoom factor.
|
421
|
+
*/
|
422
|
+
void
|
423
|
+
chartsheet_set_zoom(lxw_chartsheet *self, uint16_t scale)
|
424
|
+
{
|
425
|
+
/* Confine the scale to Excel"s range */
|
426
|
+
if (scale < 10 || scale > 400) {
|
427
|
+
LXW_WARN("chartsheet_set_zoom(): "
|
428
|
+
"Zoom factor scale outside range: 10 <= zoom <= 400.");
|
429
|
+
return;
|
430
|
+
}
|
431
|
+
|
432
|
+
self->worksheet->zoom = scale;
|
433
|
+
}
|
434
|
+
|
435
|
+
/*
|
436
|
+
* Set the page orientation as portrait.
|
437
|
+
*/
|
438
|
+
void
|
439
|
+
chartsheet_set_portrait(lxw_chartsheet *self)
|
440
|
+
{
|
441
|
+
worksheet_set_portrait(self->worksheet);
|
442
|
+
}
|
443
|
+
|
444
|
+
/*
|
445
|
+
* Set the page orientation as landscape.
|
446
|
+
*/
|
447
|
+
void
|
448
|
+
chartsheet_set_landscape(lxw_chartsheet *self)
|
449
|
+
{
|
450
|
+
worksheet_set_landscape(self->worksheet);
|
451
|
+
}
|
452
|
+
|
453
|
+
/*
|
454
|
+
* Set the paper type. Example. 1 = US Letter, 9 = A4
|
455
|
+
*/
|
456
|
+
void
|
457
|
+
chartsheet_set_paper(lxw_chartsheet *self, uint8_t paper_size)
|
458
|
+
{
|
459
|
+
worksheet_set_paper(self->worksheet, paper_size);
|
460
|
+
}
|
461
|
+
|
462
|
+
/*
|
463
|
+
* Set all the page margins in inches.
|
464
|
+
*/
|
465
|
+
void
|
466
|
+
chartsheet_set_margins(lxw_chartsheet *self, double left, double right,
|
467
|
+
double top, double bottom)
|
468
|
+
{
|
469
|
+
worksheet_set_margins(self->worksheet, left, right, top, bottom);
|
470
|
+
}
|
471
|
+
|
472
|
+
/*
|
473
|
+
* Set the page header caption and options.
|
474
|
+
*/
|
475
|
+
lxw_error
|
476
|
+
chartsheet_set_header_opt(lxw_chartsheet *self, const char *string,
|
477
|
+
lxw_header_footer_options *options)
|
478
|
+
{
|
479
|
+
return worksheet_set_header_opt(self->worksheet, string, options);
|
480
|
+
}
|
481
|
+
|
482
|
+
/*
|
483
|
+
* Set the page footer caption and options.
|
484
|
+
*/
|
485
|
+
lxw_error
|
486
|
+
chartsheet_set_footer_opt(lxw_chartsheet *self, const char *string,
|
487
|
+
lxw_header_footer_options *options)
|
488
|
+
{
|
489
|
+
return worksheet_set_footer_opt(self->worksheet, string, options);
|
490
|
+
}
|
491
|
+
|
492
|
+
/*
|
493
|
+
* Set the page header caption.
|
494
|
+
*/
|
495
|
+
lxw_error
|
496
|
+
chartsheet_set_header(lxw_chartsheet *self, const char *string)
|
497
|
+
{
|
498
|
+
return chartsheet_set_header_opt(self, string, NULL);
|
499
|
+
}
|
500
|
+
|
501
|
+
/*
|
502
|
+
* Set the page footer caption.
|
503
|
+
*/
|
504
|
+
lxw_error
|
505
|
+
chartsheet_set_footer(lxw_chartsheet *self, const char *string)
|
506
|
+
{
|
507
|
+
return chartsheet_set_footer_opt(self, string, NULL);
|
508
|
+
}
|