xlsxwriter 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +40 -0
- data/ext/xlsxwriter/chart.c +105 -0
- data/ext/xlsxwriter/chart.h +27 -0
- data/ext/xlsxwriter/extconf.rb +14 -0
- data/ext/xlsxwriter/format.c +67 -0
- data/ext/xlsxwriter/format.h +9 -0
- data/ext/xlsxwriter/libxlsxwriter/LICENSE.txt +89 -0
- data/ext/xlsxwriter/libxlsxwriter/Makefile +141 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter.h +23 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/app.h +79 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/chart.h +1093 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/common.h +336 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/core.h +51 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +215 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/workbook.h +751 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
- data/ext/xlsxwriter/libxlsxwriter/lib/.gitignore +0 -0
- data/ext/xlsxwriter/libxlsxwriter/src/Makefile +125 -0
- data/ext/xlsxwriter/libxlsxwriter/src/app.c +439 -0
- data/ext/xlsxwriter/libxlsxwriter/src/chart.c +3420 -0
- data/ext/xlsxwriter/libxlsxwriter/src/content_types.c +341 -0
- data/ext/xlsxwriter/libxlsxwriter/src/core.c +293 -0
- data/ext/xlsxwriter/libxlsxwriter/src/custom.c +224 -0
- data/ext/xlsxwriter/libxlsxwriter/src/drawing.c +746 -0
- data/ext/xlsxwriter/libxlsxwriter/src/format.c +728 -0
- data/ext/xlsxwriter/libxlsxwriter/src/hash_table.c +223 -0
- data/ext/xlsxwriter/libxlsxwriter/src/packager.c +877 -0
- data/ext/xlsxwriter/libxlsxwriter/src/relationships.c +242 -0
- data/ext/xlsxwriter/libxlsxwriter/src/shared_strings.c +264 -0
- data/ext/xlsxwriter/libxlsxwriter/src/styles.c +1086 -0
- data/ext/xlsxwriter/libxlsxwriter/src/theme.c +348 -0
- data/ext/xlsxwriter/libxlsxwriter/src/utility.c +512 -0
- data/ext/xlsxwriter/libxlsxwriter/src/workbook.c +1895 -0
- data/ext/xlsxwriter/libxlsxwriter/src/worksheet.c +4992 -0
- data/ext/xlsxwriter/libxlsxwriter/src/xmlwriter.c +355 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/Makefile +44 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/crypt.h +131 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.h +209 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/minizip.c +520 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.c +291 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.h +37 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.h +437 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.c +2007 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.h +367 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
- data/ext/xlsxwriter/workbook.c +257 -0
- data/ext/xlsxwriter/workbook.h +42 -0
- data/ext/xlsxwriter/workbook_properties.c +103 -0
- data/ext/xlsxwriter/workbook_properties.h +10 -0
- data/ext/xlsxwriter/worksheet.c +1064 -0
- data/ext/xlsxwriter/worksheet.h +74 -0
- data/ext/xlsxwriter/xlsxwriter.c +239 -0
- data/lib/xlsxwriter.rb +6 -0
- data/lib/xlsxwriter/version.rb +3 -0
- data/lib/xlsxwriter/worksheet.rb +72 -0
- data/test/run-test.rb +11 -0
- data/test/support/xlsx_comparable.rb +109 -0
- data/test/test-array-formula.rb +33 -0
- data/test/test-autofilter.rb +70 -0
- data/test/test-chart-area.rb +25 -0
- data/test/test-data.rb +65 -0
- data/test/test-default-row.rb +25 -0
- data/test/test-defined-name.rb +46 -0
- data/test/test-escapes.rb +33 -0
- data/test/test-fit-to-pages.rb +21 -0
- data/test/test-formatting.rb +137 -0
- data/test/test-gridlines.rb +15 -0
- data/test/test-hyperlink.rb +67 -0
- data/test/test-image.rb +84 -0
- data/test/test-merge-range.rb +18 -0
- data/test/test-misc.rb +29 -0
- data/test/test-optimize.rb +32 -0
- data/test/test-page-breaks.rb +13 -0
- data/test/test-page-setup.rb +28 -0
- data/test/test-panes.rb +45 -0
- data/test/test-print-area.rb +19 -0
- data/test/test-print-options.rb +61 -0
- data/test/test-print-scale.rb +12 -0
- data/test/test-properties.rb +51 -0
- data/test/test-protect.rb +27 -0
- data/test/test-repeat.rb +23 -0
- data/test/test-row-col-format.rb +35 -0
- data/test/test-set-selection.rb +13 -0
- data/test/test-set-start-page.rb +13 -0
- data/test/test-simple.rb +62 -0
- data/test/test-types.rb +17 -0
- data/test/xlsx-func-testcase.rb +36 -0
- metadata +228 -0
@@ -0,0 +1,2641 @@
|
|
1
|
+
/*
|
2
|
+
* libxlsxwriter
|
3
|
+
*
|
4
|
+
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @page worksheet_page The Worksheet object
|
9
|
+
*
|
10
|
+
* The Worksheet object represents an Excel worksheet. It handles
|
11
|
+
* operations such as writing data to cells or formatting worksheet
|
12
|
+
* layout.
|
13
|
+
*
|
14
|
+
* See @ref worksheet.h for full details of the functionality.
|
15
|
+
*
|
16
|
+
* @file worksheet.h
|
17
|
+
*
|
18
|
+
* @brief Functions related to adding data and formatting to a worksheet.
|
19
|
+
*
|
20
|
+
* The Worksheet object represents an Excel worksheet. It handles
|
21
|
+
* operations such as writing data to cells or formatting worksheet
|
22
|
+
* layout.
|
23
|
+
*
|
24
|
+
* A Worksheet object isn't created directly. Instead a worksheet is
|
25
|
+
* created by calling the workbook_add_worksheet() function from a
|
26
|
+
* Workbook object:
|
27
|
+
*
|
28
|
+
* @code
|
29
|
+
* #include "xlsxwriter.h"
|
30
|
+
*
|
31
|
+
* int main() {
|
32
|
+
*
|
33
|
+
* lxw_workbook *workbook = workbook_new("filename.xlsx");
|
34
|
+
* lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
35
|
+
*
|
36
|
+
* worksheet_write_string(worksheet, 0, 0, "Hello Excel", NULL);
|
37
|
+
*
|
38
|
+
* return workbook_close(workbook);
|
39
|
+
* }
|
40
|
+
* @endcode
|
41
|
+
*
|
42
|
+
*/
|
43
|
+
#ifndef __LXW_WORKSHEET_H__
|
44
|
+
#define __LXW_WORKSHEET_H__
|
45
|
+
|
46
|
+
#include <stdio.h>
|
47
|
+
#include <stdlib.h>
|
48
|
+
#include <stdint.h>
|
49
|
+
#include <string.h>
|
50
|
+
|
51
|
+
#include "shared_strings.h"
|
52
|
+
#include "chart.h"
|
53
|
+
#include "drawing.h"
|
54
|
+
#include "common.h"
|
55
|
+
#include "format.h"
|
56
|
+
#include "utility.h"
|
57
|
+
|
58
|
+
#define LXW_ROW_MAX 1048576
|
59
|
+
#define LXW_COL_MAX 16384
|
60
|
+
#define LXW_COL_META_MAX 128
|
61
|
+
#define LXW_HEADER_FOOTER_MAX 255
|
62
|
+
#define LXW_MAX_NUMBER_URLS 65530
|
63
|
+
#define LXW_PANE_NAME_LENGTH 12 /* bottomRight + 1 */
|
64
|
+
|
65
|
+
/* The Excel 2007 specification says that the maximum number of page
|
66
|
+
* breaks is 1026. However, in practice it is actually 1023. */
|
67
|
+
#define LXW_BREAKS_MAX 1023
|
68
|
+
|
69
|
+
/** Default column width in Excel */
|
70
|
+
#define LXW_DEF_COL_WIDTH (double)8.43
|
71
|
+
|
72
|
+
/** Default row height in Excel */
|
73
|
+
#define LXW_DEF_ROW_HEIGHT (double)15.0
|
74
|
+
|
75
|
+
/** Gridline options using in `worksheet_gridlines()`. */
|
76
|
+
enum lxw_gridlines {
|
77
|
+
/** Hide screen and print gridlines. */
|
78
|
+
LXW_HIDE_ALL_GRIDLINES = 0,
|
79
|
+
/** Show screen gridlines. */
|
80
|
+
LXW_SHOW_SCREEN_GRIDLINES,
|
81
|
+
/** Show print gridlines. */
|
82
|
+
LXW_SHOW_PRINT_GRIDLINES,
|
83
|
+
/** Show screen and print gridlines. */
|
84
|
+
LXW_SHOW_ALL_GRIDLINES
|
85
|
+
};
|
86
|
+
|
87
|
+
enum cell_types {
|
88
|
+
NUMBER_CELL = 1,
|
89
|
+
STRING_CELL,
|
90
|
+
INLINE_STRING_CELL,
|
91
|
+
FORMULA_CELL,
|
92
|
+
ARRAY_FORMULA_CELL,
|
93
|
+
BLANK_CELL,
|
94
|
+
BOOLEAN_CELL,
|
95
|
+
HYPERLINK_URL,
|
96
|
+
HYPERLINK_INTERNAL,
|
97
|
+
HYPERLINK_EXTERNAL
|
98
|
+
};
|
99
|
+
|
100
|
+
enum pane_types {
|
101
|
+
NO_PANES = 0,
|
102
|
+
FREEZE_PANES,
|
103
|
+
SPLIT_PANES,
|
104
|
+
FREEZE_SPLIT_PANES
|
105
|
+
};
|
106
|
+
|
107
|
+
/* Define the tree.h RB structs for the red-black head types. */
|
108
|
+
RB_HEAD(lxw_table_cells, lxw_cell);
|
109
|
+
|
110
|
+
/* Define a RB_TREE struct manually to add extra members. */
|
111
|
+
struct lxw_table_rows {
|
112
|
+
struct lxw_row *rbh_root;
|
113
|
+
struct lxw_row *cached_row;
|
114
|
+
lxw_row_t cached_row_num;
|
115
|
+
};
|
116
|
+
|
117
|
+
/* Wrapper around RB_GENERATE_STATIC from tree.h to avoid unused function
|
118
|
+
* warnings and to avoid portability issues with the _unused attribute. */
|
119
|
+
#define LXW_RB_GENERATE_ROW(name, type, field, cmp) \
|
120
|
+
RB_GENERATE_INSERT_COLOR(name, type, field, static) \
|
121
|
+
RB_GENERATE_REMOVE_COLOR(name, type, field, static) \
|
122
|
+
RB_GENERATE_INSERT(name, type, field, cmp, static) \
|
123
|
+
RB_GENERATE_REMOVE(name, type, field, static) \
|
124
|
+
RB_GENERATE_FIND(name, type, field, cmp, static) \
|
125
|
+
RB_GENERATE_NEXT(name, type, field, static) \
|
126
|
+
RB_GENERATE_MINMAX(name, type, field, static) \
|
127
|
+
/* Add unused struct to allow adding a semicolon */ \
|
128
|
+
struct lxw_rb_generate_row{int unused;}
|
129
|
+
|
130
|
+
#define LXW_RB_GENERATE_CELL(name, type, field, cmp) \
|
131
|
+
RB_GENERATE_INSERT_COLOR(name, type, field, static) \
|
132
|
+
RB_GENERATE_REMOVE_COLOR(name, type, field, static) \
|
133
|
+
RB_GENERATE_INSERT(name, type, field, cmp, static) \
|
134
|
+
RB_GENERATE_REMOVE(name, type, field, static) \
|
135
|
+
RB_GENERATE_FIND(name, type, field, cmp, static) \
|
136
|
+
RB_GENERATE_NEXT(name, type, field, static) \
|
137
|
+
RB_GENERATE_MINMAX(name, type, field, static) \
|
138
|
+
/* Add unused struct to allow adding a semicolon */ \
|
139
|
+
struct lxw_rb_generate_cell{int unused;}
|
140
|
+
|
141
|
+
STAILQ_HEAD(lxw_merged_ranges, lxw_merged_range);
|
142
|
+
STAILQ_HEAD(lxw_selections, lxw_selection);
|
143
|
+
STAILQ_HEAD(lxw_image_data, lxw_image_options);
|
144
|
+
STAILQ_HEAD(lxw_chart_data, lxw_image_options);
|
145
|
+
|
146
|
+
/**
|
147
|
+
* @brief Options for rows and columns.
|
148
|
+
*
|
149
|
+
* Options struct for the worksheet_set_column() and worksheet_set_row()
|
150
|
+
* functions.
|
151
|
+
*
|
152
|
+
* It has the following members but currently only the `hidden` property is
|
153
|
+
* supported:
|
154
|
+
*
|
155
|
+
* * `hidden`
|
156
|
+
* * `level`
|
157
|
+
* * `collapsed`
|
158
|
+
*/
|
159
|
+
typedef struct lxw_row_col_options {
|
160
|
+
/** Hide the row/column */
|
161
|
+
uint8_t hidden;
|
162
|
+
uint8_t level;
|
163
|
+
uint8_t collapsed;
|
164
|
+
} lxw_row_col_options;
|
165
|
+
|
166
|
+
typedef struct lxw_col_options {
|
167
|
+
lxw_col_t firstcol;
|
168
|
+
lxw_col_t lastcol;
|
169
|
+
double width;
|
170
|
+
lxw_format *format;
|
171
|
+
uint8_t hidden;
|
172
|
+
uint8_t level;
|
173
|
+
uint8_t collapsed;
|
174
|
+
} lxw_col_options;
|
175
|
+
|
176
|
+
typedef struct lxw_merged_range {
|
177
|
+
lxw_row_t first_row;
|
178
|
+
lxw_row_t last_row;
|
179
|
+
lxw_col_t first_col;
|
180
|
+
lxw_col_t last_col;
|
181
|
+
|
182
|
+
STAILQ_ENTRY (lxw_merged_range) list_pointers;
|
183
|
+
} lxw_merged_range;
|
184
|
+
|
185
|
+
typedef struct lxw_repeat_rows {
|
186
|
+
uint8_t in_use;
|
187
|
+
lxw_row_t first_row;
|
188
|
+
lxw_row_t last_row;
|
189
|
+
} lxw_repeat_rows;
|
190
|
+
|
191
|
+
typedef struct lxw_repeat_cols {
|
192
|
+
uint8_t in_use;
|
193
|
+
lxw_col_t first_col;
|
194
|
+
lxw_col_t last_col;
|
195
|
+
} lxw_repeat_cols;
|
196
|
+
|
197
|
+
typedef struct lxw_print_area {
|
198
|
+
uint8_t in_use;
|
199
|
+
lxw_row_t first_row;
|
200
|
+
lxw_row_t last_row;
|
201
|
+
lxw_col_t first_col;
|
202
|
+
lxw_col_t last_col;
|
203
|
+
} lxw_print_area;
|
204
|
+
|
205
|
+
typedef struct lxw_autofilter {
|
206
|
+
uint8_t in_use;
|
207
|
+
lxw_row_t first_row;
|
208
|
+
lxw_row_t last_row;
|
209
|
+
lxw_col_t first_col;
|
210
|
+
lxw_col_t last_col;
|
211
|
+
} lxw_autofilter;
|
212
|
+
|
213
|
+
typedef struct lxw_panes {
|
214
|
+
uint8_t type;
|
215
|
+
lxw_row_t first_row;
|
216
|
+
lxw_col_t first_col;
|
217
|
+
lxw_row_t top_row;
|
218
|
+
lxw_col_t left_col;
|
219
|
+
double x_split;
|
220
|
+
double y_split;
|
221
|
+
} lxw_panes;
|
222
|
+
|
223
|
+
typedef struct lxw_selection {
|
224
|
+
char pane[LXW_PANE_NAME_LENGTH];
|
225
|
+
char active_cell[LXW_MAX_CELL_RANGE_LENGTH];
|
226
|
+
char sqref[LXW_MAX_CELL_RANGE_LENGTH];
|
227
|
+
|
228
|
+
STAILQ_ENTRY (lxw_selection) list_pointers;
|
229
|
+
|
230
|
+
} lxw_selection;
|
231
|
+
|
232
|
+
/**
|
233
|
+
* @brief Options for inserted images
|
234
|
+
*
|
235
|
+
* Options for modifying images inserted via `worksheet_insert_image_opt()`.
|
236
|
+
*
|
237
|
+
*/
|
238
|
+
typedef struct lxw_image_options {
|
239
|
+
|
240
|
+
/** Offset from the left of the cell in pixels. */
|
241
|
+
int32_t x_offset;
|
242
|
+
|
243
|
+
/** Offset from the top of the cell in pixels. */
|
244
|
+
int32_t y_offset;
|
245
|
+
|
246
|
+
/** X scale of the image as a decimal. */
|
247
|
+
double x_scale;
|
248
|
+
|
249
|
+
/** Y scale of the image as a decimal. */
|
250
|
+
double y_scale;
|
251
|
+
|
252
|
+
lxw_row_t row;
|
253
|
+
lxw_col_t col;
|
254
|
+
char *filename;
|
255
|
+
char *url;
|
256
|
+
char *tip;
|
257
|
+
uint8_t anchor;
|
258
|
+
|
259
|
+
/* Internal metadata. */
|
260
|
+
FILE *stream;
|
261
|
+
uint8_t image_type;
|
262
|
+
double width;
|
263
|
+
double height;
|
264
|
+
char *short_name;
|
265
|
+
char *extension;
|
266
|
+
double x_dpi;
|
267
|
+
double y_dpi;
|
268
|
+
lxw_chart *chart;
|
269
|
+
|
270
|
+
STAILQ_ENTRY (lxw_image_options) list_pointers;
|
271
|
+
|
272
|
+
} lxw_image_options;
|
273
|
+
|
274
|
+
/**
|
275
|
+
* @brief Header and footer options.
|
276
|
+
*
|
277
|
+
* Optional parameters used in the worksheet_set_header_opt() and
|
278
|
+
* worksheet_set_footer_opt() functions.
|
279
|
+
*
|
280
|
+
*/
|
281
|
+
typedef struct lxw_header_footer_options {
|
282
|
+
/** Header or footer margin in inches. Excel default is 0.3. */
|
283
|
+
double margin;
|
284
|
+
} lxw_header_footer_options;
|
285
|
+
|
286
|
+
/**
|
287
|
+
* @brief Worksheet protection options.
|
288
|
+
*/
|
289
|
+
typedef struct lxw_protection {
|
290
|
+
/** Turn off selection of locked cells. This in on in Excel by default.*/
|
291
|
+
uint8_t no_select_locked_cells;
|
292
|
+
|
293
|
+
/** Turn off selection of unlocked cells. This in on in Excel by default.*/
|
294
|
+
uint8_t no_select_unlocked_cells;
|
295
|
+
|
296
|
+
/** Prevent formatting of cells. */
|
297
|
+
uint8_t format_cells;
|
298
|
+
|
299
|
+
/** Prevent formatting of columns. */
|
300
|
+
uint8_t format_columns;
|
301
|
+
|
302
|
+
/** Prevent formatting of rows. */
|
303
|
+
uint8_t format_rows;
|
304
|
+
|
305
|
+
/** Prevent insertion of columns. */
|
306
|
+
uint8_t insert_columns;
|
307
|
+
|
308
|
+
/** Prevent insertion of rows. */
|
309
|
+
uint8_t insert_rows;
|
310
|
+
|
311
|
+
/** Prevent insertion of hyperlinks. */
|
312
|
+
uint8_t insert_hyperlinks;
|
313
|
+
|
314
|
+
/** Prevent deletion of columns. */
|
315
|
+
uint8_t delete_columns;
|
316
|
+
|
317
|
+
/** Prevent deletion of rows. */
|
318
|
+
uint8_t delete_rows;
|
319
|
+
|
320
|
+
/** Prevent sorting data. */
|
321
|
+
uint8_t sort;
|
322
|
+
|
323
|
+
/** Prevent filtering data. */
|
324
|
+
uint8_t autofilter;
|
325
|
+
|
326
|
+
/** Prevent insertion of pivot tables. */
|
327
|
+
uint8_t pivot_tables;
|
328
|
+
|
329
|
+
/** Protect scenarios. */
|
330
|
+
uint8_t scenarios;
|
331
|
+
|
332
|
+
/** Protect drawing objects. */
|
333
|
+
uint8_t objects;
|
334
|
+
|
335
|
+
uint8_t no_sheet;
|
336
|
+
uint8_t content;
|
337
|
+
uint8_t is_configured;
|
338
|
+
char hash[5];
|
339
|
+
} lxw_protection;
|
340
|
+
|
341
|
+
/**
|
342
|
+
* @brief Struct to represent an Excel worksheet.
|
343
|
+
*
|
344
|
+
* The members of the lxw_worksheet struct aren't modified directly. Instead
|
345
|
+
* the worksheet properties are set by calling the functions shown in
|
346
|
+
* worksheet.h.
|
347
|
+
*/
|
348
|
+
typedef struct lxw_worksheet {
|
349
|
+
|
350
|
+
FILE *file;
|
351
|
+
FILE *optimize_tmpfile;
|
352
|
+
struct lxw_table_rows *table;
|
353
|
+
struct lxw_table_rows *hyperlinks;
|
354
|
+
struct lxw_cell **array;
|
355
|
+
struct lxw_merged_ranges *merged_ranges;
|
356
|
+
struct lxw_selections *selections;
|
357
|
+
struct lxw_image_data *image_data;
|
358
|
+
struct lxw_chart_data *chart_data;
|
359
|
+
|
360
|
+
lxw_row_t dim_rowmin;
|
361
|
+
lxw_row_t dim_rowmax;
|
362
|
+
lxw_col_t dim_colmin;
|
363
|
+
lxw_col_t dim_colmax;
|
364
|
+
|
365
|
+
lxw_sst *sst;
|
366
|
+
char *name;
|
367
|
+
char *quoted_name;
|
368
|
+
char *tmpdir;
|
369
|
+
|
370
|
+
uint32_t index;
|
371
|
+
uint8_t active;
|
372
|
+
uint8_t selected;
|
373
|
+
uint8_t hidden;
|
374
|
+
uint16_t *active_sheet;
|
375
|
+
uint16_t *first_sheet;
|
376
|
+
|
377
|
+
lxw_col_options **col_options;
|
378
|
+
uint16_t col_options_max;
|
379
|
+
|
380
|
+
double *col_sizes;
|
381
|
+
uint16_t col_sizes_max;
|
382
|
+
|
383
|
+
lxw_format **col_formats;
|
384
|
+
uint16_t col_formats_max;
|
385
|
+
|
386
|
+
uint8_t col_size_changed;
|
387
|
+
uint8_t row_size_changed;
|
388
|
+
uint8_t optimize;
|
389
|
+
struct lxw_row *optimize_row;
|
390
|
+
|
391
|
+
uint16_t fit_height;
|
392
|
+
uint16_t fit_width;
|
393
|
+
uint16_t horizontal_dpi;
|
394
|
+
uint16_t hlink_count;
|
395
|
+
uint16_t page_start;
|
396
|
+
uint16_t print_scale;
|
397
|
+
uint16_t rel_count;
|
398
|
+
uint16_t vertical_dpi;
|
399
|
+
uint16_t zoom;
|
400
|
+
uint8_t filter_on;
|
401
|
+
uint8_t fit_page;
|
402
|
+
uint8_t hcenter;
|
403
|
+
uint8_t orientation;
|
404
|
+
uint8_t outline_changed;
|
405
|
+
uint8_t outline_on;
|
406
|
+
uint8_t page_order;
|
407
|
+
uint8_t page_setup_changed;
|
408
|
+
uint8_t page_view;
|
409
|
+
uint8_t paper_size;
|
410
|
+
uint8_t print_gridlines;
|
411
|
+
uint8_t print_headers;
|
412
|
+
uint8_t print_options_changed;
|
413
|
+
uint8_t right_to_left;
|
414
|
+
uint8_t screen_gridlines;
|
415
|
+
uint8_t show_zeros;
|
416
|
+
uint8_t vba_codename;
|
417
|
+
uint8_t vcenter;
|
418
|
+
uint8_t zoom_scale_normal;
|
419
|
+
|
420
|
+
lxw_color_t tab_color;
|
421
|
+
|
422
|
+
double margin_left;
|
423
|
+
double margin_right;
|
424
|
+
double margin_top;
|
425
|
+
double margin_bottom;
|
426
|
+
double margin_header;
|
427
|
+
double margin_footer;
|
428
|
+
|
429
|
+
double default_row_height;
|
430
|
+
uint32_t default_row_pixels;
|
431
|
+
uint32_t default_col_pixels;
|
432
|
+
uint8_t default_row_zeroed;
|
433
|
+
uint8_t default_row_set;
|
434
|
+
|
435
|
+
uint8_t header_footer_changed;
|
436
|
+
char header[LXW_HEADER_FOOTER_MAX];
|
437
|
+
char footer[LXW_HEADER_FOOTER_MAX];
|
438
|
+
|
439
|
+
struct lxw_repeat_rows repeat_rows;
|
440
|
+
struct lxw_repeat_cols repeat_cols;
|
441
|
+
struct lxw_print_area print_area;
|
442
|
+
struct lxw_autofilter autofilter;
|
443
|
+
|
444
|
+
uint16_t merged_range_count;
|
445
|
+
|
446
|
+
lxw_row_t *hbreaks;
|
447
|
+
lxw_col_t *vbreaks;
|
448
|
+
uint16_t hbreaks_count;
|
449
|
+
uint16_t vbreaks_count;
|
450
|
+
|
451
|
+
struct lxw_rel_tuples *external_hyperlinks;
|
452
|
+
struct lxw_rel_tuples *external_drawing_links;
|
453
|
+
struct lxw_rel_tuples *drawing_links;
|
454
|
+
|
455
|
+
struct lxw_panes panes;
|
456
|
+
|
457
|
+
struct lxw_protection protection;
|
458
|
+
|
459
|
+
lxw_drawing *drawing;
|
460
|
+
|
461
|
+
STAILQ_ENTRY (lxw_worksheet) list_pointers;
|
462
|
+
|
463
|
+
} lxw_worksheet;
|
464
|
+
|
465
|
+
/*
|
466
|
+
* Worksheet initialization data.
|
467
|
+
*/
|
468
|
+
typedef struct lxw_worksheet_init_data {
|
469
|
+
uint32_t index;
|
470
|
+
uint8_t hidden;
|
471
|
+
uint8_t optimize;
|
472
|
+
uint16_t *active_sheet;
|
473
|
+
uint16_t *first_sheet;
|
474
|
+
lxw_sst *sst;
|
475
|
+
char *name;
|
476
|
+
char *quoted_name;
|
477
|
+
char *tmpdir;
|
478
|
+
|
479
|
+
} lxw_worksheet_init_data;
|
480
|
+
|
481
|
+
/* Struct to represent a worksheet row. */
|
482
|
+
typedef struct lxw_row {
|
483
|
+
lxw_row_t row_num;
|
484
|
+
double height;
|
485
|
+
lxw_format *format;
|
486
|
+
uint8_t hidden;
|
487
|
+
uint8_t level;
|
488
|
+
uint8_t collapsed;
|
489
|
+
uint8_t row_changed;
|
490
|
+
uint8_t data_changed;
|
491
|
+
uint8_t height_changed;
|
492
|
+
struct lxw_table_cells *cells;
|
493
|
+
|
494
|
+
/* tree management pointers for tree.h. */
|
495
|
+
RB_ENTRY (lxw_row) tree_pointers;
|
496
|
+
} lxw_row;
|
497
|
+
|
498
|
+
/* Struct to represent a worksheet cell. */
|
499
|
+
typedef struct lxw_cell {
|
500
|
+
lxw_row_t row_num;
|
501
|
+
lxw_col_t col_num;
|
502
|
+
enum cell_types type;
|
503
|
+
lxw_format *format;
|
504
|
+
|
505
|
+
union {
|
506
|
+
double number;
|
507
|
+
int32_t string_id;
|
508
|
+
char *string;
|
509
|
+
} u;
|
510
|
+
|
511
|
+
double formula_result;
|
512
|
+
char *user_data1;
|
513
|
+
char *user_data2;
|
514
|
+
char *sst_string;
|
515
|
+
|
516
|
+
/* List pointers for tree.h. */
|
517
|
+
RB_ENTRY (lxw_cell) tree_pointers;
|
518
|
+
} lxw_cell;
|
519
|
+
|
520
|
+
/* *INDENT-OFF* */
|
521
|
+
#ifdef __cplusplus
|
522
|
+
extern "C" {
|
523
|
+
#endif
|
524
|
+
/* *INDENT-ON* */
|
525
|
+
|
526
|
+
/**
|
527
|
+
* @brief Write a number to a worksheet cell.
|
528
|
+
*
|
529
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
530
|
+
* @param row The zero indexed row number.
|
531
|
+
* @param col The zero indexed column number.
|
532
|
+
* @param number The number to write to the cell.
|
533
|
+
* @param format A pointer to a Format instance or NULL.
|
534
|
+
*
|
535
|
+
* @return A #lxw_error code.
|
536
|
+
*
|
537
|
+
* The `worksheet_write_number()` function writes numeric types to the cell
|
538
|
+
* specified by `row` and `column`:
|
539
|
+
*
|
540
|
+
* @code
|
541
|
+
* worksheet_write_number(worksheet, 0, 0, 123456, NULL);
|
542
|
+
* worksheet_write_number(worksheet, 1, 0, 2.3451, NULL);
|
543
|
+
* @endcode
|
544
|
+
*
|
545
|
+
* @image html write_number01.png
|
546
|
+
*
|
547
|
+
* The native data type for all numbers in Excel is a IEEE-754 64-bit
|
548
|
+
* double-precision floating point, which is also the default type used by
|
549
|
+
* `%worksheet_write_number`.
|
550
|
+
*
|
551
|
+
* The `format` parameter is used to apply formatting to the cell. This
|
552
|
+
* parameter can be `NULL` to indicate no formatting or it can be a
|
553
|
+
* @ref format.h "Format" object.
|
554
|
+
*
|
555
|
+
* @code
|
556
|
+
* lxw_format *format = workbook_add_format(workbook);
|
557
|
+
* format_set_num_format(format, "$#,##0.00");
|
558
|
+
*
|
559
|
+
* worksheet_write_number(worksheet, 0, 0, 1234.567, format);
|
560
|
+
* @endcode
|
561
|
+
*
|
562
|
+
* @image html write_number02.png
|
563
|
+
*
|
564
|
+
*/
|
565
|
+
lxw_error worksheet_write_number(lxw_worksheet *worksheet,
|
566
|
+
lxw_row_t row,
|
567
|
+
lxw_col_t col, double number,
|
568
|
+
lxw_format *format);
|
569
|
+
/**
|
570
|
+
* @brief Write a string to a worksheet cell.
|
571
|
+
*
|
572
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
573
|
+
* @param row The zero indexed row number.
|
574
|
+
* @param col The zero indexed column number.
|
575
|
+
* @param string String to write to cell.
|
576
|
+
* @param format A pointer to a Format instance or NULL.
|
577
|
+
*
|
578
|
+
* @return A #lxw_error code.
|
579
|
+
*
|
580
|
+
* The `%worksheet_write_string()` function writes a string to the cell
|
581
|
+
* specified by `row` and `column`:
|
582
|
+
*
|
583
|
+
* @code
|
584
|
+
* worksheet_write_string(worksheet, 0, 0, "This phrase is English!", NULL);
|
585
|
+
* @endcode
|
586
|
+
*
|
587
|
+
* @image html write_string01.png
|
588
|
+
*
|
589
|
+
* The `format` parameter is used to apply formatting to the cell. This
|
590
|
+
* parameter can be `NULL` to indicate no formatting or it can be a
|
591
|
+
* @ref format.h "Format" object:
|
592
|
+
*
|
593
|
+
* @code
|
594
|
+
* lxw_format *format = workbook_add_format(workbook);
|
595
|
+
* format_set_bold(format);
|
596
|
+
*
|
597
|
+
* worksheet_write_string(worksheet, 0, 0, "This phrase is Bold!", format);
|
598
|
+
* @endcode
|
599
|
+
*
|
600
|
+
* @image html write_string02.png
|
601
|
+
*
|
602
|
+
* Unicode strings are supported in UTF-8 encoding. This generally requires
|
603
|
+
* that your source file is UTF-8 encoded or that the data has been read from
|
604
|
+
* a UTF-8 source:
|
605
|
+
*
|
606
|
+
* @code
|
607
|
+
* worksheet_write_string(worksheet, 0, 0, "Это фраза на русском!", NULL);
|
608
|
+
* @endcode
|
609
|
+
*
|
610
|
+
* @image html write_string03.png
|
611
|
+
*
|
612
|
+
*/
|
613
|
+
lxw_error worksheet_write_string(lxw_worksheet *worksheet,
|
614
|
+
lxw_row_t row,
|
615
|
+
lxw_col_t col, const char *string,
|
616
|
+
lxw_format *format);
|
617
|
+
/**
|
618
|
+
* @brief Write a formula to a worksheet cell.
|
619
|
+
*
|
620
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
621
|
+
* @param row The zero indexed row number.
|
622
|
+
* @param col The zero indexed column number.
|
623
|
+
* @param formula Formula string to write to cell.
|
624
|
+
* @param format A pointer to a Format instance or NULL.
|
625
|
+
*
|
626
|
+
* @return A #lxw_error code.
|
627
|
+
*
|
628
|
+
* The `%worksheet_write_formula()` function writes a formula or function to
|
629
|
+
* the cell specified by `row` and `column`:
|
630
|
+
*
|
631
|
+
* @code
|
632
|
+
* worksheet_write_formula(worksheet, 0, 0, "=B3 + 6", NULL);
|
633
|
+
* worksheet_write_formula(worksheet, 1, 0, "=SIN(PI()/4)", NULL);
|
634
|
+
* worksheet_write_formula(worksheet, 2, 0, "=SUM(A1:A2)", NULL);
|
635
|
+
* worksheet_write_formula(worksheet, 3, 0, "=IF(A3>1,\"Yes\", \"No\")", NULL);
|
636
|
+
* worksheet_write_formula(worksheet, 4, 0, "=AVERAGE(1, 2, 3, 4)", NULL);
|
637
|
+
* worksheet_write_formula(worksheet, 5, 0, "=DATEVALUE(\"1-Jan-2013\")", NULL);
|
638
|
+
* @endcode
|
639
|
+
*
|
640
|
+
* @image html write_formula01.png
|
641
|
+
*
|
642
|
+
* The `format` parameter is used to apply formatting to the cell. This
|
643
|
+
* parameter can be `NULL` to indicate no formatting or it can be a
|
644
|
+
* @ref format.h "Format" object.
|
645
|
+
*
|
646
|
+
* Libxlsxwriter doesn't calculate the value of a formula and instead stores a
|
647
|
+
* default value of `0`. The correct formula result is displayed in Excel, as
|
648
|
+
* shown in the example above, since it recalculates the formulas when it loads
|
649
|
+
* the file. For cases where this is an issue see the
|
650
|
+
* `worksheet_write_formula_num()` function and the discussion in that section.
|
651
|
+
*
|
652
|
+
* Formulas must be written with the US style separator/range operator which
|
653
|
+
* is a comma (not semi-colon). Therefore a formula with multiple values
|
654
|
+
* should be written as follows:
|
655
|
+
*
|
656
|
+
* @code
|
657
|
+
* // OK.
|
658
|
+
* worksheet_write_formula(worksheet, 0, 0, "=SUM(1, 2, 3)", NULL);
|
659
|
+
*
|
660
|
+
* // NO. Error on load.
|
661
|
+
* worksheet_write_formula(worksheet, 1, 0, "=SUM(1; 2; 3)", NULL);
|
662
|
+
* @endcode
|
663
|
+
*
|
664
|
+
*/
|
665
|
+
lxw_error worksheet_write_formula(lxw_worksheet *worksheet,
|
666
|
+
lxw_row_t row,
|
667
|
+
lxw_col_t col, const char *formula,
|
668
|
+
lxw_format *format);
|
669
|
+
/**
|
670
|
+
* @brief Write an array formula to a worksheet cell.
|
671
|
+
*
|
672
|
+
* @param worksheet
|
673
|
+
* @param first_row The first row of the range. (All zero indexed.)
|
674
|
+
* @param first_col The first column of the range.
|
675
|
+
* @param last_row The last row of the range.
|
676
|
+
* @param last_col The last col of the range.
|
677
|
+
* @param formula Array formula to write to cell.
|
678
|
+
* @param format A pointer to a Format instance or NULL.
|
679
|
+
*
|
680
|
+
* @return A #lxw_error code.
|
681
|
+
*
|
682
|
+
* The `%worksheet_write_array_formula()` function writes an array formula to
|
683
|
+
* a cell range. In Excel an array formula is a formula that performs a
|
684
|
+
* calculation on a set of values.
|
685
|
+
*
|
686
|
+
* In Excel an array formula is indicated by a pair of braces around the
|
687
|
+
* formula: `{=SUM(A1:B1*A2:B2)}`.
|
688
|
+
*
|
689
|
+
* Array formulas can return a single value or a range or values. For array
|
690
|
+
* formulas that return a range of values you must specify the range that the
|
691
|
+
* return values will be written to. This is why this function has `first_`
|
692
|
+
* and `last_` row/column parameters. The RANGE() macro can also be used to
|
693
|
+
* specify the range:
|
694
|
+
*
|
695
|
+
* @code
|
696
|
+
* worksheet_write_array_formula(worksheet, 4, 0, 6, 0, "{=TREND(C5:C7,B5:B7)}", NULL);
|
697
|
+
*
|
698
|
+
* // Same as above using the RANGE() macro.
|
699
|
+
* worksheet_write_array_formula(worksheet, RANGE("A5:A7"), "{=TREND(C5:C7,B5:B7)}", NULL);
|
700
|
+
* @endcode
|
701
|
+
*
|
702
|
+
* If the array formula returns a single value then the `first_` and `last_`
|
703
|
+
* parameters should be the same:
|
704
|
+
*
|
705
|
+
* @code
|
706
|
+
* worksheet_write_array_formula(worksheet, 1, 0, 1, 0, "{=SUM(B1:C1*B2:C2)}", NULL);
|
707
|
+
* worksheet_write_array_formula(worksheet, RANGE("A2:A2"), "{=SUM(B1:C1*B2:C2)}", NULL);
|
708
|
+
* @endcode
|
709
|
+
*
|
710
|
+
*/
|
711
|
+
lxw_error worksheet_write_array_formula(lxw_worksheet *worksheet,
|
712
|
+
lxw_row_t first_row,
|
713
|
+
lxw_col_t first_col,
|
714
|
+
lxw_row_t last_row,
|
715
|
+
lxw_col_t last_col,
|
716
|
+
const char *formula,
|
717
|
+
lxw_format *format);
|
718
|
+
|
719
|
+
lxw_error worksheet_write_array_formula_num(lxw_worksheet *worksheet,
|
720
|
+
lxw_row_t first_row,
|
721
|
+
lxw_col_t first_col,
|
722
|
+
lxw_row_t last_row,
|
723
|
+
lxw_col_t last_col,
|
724
|
+
const char *formula,
|
725
|
+
lxw_format *format,
|
726
|
+
double result);
|
727
|
+
|
728
|
+
/**
|
729
|
+
* @brief Write a date or time to a worksheet cell.
|
730
|
+
*
|
731
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
732
|
+
* @param row The zero indexed row number.
|
733
|
+
* @param col The zero indexed column number.
|
734
|
+
* @param datetime The datetime to write to the cell.
|
735
|
+
* @param format A pointer to a Format instance or NULL.
|
736
|
+
*
|
737
|
+
* @return A #lxw_error code.
|
738
|
+
*
|
739
|
+
* The `worksheet_write_datetime()` function can be used to write a date or
|
740
|
+
* time to the cell specified by `row` and `column`:
|
741
|
+
*
|
742
|
+
* @dontinclude dates_and_times02.c
|
743
|
+
* @skip include
|
744
|
+
* @until num_format
|
745
|
+
* @skip Feb
|
746
|
+
* @until }
|
747
|
+
*
|
748
|
+
* The `format` parameter should be used to apply formatting to the cell using
|
749
|
+
* a @ref format.h "Format" object as shown above. Without a date format the
|
750
|
+
* datetime will appear as a number only.
|
751
|
+
*
|
752
|
+
* See @ref working_with_dates for more information about handling dates and
|
753
|
+
* times in libxlsxwriter.
|
754
|
+
*/
|
755
|
+
lxw_error worksheet_write_datetime(lxw_worksheet *worksheet,
|
756
|
+
lxw_row_t row,
|
757
|
+
lxw_col_t col, lxw_datetime *datetime,
|
758
|
+
lxw_format *format);
|
759
|
+
|
760
|
+
lxw_error worksheet_write_url_opt(lxw_worksheet *worksheet,
|
761
|
+
lxw_row_t row_num,
|
762
|
+
lxw_col_t col_num, const char *url,
|
763
|
+
lxw_format *format, const char *string,
|
764
|
+
const char *tooltip);
|
765
|
+
/**
|
766
|
+
*
|
767
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
768
|
+
* @param row The zero indexed row number.
|
769
|
+
* @param col The zero indexed column number.
|
770
|
+
* @param url The url to write to the cell.
|
771
|
+
* @param format A pointer to a Format instance or NULL.
|
772
|
+
*
|
773
|
+
* @return A #lxw_error code.
|
774
|
+
*
|
775
|
+
*
|
776
|
+
* The `%worksheet_write_url()` function is used to write a URL/hyperlink to a
|
777
|
+
* worksheet cell specified by `row` and `column`.
|
778
|
+
*
|
779
|
+
* @code
|
780
|
+
* worksheet_write_url(worksheet, 0, 0, "http://libxlsxwriter.github.io", url_format);
|
781
|
+
* @endcode
|
782
|
+
*
|
783
|
+
* @image html hyperlinks_short.png
|
784
|
+
*
|
785
|
+
* The `format` parameter is used to apply formatting to the cell. This
|
786
|
+
* parameter can be `NULL` to indicate no formatting or it can be a @ref
|
787
|
+
* format.h "Format" object. The typical worksheet format for a hyperlink is a
|
788
|
+
* blue underline:
|
789
|
+
*
|
790
|
+
* @code
|
791
|
+
* lxw_format *url_format = workbook_add_format(workbook);
|
792
|
+
*
|
793
|
+
* format_set_underline (url_format, LXW_UNDERLINE_SINGLE);
|
794
|
+
* format_set_font_color(url_format, LXW_COLOR_BLUE);
|
795
|
+
*
|
796
|
+
* @endcode
|
797
|
+
*
|
798
|
+
* The usual web style URI's are supported: `%http://`, `%https://`, `%ftp://`
|
799
|
+
* and `mailto:` :
|
800
|
+
*
|
801
|
+
* @code
|
802
|
+
* worksheet_write_url(worksheet, 0, 0, "ftp://www.python.org/", url_format);
|
803
|
+
* worksheet_write_url(worksheet, 1, 0, "http://www.python.org/", url_format);
|
804
|
+
* worksheet_write_url(worksheet, 2, 0, "https://www.python.org/", url_format);
|
805
|
+
* worksheet_write_url(worksheet, 3, 0, "mailto:jmcnamara@cpan.org", url_format);
|
806
|
+
*
|
807
|
+
* @endcode
|
808
|
+
*
|
809
|
+
* An Excel hyperlink is comprised of two elements: the displayed string and
|
810
|
+
* the non-displayed link. By default the displayed string is the same as the
|
811
|
+
* link. However, it is possible to overwrite it with any other
|
812
|
+
* `libxlsxwriter` type using the appropriate `worksheet_write_*()`
|
813
|
+
* function. The most common case is to overwrite the displayed link text with
|
814
|
+
* another string:
|
815
|
+
*
|
816
|
+
* @code
|
817
|
+
* // Write a hyperlink but overwrite the displayed string.
|
818
|
+
* worksheet_write_url (worksheet, 2, 0, "http://libxlsxwriter.github.io", url_format);
|
819
|
+
* worksheet_write_string(worksheet, 2, 0, "Read the documentation.", url_format);
|
820
|
+
*
|
821
|
+
* @endcode
|
822
|
+
*
|
823
|
+
* @image html hyperlinks_short2.png
|
824
|
+
*
|
825
|
+
* Two local URIs are supported: `internal:` and `external:`. These are used
|
826
|
+
* for hyperlinks to internal worksheet references or external workbook and
|
827
|
+
* worksheet references:
|
828
|
+
*
|
829
|
+
* @code
|
830
|
+
* worksheet_write_url(worksheet, 0, 0, "internal:Sheet2!A1", url_format);
|
831
|
+
* worksheet_write_url(worksheet, 1, 0, "internal:Sheet2!B2", url_format);
|
832
|
+
* worksheet_write_url(worksheet, 2, 0, "internal:Sheet2!A1:B2", url_format);
|
833
|
+
* worksheet_write_url(worksheet, 3, 0, "internal:'Sales Data'!A1", url_format);
|
834
|
+
* worksheet_write_url(worksheet, 4, 0, "external:c:\\temp\\foo.xlsx", url_format);
|
835
|
+
* worksheet_write_url(worksheet, 5, 0, "external:c:\\foo.xlsx#Sheet2!A1", url_format);
|
836
|
+
* worksheet_write_url(worksheet, 6, 0, "external:..\\foo.xlsx", url_format);
|
837
|
+
* worksheet_write_url(worksheet, 7, 0, "external:..\\foo.xlsx#Sheet2!A1", url_format);
|
838
|
+
* worksheet_write_url(worksheet, 8, 0, "external:\\\\NET\\share\\foo.xlsx", url_format);
|
839
|
+
*
|
840
|
+
* @endcode
|
841
|
+
*
|
842
|
+
* Worksheet references are typically of the form `Sheet1!A1`. You can also
|
843
|
+
* link to a worksheet range using the standard Excel notation:
|
844
|
+
* `Sheet1!A1:B2`.
|
845
|
+
*
|
846
|
+
* In external links the workbook and worksheet name must be separated by the
|
847
|
+
* `#` character:
|
848
|
+
*
|
849
|
+
* @code
|
850
|
+
* worksheet_write_url(worksheet, 0, 0, "external:c:\\foo.xlsx#Sheet2!A1", url_format);
|
851
|
+
* @endcode
|
852
|
+
*
|
853
|
+
* You can also link to a named range in the target worksheet: For example say
|
854
|
+
* you have a named range called `my_name` in the workbook `c:\temp\foo.xlsx`
|
855
|
+
* you could link to it as follows:
|
856
|
+
*
|
857
|
+
* @code
|
858
|
+
* worksheet_write_url(worksheet, 0, 0, "external:c:\\temp\\foo.xlsx#my_name", url_format);
|
859
|
+
*
|
860
|
+
* @endcode
|
861
|
+
*
|
862
|
+
* Excel requires that worksheet names containing spaces or non alphanumeric
|
863
|
+
* characters are single quoted as follows:
|
864
|
+
*
|
865
|
+
* @code
|
866
|
+
* worksheet_write_url(worksheet, 0, 0, "internal:'Sales Data'!A1", url_format);
|
867
|
+
* @endcode
|
868
|
+
*
|
869
|
+
* Links to network files are also supported. Network files normally begin
|
870
|
+
* with two back slashes as follows `\\NETWORK\etc`. In order to represent
|
871
|
+
* this in a C string literal the backslashes should be escaped:
|
872
|
+
* @code
|
873
|
+
* worksheet_write_url(worksheet, 0, 0, "external:\\\\NET\\share\\foo.xlsx", url_format);
|
874
|
+
* @endcode
|
875
|
+
*
|
876
|
+
*
|
877
|
+
* Alternatively, you can use Windows style forward slashes. These are
|
878
|
+
* translated internally to backslashes:
|
879
|
+
*
|
880
|
+
* @code
|
881
|
+
* worksheet_write_url(worksheet, 0, 0, "external:c:/temp/foo.xlsx", url_format);
|
882
|
+
* worksheet_write_url(worksheet, 1, 0, "external://NET/share/foo.xlsx", url_format);
|
883
|
+
*
|
884
|
+
* @endcode
|
885
|
+
*
|
886
|
+
*
|
887
|
+
* **Note:**
|
888
|
+
*
|
889
|
+
* libxlsxwriter will escape the following characters in URLs as required
|
890
|
+
* by Excel: `\s " < > \ [ ] ^ { }` unless the URL already contains `%%xx`
|
891
|
+
* style escapes. In which case it is assumed that the URL was escaped
|
892
|
+
* correctly by the user and will by passed directly to Excel.
|
893
|
+
*
|
894
|
+
*/
|
895
|
+
lxw_error worksheet_write_url(lxw_worksheet *worksheet,
|
896
|
+
lxw_row_t row,
|
897
|
+
lxw_col_t col, const char *url,
|
898
|
+
lxw_format *format);
|
899
|
+
|
900
|
+
/**
|
901
|
+
* @brief Write a formatted boolean worksheet cell.
|
902
|
+
*
|
903
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
904
|
+
* @param row The zero indexed row number.
|
905
|
+
* @param col The zero indexed column number.
|
906
|
+
* @param value The boolean value to write to the cell.
|
907
|
+
* @param format A pointer to a Format instance or NULL.
|
908
|
+
*
|
909
|
+
* @return A #lxw_error code.
|
910
|
+
*
|
911
|
+
* Write an Excel boolean to the cell specified by `row` and `column`:
|
912
|
+
*
|
913
|
+
* @code
|
914
|
+
* worksheet_write_boolean(worksheet, 2, 2, 0, my_format);
|
915
|
+
* @endcode
|
916
|
+
*
|
917
|
+
*/
|
918
|
+
lxw_error worksheet_write_boolean(lxw_worksheet *worksheet,
|
919
|
+
lxw_row_t row, lxw_col_t col,
|
920
|
+
int value, lxw_format *format);
|
921
|
+
|
922
|
+
/**
|
923
|
+
* @brief Write a formatted blank worksheet cell.
|
924
|
+
*
|
925
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
926
|
+
* @param row The zero indexed row number.
|
927
|
+
* @param col The zero indexed column number.
|
928
|
+
* @param format A pointer to a Format instance or NULL.
|
929
|
+
*
|
930
|
+
* @return A #lxw_error code.
|
931
|
+
*
|
932
|
+
* Write a blank cell specified by `row` and `column`:
|
933
|
+
*
|
934
|
+
* @code
|
935
|
+
* worksheet_write_blank(worksheet, 1, 1, border_format);
|
936
|
+
* @endcode
|
937
|
+
*
|
938
|
+
* This function is used to add formatting to a cell which doesn't contain a
|
939
|
+
* string or number value.
|
940
|
+
*
|
941
|
+
* Excel differentiates between an "Empty" cell and a "Blank" cell. An Empty
|
942
|
+
* cell is a cell which doesn't contain data or formatting whilst a Blank cell
|
943
|
+
* doesn't contain data but does contain formatting. Excel stores Blank cells
|
944
|
+
* but ignores Empty cells.
|
945
|
+
*
|
946
|
+
* As such, if you write an empty cell without formatting it is ignored.
|
947
|
+
*
|
948
|
+
*/
|
949
|
+
lxw_error worksheet_write_blank(lxw_worksheet *worksheet,
|
950
|
+
lxw_row_t row, lxw_col_t col,
|
951
|
+
lxw_format *format);
|
952
|
+
|
953
|
+
/**
|
954
|
+
* @brief Write a formula to a worksheet cell with a user defined result.
|
955
|
+
*
|
956
|
+
* @param worksheet pointer to a lxw_worksheet instance to be updated.
|
957
|
+
* @param row The zero indexed row number.
|
958
|
+
* @param col The zero indexed column number.
|
959
|
+
* @param formula Formula string to write to cell.
|
960
|
+
* @param format A pointer to a Format instance or NULL.
|
961
|
+
* @param result A user defined result for a formula.
|
962
|
+
*
|
963
|
+
* @return A #lxw_error code.
|
964
|
+
*
|
965
|
+
* The `%worksheet_write_formula_num()` function writes a formula or Excel
|
966
|
+
* function to the cell specified by `row` and `column` with a user defined
|
967
|
+
* result:
|
968
|
+
*
|
969
|
+
* @code
|
970
|
+
* // Required as a workaround only.
|
971
|
+
* worksheet_write_formula_num(worksheet, 0, 0, "=1 + 2", NULL, 3);
|
972
|
+
* @endcode
|
973
|
+
*
|
974
|
+
* Libxlsxwriter doesn't calculate the value of a formula and instead stores
|
975
|
+
* the value `0` as the formula result. It then sets a global flag in the XLSX
|
976
|
+
* file to say that all formulas and functions should be recalculated when the
|
977
|
+
* file is opened.
|
978
|
+
*
|
979
|
+
* This is the method recommended in the Excel documentation and in general it
|
980
|
+
* works fine with spreadsheet applications.
|
981
|
+
*
|
982
|
+
* However, applications that don't have a facility to calculate formulas,
|
983
|
+
* such as Excel Viewer, or some mobile applications will only display the `0`
|
984
|
+
* results.
|
985
|
+
*
|
986
|
+
* If required, the `%worksheet_write_formula_num()` function can be used to
|
987
|
+
* specify a formula and its result.
|
988
|
+
*
|
989
|
+
* This function is rarely required and is only provided for compatibility
|
990
|
+
* with some third party applications. For most applications the
|
991
|
+
* worksheet_write_formula() function is the recommended way of writing
|
992
|
+
* formulas.
|
993
|
+
*
|
994
|
+
*/
|
995
|
+
lxw_error worksheet_write_formula_num(lxw_worksheet *worksheet,
|
996
|
+
lxw_row_t row,
|
997
|
+
lxw_col_t col,
|
998
|
+
const char *formula,
|
999
|
+
lxw_format *format, double result);
|
1000
|
+
|
1001
|
+
/**
|
1002
|
+
* @brief Set the properties for a row of cells.
|
1003
|
+
*
|
1004
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1005
|
+
* @param row The zero indexed row number.
|
1006
|
+
* @param height The row height.
|
1007
|
+
* @param format A pointer to a Format instance or NULL.
|
1008
|
+
*
|
1009
|
+
* The `%worksheet_set_row()` function is used to change the default
|
1010
|
+
* properties of a row. The most common use for this function is to change the
|
1011
|
+
* height of a row:
|
1012
|
+
*
|
1013
|
+
* @code
|
1014
|
+
* // Set the height of Row 1 to 20.
|
1015
|
+
* worksheet_set_row(worksheet, 0, 20, NULL);
|
1016
|
+
* @endcode
|
1017
|
+
*
|
1018
|
+
* The other common use for `%worksheet_set_row()` is to set the a @ref
|
1019
|
+
* format.h "Format" for all cells in the row:
|
1020
|
+
*
|
1021
|
+
* @code
|
1022
|
+
* lxw_format *bold = workbook_add_format(workbook);
|
1023
|
+
* format_set_bold(bold);
|
1024
|
+
*
|
1025
|
+
* // Set the header row to bold.
|
1026
|
+
* worksheet_set_row(worksheet, 0, 15, bold);
|
1027
|
+
* @endcode
|
1028
|
+
*
|
1029
|
+
* If you wish to set the format of a row without changing the height you can
|
1030
|
+
* pass the default row height of #LXW_DEF_ROW_HEIGHT = 15:
|
1031
|
+
*
|
1032
|
+
* @code
|
1033
|
+
* worksheet_set_row(worksheet, 0, LXW_DEF_ROW_HEIGHT, format);
|
1034
|
+
* worksheet_set_row(worksheet, 0, 15, format); // Same as above.
|
1035
|
+
* @endcode
|
1036
|
+
*
|
1037
|
+
* The `format` parameter will be applied to any cells in the row that don't
|
1038
|
+
* have a format. As with Excel the row format is overridden by an explicit
|
1039
|
+
* cell format. For example:
|
1040
|
+
*
|
1041
|
+
* @code
|
1042
|
+
* // Row 1 has format1.
|
1043
|
+
* worksheet_set_row(worksheet, 0, 15, format1);
|
1044
|
+
*
|
1045
|
+
* // Cell A1 in Row 1 defaults to format1.
|
1046
|
+
* worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
|
1047
|
+
*
|
1048
|
+
* // Cell B1 in Row 1 keeps format2.
|
1049
|
+
* worksheet_write_string(worksheet, 0, 1, "Hello", format2);
|
1050
|
+
* @endcode
|
1051
|
+
*
|
1052
|
+
*/
|
1053
|
+
lxw_error worksheet_set_row(lxw_worksheet *worksheet,
|
1054
|
+
lxw_row_t row, double height, lxw_format *format);
|
1055
|
+
|
1056
|
+
/**
|
1057
|
+
* @brief Set the properties for a row of cells.
|
1058
|
+
*
|
1059
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1060
|
+
* @param row The zero indexed row number.
|
1061
|
+
* @param height The row height.
|
1062
|
+
* @param format A pointer to a Format instance or NULL.
|
1063
|
+
* @param options Optional row parameters: hidden, level, collapsed.
|
1064
|
+
*
|
1065
|
+
* The `%worksheet_set_row_opt()` function is the same as
|
1066
|
+
* `worksheet_set_row()` with an additional `options` parameter.
|
1067
|
+
*
|
1068
|
+
* The `options` parameter is a #lxw_row_col_options struct. It has the
|
1069
|
+
* following members but currently only the `hidden` property is supported:
|
1070
|
+
*
|
1071
|
+
* - `hidden`
|
1072
|
+
* - `level`
|
1073
|
+
* - `collapsed`
|
1074
|
+
*
|
1075
|
+
* The `"hidden"` option is used to hide a row. This can be used, for
|
1076
|
+
* example, to hide intermediary steps in a complicated calculation:
|
1077
|
+
*
|
1078
|
+
* @code
|
1079
|
+
* lxw_row_col_options options = {.hidden = 1, .level = 0, .collapsed = 0};
|
1080
|
+
*
|
1081
|
+
* // Hide the fourth row.
|
1082
|
+
* worksheet_set_row(worksheet, 3, 20, NULL, &options);
|
1083
|
+
* @endcode
|
1084
|
+
*
|
1085
|
+
*/
|
1086
|
+
lxw_error worksheet_set_row_opt(lxw_worksheet *worksheet,
|
1087
|
+
lxw_row_t row,
|
1088
|
+
double height,
|
1089
|
+
lxw_format *format,
|
1090
|
+
lxw_row_col_options *options);
|
1091
|
+
|
1092
|
+
/**
|
1093
|
+
* @brief Set the properties for one or more columns of cells.
|
1094
|
+
*
|
1095
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1096
|
+
* @param first_col The zero indexed first column.
|
1097
|
+
* @param last_col The zero indexed last column.
|
1098
|
+
* @param width The width of the column(s).
|
1099
|
+
* @param format A pointer to a Format instance or NULL.
|
1100
|
+
*
|
1101
|
+
* The `%worksheet_set_column()` function can be used to change the default
|
1102
|
+
* properties of a single column or a range of columns:
|
1103
|
+
*
|
1104
|
+
* @code
|
1105
|
+
* // Width of columns B:D set to 30.
|
1106
|
+
* worksheet_set_column(worksheet, 1, 3, 30, NULL);
|
1107
|
+
*
|
1108
|
+
* @endcode
|
1109
|
+
*
|
1110
|
+
* If `%worksheet_set_column()` is applied to a single column the value of
|
1111
|
+
* `first_col` and `last_col` should be the same:
|
1112
|
+
*
|
1113
|
+
* @code
|
1114
|
+
* // Width of column B set to 30.
|
1115
|
+
* worksheet_set_column(worksheet, 1, 1, 30, NULL);
|
1116
|
+
*
|
1117
|
+
* @endcode
|
1118
|
+
*
|
1119
|
+
* It is also possible, and generally clearer, to specify a column range using
|
1120
|
+
* the form of `COLS()` macro:
|
1121
|
+
*
|
1122
|
+
* @code
|
1123
|
+
* worksheet_set_column(worksheet, 4, 4, 20, NULL);
|
1124
|
+
* worksheet_set_column(worksheet, 5, 8, 30, NULL);
|
1125
|
+
*
|
1126
|
+
* // Same as the examples above but clearer.
|
1127
|
+
* worksheet_set_column(worksheet, COLS("E:E"), 20, NULL);
|
1128
|
+
* worksheet_set_column(worksheet, COLS("F:H"), 30, NULL);
|
1129
|
+
*
|
1130
|
+
* @endcode
|
1131
|
+
*
|
1132
|
+
* The `width` parameter sets the column width in the same units used by Excel
|
1133
|
+
* which is: the number of characters in the default font. The default width
|
1134
|
+
* is 8.43 in the default font of Calibri 11. The actual relationship between
|
1135
|
+
* a string width and a column width in Excel is complex. See the
|
1136
|
+
* [following explanation of column widths](https://support.microsoft.com/en-us/kb/214123)
|
1137
|
+
* from the Microsoft support documentation for more details.
|
1138
|
+
*
|
1139
|
+
* There is no way to specify "AutoFit" for a column in the Excel file
|
1140
|
+
* format. This feature is only available at runtime from within Excel. It is
|
1141
|
+
* possible to simulate "AutoFit" in your application by tracking the maximum
|
1142
|
+
* width of the data in the column as your write it and then adjusting the
|
1143
|
+
* column width at the end.
|
1144
|
+
*
|
1145
|
+
* As usual the @ref format.h `format` parameter is optional. If you wish to
|
1146
|
+
* set the format without changing the width you can pass a default column
|
1147
|
+
* width of #LXW_DEF_COL_WIDTH = 8.43:
|
1148
|
+
*
|
1149
|
+
* @code
|
1150
|
+
* lxw_format *bold = workbook_add_format(workbook);
|
1151
|
+
* format_set_bold(bold);
|
1152
|
+
*
|
1153
|
+
* // Set the first column to bold.
|
1154
|
+
* worksheet_set_column(worksheet, 0, 0, LXW_DEF_COL_HEIGHT, bold);
|
1155
|
+
* @endcode
|
1156
|
+
*
|
1157
|
+
* The `format` parameter will be applied to any cells in the column that
|
1158
|
+
* don't have a format. For example:
|
1159
|
+
*
|
1160
|
+
* @code
|
1161
|
+
* // Column 1 has format1.
|
1162
|
+
* worksheet_set_column(worksheet, COLS("A:A"), 8.43, format1);
|
1163
|
+
*
|
1164
|
+
* // Cell A1 in column 1 defaults to format1.
|
1165
|
+
* worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
|
1166
|
+
*
|
1167
|
+
* // Cell A2 in column 1 keeps format2.
|
1168
|
+
* worksheet_write_string(worksheet, 1, 0, "Hello", format2);
|
1169
|
+
* @endcode
|
1170
|
+
*
|
1171
|
+
* As in Excel a row format takes precedence over a default column format:
|
1172
|
+
*
|
1173
|
+
* @code
|
1174
|
+
* // Row 1 has format1.
|
1175
|
+
* worksheet_set_row(worksheet, 0, 15, format1);
|
1176
|
+
*
|
1177
|
+
* // Col 1 has format2.
|
1178
|
+
* worksheet_set_column(worksheet, COLS("A:A"), 8.43, format2);
|
1179
|
+
*
|
1180
|
+
* // Cell A1 defaults to format1, the row format.
|
1181
|
+
* worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
|
1182
|
+
*
|
1183
|
+
* // Cell A2 keeps format2, the column format.
|
1184
|
+
* worksheet_write_string(worksheet, 1, 0, "Hello", NULL);
|
1185
|
+
* @endcode
|
1186
|
+
*/
|
1187
|
+
lxw_error worksheet_set_column(lxw_worksheet *worksheet,
|
1188
|
+
lxw_col_t first_col,
|
1189
|
+
lxw_col_t last_col,
|
1190
|
+
double width, lxw_format *format);
|
1191
|
+
|
1192
|
+
/**
|
1193
|
+
* @brief Set the properties for one or more columns of cells with options.
|
1194
|
+
*
|
1195
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1196
|
+
* @param first_col The zero indexed first column.
|
1197
|
+
* @param last_col The zero indexed last column.
|
1198
|
+
* @param width The width of the column(s).
|
1199
|
+
* @param format A pointer to a Format instance or NULL.
|
1200
|
+
* @param options Optional row parameters: hidden, level, collapsed.
|
1201
|
+
*
|
1202
|
+
* The `%worksheet_set_column_opt()` function is the same as
|
1203
|
+
* `worksheet_set_column()` with an additional `options` parameter.
|
1204
|
+
*
|
1205
|
+
* The `options` parameter is a #lxw_row_col_options struct. It has the
|
1206
|
+
* following members but currently only the `hidden` property is supported:
|
1207
|
+
*
|
1208
|
+
* - `hidden`
|
1209
|
+
* - `level`
|
1210
|
+
* - `collapsed`
|
1211
|
+
*
|
1212
|
+
* The `"hidden"` option is used to hide a column. This can be used, for
|
1213
|
+
* example, to hide intermediary steps in a complicated calculation:
|
1214
|
+
*
|
1215
|
+
* @code
|
1216
|
+
* lxw_row_col_options options = {.hidden = 1, .level = 0, .collapsed = 0};
|
1217
|
+
*
|
1218
|
+
* worksheet_set_column_opt(worksheet, COLS("A:A"), 8.43, NULL, &options);
|
1219
|
+
* @endcode
|
1220
|
+
*
|
1221
|
+
*/
|
1222
|
+
lxw_error worksheet_set_column_opt(lxw_worksheet *worksheet,
|
1223
|
+
lxw_col_t first_col,
|
1224
|
+
lxw_col_t last_col,
|
1225
|
+
double width,
|
1226
|
+
lxw_format *format,
|
1227
|
+
lxw_row_col_options *options);
|
1228
|
+
|
1229
|
+
/**
|
1230
|
+
* @brief Insert an image in a worksheet cell.
|
1231
|
+
*
|
1232
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1233
|
+
* @param row The zero indexed row number.
|
1234
|
+
* @param col The zero indexed column number.
|
1235
|
+
* @param filename The image filename, with path if required.
|
1236
|
+
*
|
1237
|
+
* @return A #lxw_error code.
|
1238
|
+
*
|
1239
|
+
* This function can be used to insert a image into a worksheet. The image can
|
1240
|
+
* be in PNG, JPEG or BMP format:
|
1241
|
+
*
|
1242
|
+
* @code
|
1243
|
+
* worksheet_insert_image(worksheet, 2, 1, "logo.png");
|
1244
|
+
* @endcode
|
1245
|
+
*
|
1246
|
+
* @image html insert_image.png
|
1247
|
+
*
|
1248
|
+
* The `worksheet_insert_image_opt()` function takes additional optional
|
1249
|
+
* parameters to position and scale the image, see below.
|
1250
|
+
*
|
1251
|
+
* **Note**:
|
1252
|
+
* The scaling of a image may be affected if is crosses a row that has its
|
1253
|
+
* default height changed due to a font that is larger than the default font
|
1254
|
+
* size or that has text wrapping turned on. To avoid this you should
|
1255
|
+
* explicitly set the height of the row using `worksheet_set_row()` if it
|
1256
|
+
* crosses an inserted image.
|
1257
|
+
*
|
1258
|
+
* BMP images are only supported for backward compatibility. In general it is
|
1259
|
+
* best to avoid BMP images since they aren't compressed. If used, BMP images
|
1260
|
+
* must be 24 bit, true color, bitmaps.
|
1261
|
+
*/
|
1262
|
+
lxw_error worksheet_insert_image(lxw_worksheet *worksheet,
|
1263
|
+
lxw_row_t row, lxw_col_t col,
|
1264
|
+
const char *filename);
|
1265
|
+
|
1266
|
+
/**
|
1267
|
+
* @brief Insert an image in a worksheet cell, with options.
|
1268
|
+
*
|
1269
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1270
|
+
* @param row The zero indexed row number.
|
1271
|
+
* @param col The zero indexed column number.
|
1272
|
+
* @param filename The image filename, with path if required.
|
1273
|
+
* @param options Optional image parameters.
|
1274
|
+
*
|
1275
|
+
* @return A #lxw_error code.
|
1276
|
+
*
|
1277
|
+
* The `%worksheet_insert_image_opt()` function is like
|
1278
|
+
* `worksheet_insert_image()` function except that it takes an optional
|
1279
|
+
* #lxw_image_options struct to scale and position the image:
|
1280
|
+
*
|
1281
|
+
* @code
|
1282
|
+
* lxw_image_options options = {.x_offset = 30, .y_offset = 10,
|
1283
|
+
* .x_scale = 0.5, .y_scale = 0.5};
|
1284
|
+
*
|
1285
|
+
* worksheet_insert_image_opt(worksheet, 2, 1, "logo.png", &options);
|
1286
|
+
*
|
1287
|
+
* @endcode
|
1288
|
+
*
|
1289
|
+
* @image html insert_image_opt.png
|
1290
|
+
*
|
1291
|
+
* @note See the notes about row scaling and BMP images in
|
1292
|
+
* `worksheet_insert_image()` above.
|
1293
|
+
*/
|
1294
|
+
lxw_error worksheet_insert_image_opt(lxw_worksheet *worksheet,
|
1295
|
+
lxw_row_t row, lxw_col_t col,
|
1296
|
+
const char *filename,
|
1297
|
+
lxw_image_options *options);
|
1298
|
+
/**
|
1299
|
+
* @brief Insert a chart object into a worksheet.
|
1300
|
+
*
|
1301
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1302
|
+
* @param row The zero indexed row number.
|
1303
|
+
* @param col The zero indexed column number.
|
1304
|
+
* @param chart A #lxw_chart object created via workbook_add_chart().
|
1305
|
+
*
|
1306
|
+
* @return A #lxw_error code.
|
1307
|
+
*
|
1308
|
+
* The `%worksheet_insert_chart()` can be used to insert a chart into a
|
1309
|
+
* worksheet. The chart object must be created first using the
|
1310
|
+
* `workbook_add_chart()` function and configured using the @ref chart.h
|
1311
|
+
* functions.
|
1312
|
+
*
|
1313
|
+
* @code
|
1314
|
+
* // Create a chart object.
|
1315
|
+
* lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
|
1316
|
+
*
|
1317
|
+
* // Add a data series to the chart.
|
1318
|
+
* chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$6");
|
1319
|
+
*
|
1320
|
+
* // Insert the chart into the worksheet
|
1321
|
+
* worksheet_insert_chart(worksheet, 0, 2, chart);
|
1322
|
+
* @endcode
|
1323
|
+
*
|
1324
|
+
* @image html chart_working.png
|
1325
|
+
*
|
1326
|
+
*
|
1327
|
+
* **Note:**
|
1328
|
+
*
|
1329
|
+
* A chart may only be inserted into a worksheet once. If several similar
|
1330
|
+
* charts are required then each one must be created separately with
|
1331
|
+
* `%worksheet_insert_chart()`.
|
1332
|
+
*
|
1333
|
+
*/
|
1334
|
+
lxw_error worksheet_insert_chart(lxw_worksheet *worksheet,
|
1335
|
+
lxw_row_t row, lxw_col_t col,
|
1336
|
+
lxw_chart *chart);
|
1337
|
+
|
1338
|
+
/**
|
1339
|
+
* @brief Insert a chart object into a worksheet, with options.
|
1340
|
+
*
|
1341
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1342
|
+
* @param row The zero indexed row number.
|
1343
|
+
* @param col The zero indexed column number.
|
1344
|
+
* @param chart A #lxw_chart object created via workbook_add_chart().
|
1345
|
+
* @param user_options Optional chart parameters.
|
1346
|
+
*
|
1347
|
+
* @return A #lxw_error code.
|
1348
|
+
*
|
1349
|
+
* The `%worksheet_insert_chart_opt()` function is like
|
1350
|
+
* `worksheet_insert_chart()` function except that it takes an optional
|
1351
|
+
* #lxw_image_options struct to scale and position the image of the chart:
|
1352
|
+
*
|
1353
|
+
* @code
|
1354
|
+
* lxw_image_options options = {.x_offset = 30, .y_offset = 10,
|
1355
|
+
* .x_scale = 0.5, .y_scale = 0.75};
|
1356
|
+
*
|
1357
|
+
* worksheet_insert_chart_opt(worksheet, 0, 2, chart, &options);
|
1358
|
+
*
|
1359
|
+
* @endcode
|
1360
|
+
*
|
1361
|
+
* @image html chart_line_opt.png
|
1362
|
+
*
|
1363
|
+
* The #lxw_image_options struct is the same struct used in
|
1364
|
+
* `worksheet_insert_image_opt()` to position and scale images.
|
1365
|
+
*
|
1366
|
+
*/
|
1367
|
+
lxw_error worksheet_insert_chart_opt(lxw_worksheet *worksheet,
|
1368
|
+
lxw_row_t row, lxw_col_t col,
|
1369
|
+
lxw_chart *chart,
|
1370
|
+
lxw_image_options *user_options);
|
1371
|
+
|
1372
|
+
/**
|
1373
|
+
* @brief Merge a range of cells.
|
1374
|
+
*
|
1375
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1376
|
+
* @param first_row The first row of the range. (All zero indexed.)
|
1377
|
+
* @param first_col The first column of the range.
|
1378
|
+
* @param last_row The last row of the range.
|
1379
|
+
* @param last_col The last col of the range.
|
1380
|
+
* @param string String to write to the merged range.
|
1381
|
+
* @param format A pointer to a Format instance or NULL.
|
1382
|
+
*
|
1383
|
+
* @return A #lxw_error code.
|
1384
|
+
*
|
1385
|
+
* The `%worksheet_merge_range()` function allows cells to be merged together
|
1386
|
+
* so that they act as a single area.
|
1387
|
+
*
|
1388
|
+
* Excel generally merges and centers cells at same time. To get similar
|
1389
|
+
* behavior with libxlsxwriter you need to apply a @ref format.h "Format"
|
1390
|
+
* object with the appropriate alignment:
|
1391
|
+
*
|
1392
|
+
* @code
|
1393
|
+
* lxw_format *merge_format = workbook_add_format(workbook);
|
1394
|
+
* format_set_align(merge_format, LXW_ALIGN_CENTER);
|
1395
|
+
*
|
1396
|
+
* worksheet_merge_range(worksheet, 1, 1, 1, 3, "Merged Range", merge_format);
|
1397
|
+
*
|
1398
|
+
* @endcode
|
1399
|
+
*
|
1400
|
+
* It is possible to apply other formatting to the merged cells as well:
|
1401
|
+
*
|
1402
|
+
* @code
|
1403
|
+
* format_set_align (merge_format, LXW_ALIGN_CENTER);
|
1404
|
+
* format_set_align (merge_format, LXW_ALIGN_VERTICAL_CENTER);
|
1405
|
+
* format_set_border (merge_format, LXW_BORDER_DOUBLE);
|
1406
|
+
* format_set_bold (merge_format);
|
1407
|
+
* format_set_bg_color(merge_format, 0xD7E4BC);
|
1408
|
+
*
|
1409
|
+
* worksheet_merge_range(worksheet, 2, 1, 3, 3, "Merged Range", merge_format);
|
1410
|
+
*
|
1411
|
+
* @endcode
|
1412
|
+
*
|
1413
|
+
* @image html merge.png
|
1414
|
+
*
|
1415
|
+
* The `%worksheet_merge_range()` function writes a `char*` string using
|
1416
|
+
* `worksheet_write_string()`. In order to write other data types, such as a
|
1417
|
+
* number or a formula, you can overwrite the first cell with a call to one of
|
1418
|
+
* the other write functions. The same Format should be used as was used in
|
1419
|
+
* the merged range.
|
1420
|
+
*
|
1421
|
+
* @code
|
1422
|
+
* // First write a range with a blank string.
|
1423
|
+
* worksheet_merge_range (worksheet, 1, 1, 1, 3, "", format);
|
1424
|
+
*
|
1425
|
+
* // Then overwrite the first cell with a number.
|
1426
|
+
* worksheet_write_number(worksheet, 1, 1, 123, format);
|
1427
|
+
* @endcode
|
1428
|
+
*
|
1429
|
+
* @note Merged ranges generally don’t work in libxlsxwriter when the Workbook
|
1430
|
+
* #lxw_workbook_options `constant_memory` mode is enabled.
|
1431
|
+
*/
|
1432
|
+
lxw_error worksheet_merge_range(lxw_worksheet *worksheet, lxw_row_t first_row,
|
1433
|
+
lxw_col_t first_col, lxw_row_t last_row,
|
1434
|
+
lxw_col_t last_col, const char *string,
|
1435
|
+
lxw_format *format);
|
1436
|
+
|
1437
|
+
/**
|
1438
|
+
* @brief Set the autofilter area in the worksheet.
|
1439
|
+
*
|
1440
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1441
|
+
* @param first_row The first row of the range. (All zero indexed.)
|
1442
|
+
* @param first_col The first column of the range.
|
1443
|
+
* @param last_row The last row of the range.
|
1444
|
+
* @param last_col The last col of the range.
|
1445
|
+
*
|
1446
|
+
* @return A #lxw_error code.
|
1447
|
+
*
|
1448
|
+
* The `%worksheet_autofilter()` function allows an autofilter to be added to
|
1449
|
+
* a worksheet.
|
1450
|
+
*
|
1451
|
+
* An autofilter is a way of adding drop down lists to the headers of a 2D
|
1452
|
+
* range of worksheet data. This allows users to filter the data based on
|
1453
|
+
* simple criteria so that some data is shown and some is hidden.
|
1454
|
+
*
|
1455
|
+
* @image html autofilter.png
|
1456
|
+
*
|
1457
|
+
* To add an autofilter to a worksheet:
|
1458
|
+
*
|
1459
|
+
* @code
|
1460
|
+
* worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
1461
|
+
*
|
1462
|
+
* // Same as above using the RANGE() macro.
|
1463
|
+
* worksheet_autofilter(worksheet, RANGE("A1:D51"));
|
1464
|
+
* @endcode
|
1465
|
+
*
|
1466
|
+
* Note: it isn't currently possible to apply filter conditions to the
|
1467
|
+
* autofilter.
|
1468
|
+
*/
|
1469
|
+
lxw_error worksheet_autofilter(lxw_worksheet *worksheet, lxw_row_t first_row,
|
1470
|
+
lxw_col_t first_col, lxw_row_t last_row,
|
1471
|
+
lxw_col_t last_col);
|
1472
|
+
|
1473
|
+
/**
|
1474
|
+
* @brief Make a worksheet the active, i.e., visible worksheet.
|
1475
|
+
*
|
1476
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1477
|
+
*
|
1478
|
+
* The `%worksheet_activate()` function is used to specify which worksheet is
|
1479
|
+
* initially visible in a multi-sheet workbook:
|
1480
|
+
*
|
1481
|
+
* @code
|
1482
|
+
* lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
|
1483
|
+
* lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
|
1484
|
+
* lxw_worksheet *worksheet3 = workbook_add_worksheet(workbook, NULL);
|
1485
|
+
*
|
1486
|
+
* worksheet_activate(worksheet3);
|
1487
|
+
* @endcode
|
1488
|
+
*
|
1489
|
+
* @image html worksheet_activate.png
|
1490
|
+
*
|
1491
|
+
* More than one worksheet can be selected via the `worksheet_select()`
|
1492
|
+
* function, see below, however only one worksheet can be active.
|
1493
|
+
*
|
1494
|
+
* The default active worksheet is the first worksheet.
|
1495
|
+
*
|
1496
|
+
*/
|
1497
|
+
void worksheet_activate(lxw_worksheet *worksheet);
|
1498
|
+
|
1499
|
+
/**
|
1500
|
+
* @brief Set a worksheet tab as selected.
|
1501
|
+
*
|
1502
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1503
|
+
*
|
1504
|
+
* The `%worksheet_select()` function is used to indicate that a worksheet is
|
1505
|
+
* selected in a multi-sheet workbook:
|
1506
|
+
*
|
1507
|
+
* @code
|
1508
|
+
* worksheet_activate(worksheet1);
|
1509
|
+
* worksheet_select(worksheet2);
|
1510
|
+
* worksheet_select(worksheet3);
|
1511
|
+
*
|
1512
|
+
* @endcode
|
1513
|
+
*
|
1514
|
+
* A selected worksheet has its tab highlighted. Selecting worksheets is a
|
1515
|
+
* way of grouping them together so that, for example, several worksheets
|
1516
|
+
* could be printed in one go. A worksheet that has been activated via the
|
1517
|
+
* `worksheet_activate()` function will also appear as selected.
|
1518
|
+
*
|
1519
|
+
*/
|
1520
|
+
void worksheet_select(lxw_worksheet *worksheet);
|
1521
|
+
|
1522
|
+
/**
|
1523
|
+
* @brief Hide the current worksheet.
|
1524
|
+
*
|
1525
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1526
|
+
*
|
1527
|
+
* The `%worksheet_hide()` function is used to hide a worksheet:
|
1528
|
+
*
|
1529
|
+
* @code
|
1530
|
+
* worksheet_hide(worksheet2);
|
1531
|
+
* @endcode
|
1532
|
+
*
|
1533
|
+
* You may wish to hide a worksheet in order to avoid confusing a user with
|
1534
|
+
* intermediate data or calculations.
|
1535
|
+
*
|
1536
|
+
* @image html hide_sheet.png
|
1537
|
+
*
|
1538
|
+
* A hidden worksheet can not be activated or selected so this function is
|
1539
|
+
* mutually exclusive with the `worksheet_activate()` and `worksheet_select()`
|
1540
|
+
* functions. In addition, since the first worksheet will default to being the
|
1541
|
+
* active worksheet, you cannot hide the first worksheet without activating
|
1542
|
+
* another sheet:
|
1543
|
+
*
|
1544
|
+
* @code
|
1545
|
+
* worksheet_activate(worksheet2);
|
1546
|
+
* worksheet_hide(worksheet1);
|
1547
|
+
* @endcode
|
1548
|
+
*/
|
1549
|
+
void worksheet_hide(lxw_worksheet *worksheet);
|
1550
|
+
|
1551
|
+
/**
|
1552
|
+
* @brief Set current worksheet as the first visible sheet tab.
|
1553
|
+
*
|
1554
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1555
|
+
*
|
1556
|
+
* The `worksheet_activate()` function determines which worksheet is initially
|
1557
|
+
* selected. However, if there are a large number of worksheets the selected
|
1558
|
+
* worksheet may not appear on the screen. To avoid this you can select the
|
1559
|
+
* leftmost visible worksheet tab using `%worksheet_set_first_sheet()`:
|
1560
|
+
*
|
1561
|
+
* @code
|
1562
|
+
* worksheet_set_first_sheet(worksheet19); // First visible worksheet tab.
|
1563
|
+
* worksheet_activate(worksheet20); // First visible worksheet.
|
1564
|
+
* @endcode
|
1565
|
+
*
|
1566
|
+
* This function is not required very often. The default value is the first
|
1567
|
+
* worksheet.
|
1568
|
+
*/
|
1569
|
+
void worksheet_set_first_sheet(lxw_worksheet *worksheet);
|
1570
|
+
|
1571
|
+
/**
|
1572
|
+
* @brief Split and freeze a worksheet into panes.
|
1573
|
+
*
|
1574
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1575
|
+
* @param row The cell row (zero indexed).
|
1576
|
+
* @param col The cell column (zero indexed).
|
1577
|
+
*
|
1578
|
+
* The `%worksheet_freeze_panes()` function can be used to divide a worksheet
|
1579
|
+
* into horizontal or vertical regions known as panes and to "freeze" these
|
1580
|
+
* panes so that the splitter bars are not visible.
|
1581
|
+
*
|
1582
|
+
* The parameters `row` and `col` are used to specify the location of the
|
1583
|
+
* split. It should be noted that the split is specified at the top or left of
|
1584
|
+
* a cell and that the function uses zero based indexing. Therefore to freeze
|
1585
|
+
* the first row of a worksheet it is necessary to specify the split at row 2
|
1586
|
+
* (which is 1 as the zero-based index).
|
1587
|
+
*
|
1588
|
+
* You can set one of the `row` and `col` parameters as zero if you do not
|
1589
|
+
* want either a vertical or horizontal split.
|
1590
|
+
*
|
1591
|
+
* Examples:
|
1592
|
+
*
|
1593
|
+
* @code
|
1594
|
+
* worksheet_freeze_panes(worksheet1, 1, 0); // Freeze the first row.
|
1595
|
+
* worksheet_freeze_panes(worksheet2, 0, 1); // Freeze the first column.
|
1596
|
+
* worksheet_freeze_panes(worksheet3, 1, 1); // Freeze first row/column.
|
1597
|
+
*
|
1598
|
+
* @endcode
|
1599
|
+
*
|
1600
|
+
*/
|
1601
|
+
void worksheet_freeze_panes(lxw_worksheet *worksheet,
|
1602
|
+
lxw_row_t row, lxw_col_t col);
|
1603
|
+
/**
|
1604
|
+
* @brief Split a worksheet into panes.
|
1605
|
+
*
|
1606
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1607
|
+
* @param vertical The position for the vertical split.
|
1608
|
+
* @param horizontal The position for the horizontal split.
|
1609
|
+
*
|
1610
|
+
* The `%worksheet_split_panes()` function can be used to divide a worksheet
|
1611
|
+
* into horizontal or vertical regions known as panes. This function is
|
1612
|
+
* different from the `worksheet_freeze_panes()` function in that the splits
|
1613
|
+
* between the panes will be visible to the user and each pane will have its
|
1614
|
+
* own scroll bars.
|
1615
|
+
*
|
1616
|
+
* The parameters `vertical` and `horizontal` are used to specify the vertical
|
1617
|
+
* and horizontal position of the split. The units for `vertical` and
|
1618
|
+
* `horizontal` are the same as those used by Excel to specify row height and
|
1619
|
+
* column width. However, the vertical and horizontal units are different from
|
1620
|
+
* each other. Therefore you must specify the `vertical` and `horizontal`
|
1621
|
+
* parameters in terms of the row heights and column widths that you have set
|
1622
|
+
* or the default values which are 15 for a row and 8.43 for a column.
|
1623
|
+
*
|
1624
|
+
* Examples:
|
1625
|
+
*
|
1626
|
+
* @code
|
1627
|
+
* worksheet_split_panes(worksheet1, 15, 0); // First row.
|
1628
|
+
* worksheet_split_panes(worksheet2, 0, 8.43); // First column.
|
1629
|
+
* worksheet_split_panes(worksheet3, 15, 8.43); // First row and column.
|
1630
|
+
*
|
1631
|
+
* @endcode
|
1632
|
+
*
|
1633
|
+
*/
|
1634
|
+
void worksheet_split_panes(lxw_worksheet *worksheet,
|
1635
|
+
double vertical, double horizontal);
|
1636
|
+
|
1637
|
+
/* worksheet_freeze_panes() with infrequent options. Undocumented for now. */
|
1638
|
+
void worksheet_freeze_panes_opt(lxw_worksheet *worksheet,
|
1639
|
+
lxw_row_t first_row, lxw_col_t first_col,
|
1640
|
+
lxw_row_t top_row, lxw_col_t left_col,
|
1641
|
+
uint8_t type);
|
1642
|
+
|
1643
|
+
/* worksheet_split_panes() with infrequent options. Undocumented for now. */
|
1644
|
+
void worksheet_split_panes_opt(lxw_worksheet *worksheet,
|
1645
|
+
double vertical, double horizontal,
|
1646
|
+
lxw_row_t top_row, lxw_col_t left_col);
|
1647
|
+
/**
|
1648
|
+
* @brief Set the selected cell or cells in a worksheet:
|
1649
|
+
*
|
1650
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1651
|
+
* @param first_row The first row of the range. (All zero indexed.)
|
1652
|
+
* @param first_col The first column of the range.
|
1653
|
+
* @param last_row The last row of the range.
|
1654
|
+
* @param last_col The last col of the range.
|
1655
|
+
*
|
1656
|
+
*
|
1657
|
+
* The `%worksheet_set_selection()` function can be used to specify which cell
|
1658
|
+
* or range of cells is selected in a worksheet: The most common requirement
|
1659
|
+
* is to select a single cell, in which case the `first_` and `last_`
|
1660
|
+
* parameters should be the same.
|
1661
|
+
*
|
1662
|
+
* The active cell within a selected range is determined by the order in which
|
1663
|
+
* `first_` and `last_` are specified.
|
1664
|
+
*
|
1665
|
+
* Examples:
|
1666
|
+
*
|
1667
|
+
* @code
|
1668
|
+
* worksheet_set_selection(worksheet1, 3, 3, 3, 3); // Cell D4.
|
1669
|
+
* worksheet_set_selection(worksheet2, 3, 3, 6, 6); // Cells D4 to G7.
|
1670
|
+
* worksheet_set_selection(worksheet3, 6, 6, 3, 3); // Cells G7 to D4.
|
1671
|
+
* worksheet_set_selection(worksheet5, RANGE("D4:G7")); // Using the RANGE macro.
|
1672
|
+
*
|
1673
|
+
* @endcode
|
1674
|
+
*
|
1675
|
+
*/
|
1676
|
+
void worksheet_set_selection(lxw_worksheet *worksheet,
|
1677
|
+
lxw_row_t first_row, lxw_col_t first_col,
|
1678
|
+
lxw_row_t last_row, lxw_col_t last_col);
|
1679
|
+
|
1680
|
+
/**
|
1681
|
+
* @brief Set the page orientation as landscape.
|
1682
|
+
*
|
1683
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1684
|
+
*
|
1685
|
+
* This function is used to set the orientation of a worksheet's printed page
|
1686
|
+
* to landscape:
|
1687
|
+
*
|
1688
|
+
* @code
|
1689
|
+
* worksheet_set_landscape(worksheet);
|
1690
|
+
* @endcode
|
1691
|
+
*/
|
1692
|
+
void worksheet_set_landscape(lxw_worksheet *worksheet);
|
1693
|
+
|
1694
|
+
/**
|
1695
|
+
* @brief Set the page orientation as portrait.
|
1696
|
+
*
|
1697
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1698
|
+
*
|
1699
|
+
* This function is used to set the orientation of a worksheet's printed page
|
1700
|
+
* to portrait. The default worksheet orientation is portrait, so this
|
1701
|
+
* function isn't generally required:
|
1702
|
+
*
|
1703
|
+
* @code
|
1704
|
+
* worksheet_set_portrait(worksheet);
|
1705
|
+
* @endcode
|
1706
|
+
*/
|
1707
|
+
void worksheet_set_portrait(lxw_worksheet *worksheet);
|
1708
|
+
|
1709
|
+
/**
|
1710
|
+
* @brief Set the page layout to page view mode.
|
1711
|
+
*
|
1712
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1713
|
+
*
|
1714
|
+
* This function is used to display the worksheet in "Page View/Layout" mode:
|
1715
|
+
*
|
1716
|
+
* @code
|
1717
|
+
* worksheet_set_page_view(worksheet);
|
1718
|
+
* @endcode
|
1719
|
+
*/
|
1720
|
+
void worksheet_set_page_view(lxw_worksheet *worksheet);
|
1721
|
+
|
1722
|
+
/**
|
1723
|
+
* @brief Set the paper type for printing.
|
1724
|
+
*
|
1725
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1726
|
+
* @param paper_type The Excel paper format type.
|
1727
|
+
*
|
1728
|
+
* This function is used to set the paper format for the printed output of a
|
1729
|
+
* worksheet. The following paper styles are available:
|
1730
|
+
*
|
1731
|
+
*
|
1732
|
+
* Index | Paper format | Paper size
|
1733
|
+
* :------- | :---------------------- | :-------------------
|
1734
|
+
* 0 | Printer default | Printer default
|
1735
|
+
* 1 | Letter | 8 1/2 x 11 in
|
1736
|
+
* 2 | Letter Small | 8 1/2 x 11 in
|
1737
|
+
* 3 | Tabloid | 11 x 17 in
|
1738
|
+
* 4 | Ledger | 17 x 11 in
|
1739
|
+
* 5 | Legal | 8 1/2 x 14 in
|
1740
|
+
* 6 | Statement | 5 1/2 x 8 1/2 in
|
1741
|
+
* 7 | Executive | 7 1/4 x 10 1/2 in
|
1742
|
+
* 8 | A3 | 297 x 420 mm
|
1743
|
+
* 9 | A4 | 210 x 297 mm
|
1744
|
+
* 10 | A4 Small | 210 x 297 mm
|
1745
|
+
* 11 | A5 | 148 x 210 mm
|
1746
|
+
* 12 | B4 | 250 x 354 mm
|
1747
|
+
* 13 | B5 | 182 x 257 mm
|
1748
|
+
* 14 | Folio | 8 1/2 x 13 in
|
1749
|
+
* 15 | Quarto | 215 x 275 mm
|
1750
|
+
* 16 | --- | 10x14 in
|
1751
|
+
* 17 | --- | 11x17 in
|
1752
|
+
* 18 | Note | 8 1/2 x 11 in
|
1753
|
+
* 19 | Envelope 9 | 3 7/8 x 8 7/8
|
1754
|
+
* 20 | Envelope 10 | 4 1/8 x 9 1/2
|
1755
|
+
* 21 | Envelope 11 | 4 1/2 x 10 3/8
|
1756
|
+
* 22 | Envelope 12 | 4 3/4 x 11
|
1757
|
+
* 23 | Envelope 14 | 5 x 11 1/2
|
1758
|
+
* 24 | C size sheet | ---
|
1759
|
+
* 25 | D size sheet | ---
|
1760
|
+
* 26 | E size sheet | ---
|
1761
|
+
* 27 | Envelope DL | 110 x 220 mm
|
1762
|
+
* 28 | Envelope C3 | 324 x 458 mm
|
1763
|
+
* 29 | Envelope C4 | 229 x 324 mm
|
1764
|
+
* 30 | Envelope C5 | 162 x 229 mm
|
1765
|
+
* 31 | Envelope C6 | 114 x 162 mm
|
1766
|
+
* 32 | Envelope C65 | 114 x 229 mm
|
1767
|
+
* 33 | Envelope B4 | 250 x 353 mm
|
1768
|
+
* 34 | Envelope B5 | 176 x 250 mm
|
1769
|
+
* 35 | Envelope B6 | 176 x 125 mm
|
1770
|
+
* 36 | Envelope | 110 x 230 mm
|
1771
|
+
* 37 | Monarch | 3.875 x 7.5 in
|
1772
|
+
* 38 | Envelope | 3 5/8 x 6 1/2 in
|
1773
|
+
* 39 | Fanfold | 14 7/8 x 11 in
|
1774
|
+
* 40 | German Std Fanfold | 8 1/2 x 12 in
|
1775
|
+
* 41 | German Legal Fanfold | 8 1/2 x 13 in
|
1776
|
+
*
|
1777
|
+
* Note, it is likely that not all of these paper types will be available to
|
1778
|
+
* the end user since it will depend on the paper formats that the user's
|
1779
|
+
* printer supports. Therefore, it is best to stick to standard paper types:
|
1780
|
+
*
|
1781
|
+
* @code
|
1782
|
+
* worksheet_set_paper(worksheet1, 1); // US Letter
|
1783
|
+
* worksheet_set_paper(worksheet2, 9); // A4
|
1784
|
+
* @endcode
|
1785
|
+
*
|
1786
|
+
* If you do not specify a paper type the worksheet will print using the
|
1787
|
+
* printer's default paper style.
|
1788
|
+
*/
|
1789
|
+
void worksheet_set_paper(lxw_worksheet *worksheet, uint8_t paper_type);
|
1790
|
+
|
1791
|
+
/**
|
1792
|
+
* @brief Set the worksheet margins for the printed page.
|
1793
|
+
*
|
1794
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1795
|
+
* @param left Left margin in inches. Excel default is 0.7.
|
1796
|
+
* @param right Right margin in inches. Excel default is 0.7.
|
1797
|
+
* @param top Top margin in inches. Excel default is 0.75.
|
1798
|
+
* @param bottom Bottom margin in inches. Excel default is 0.75.
|
1799
|
+
*
|
1800
|
+
* The `%worksheet_set_margins()` function is used to set the margins of the
|
1801
|
+
* worksheet when it is printed. The units are in inches. Specifying `-1` for
|
1802
|
+
* any parameter will give the default Excel value as shown above.
|
1803
|
+
*
|
1804
|
+
* @code
|
1805
|
+
* worksheet_set_margins(worksheet, 1.3, 1.2, -1, -1);
|
1806
|
+
* @endcode
|
1807
|
+
*
|
1808
|
+
*/
|
1809
|
+
void worksheet_set_margins(lxw_worksheet *worksheet, double left,
|
1810
|
+
double right, double top, double bottom);
|
1811
|
+
|
1812
|
+
/**
|
1813
|
+
* @brief Set the printed page header caption.
|
1814
|
+
*
|
1815
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1816
|
+
* @param string The header string.
|
1817
|
+
*
|
1818
|
+
* @return A #lxw_error code.
|
1819
|
+
*
|
1820
|
+
* Headers and footers are generated using a string which is a combination of
|
1821
|
+
* plain text and control characters.
|
1822
|
+
*
|
1823
|
+
* The available control character are:
|
1824
|
+
*
|
1825
|
+
*
|
1826
|
+
* | Control | Category | Description |
|
1827
|
+
* | --------------- | ------------- | --------------------- |
|
1828
|
+
* | `&L` | Justification | Left |
|
1829
|
+
* | `&C` | | Center |
|
1830
|
+
* | `&R` | | Right |
|
1831
|
+
* | `&P` | Information | Page number |
|
1832
|
+
* | `&N` | | Total number of pages |
|
1833
|
+
* | `&D` | | Date |
|
1834
|
+
* | `&T` | | Time |
|
1835
|
+
* | `&F` | | File name |
|
1836
|
+
* | `&A` | | Worksheet name |
|
1837
|
+
* | `&Z` | | Workbook path |
|
1838
|
+
* | `&fontsize` | Font | Font size |
|
1839
|
+
* | `&"font,style"` | | Font name and style |
|
1840
|
+
* | `&U` | | Single underline |
|
1841
|
+
* | `&E` | | Double underline |
|
1842
|
+
* | `&S` | | Strikethrough |
|
1843
|
+
* | `&X` | | Superscript |
|
1844
|
+
* | `&Y` | | Subscript |
|
1845
|
+
*
|
1846
|
+
*
|
1847
|
+
* Text in headers and footers can be justified (aligned) to the left, center
|
1848
|
+
* and right by prefixing the text with the control characters `&L`, `&C` and
|
1849
|
+
* `&R`.
|
1850
|
+
*
|
1851
|
+
* For example (with ASCII art representation of the results):
|
1852
|
+
*
|
1853
|
+
* @code
|
1854
|
+
* worksheet_set_header(worksheet, "&LHello");
|
1855
|
+
*
|
1856
|
+
* ---------------------------------------------------------------
|
1857
|
+
* | |
|
1858
|
+
* | Hello |
|
1859
|
+
* | |
|
1860
|
+
*
|
1861
|
+
*
|
1862
|
+
* worksheet_set_header(worksheet, "&CHello");
|
1863
|
+
*
|
1864
|
+
* ---------------------------------------------------------------
|
1865
|
+
* | |
|
1866
|
+
* | Hello |
|
1867
|
+
* | |
|
1868
|
+
*
|
1869
|
+
*
|
1870
|
+
* worksheet_set_header(worksheet, "&RHello");
|
1871
|
+
*
|
1872
|
+
* ---------------------------------------------------------------
|
1873
|
+
* | |
|
1874
|
+
* | Hello |
|
1875
|
+
* | |
|
1876
|
+
*
|
1877
|
+
*
|
1878
|
+
* @endcode
|
1879
|
+
*
|
1880
|
+
* For simple text, if you do not specify any justification the text will be
|
1881
|
+
* centered. However, you must prefix the text with `&C` if you specify a font
|
1882
|
+
* name or any other formatting:
|
1883
|
+
*
|
1884
|
+
* @code
|
1885
|
+
* worksheet_set_header(worksheet, "Hello");
|
1886
|
+
*
|
1887
|
+
* ---------------------------------------------------------------
|
1888
|
+
* | |
|
1889
|
+
* | Hello |
|
1890
|
+
* | |
|
1891
|
+
*
|
1892
|
+
* @endcode
|
1893
|
+
*
|
1894
|
+
* You can have text in each of the justification regions:
|
1895
|
+
*
|
1896
|
+
* @code
|
1897
|
+
* worksheet_set_header(worksheet, "&LCiao&CBello&RCielo");
|
1898
|
+
*
|
1899
|
+
* ---------------------------------------------------------------
|
1900
|
+
* | |
|
1901
|
+
* | Ciao Bello Cielo |
|
1902
|
+
* | |
|
1903
|
+
*
|
1904
|
+
* @endcode
|
1905
|
+
*
|
1906
|
+
* The information control characters act as variables that Excel will update
|
1907
|
+
* as the workbook or worksheet changes. Times and dates are in the users
|
1908
|
+
* default format:
|
1909
|
+
*
|
1910
|
+
* @code
|
1911
|
+
* worksheet_set_header(worksheet, "&CPage &P of &N");
|
1912
|
+
*
|
1913
|
+
* ---------------------------------------------------------------
|
1914
|
+
* | |
|
1915
|
+
* | Page 1 of 6 |
|
1916
|
+
* | |
|
1917
|
+
*
|
1918
|
+
* worksheet_set_header(worksheet, "&CUpdated at &T");
|
1919
|
+
*
|
1920
|
+
* ---------------------------------------------------------------
|
1921
|
+
* | |
|
1922
|
+
* | Updated at 12:30 PM |
|
1923
|
+
* | |
|
1924
|
+
*
|
1925
|
+
* @endcode
|
1926
|
+
*
|
1927
|
+
* You can specify the font size of a section of the text by prefixing it with
|
1928
|
+
* the control character `&n` where `n` is the font size:
|
1929
|
+
*
|
1930
|
+
* @code
|
1931
|
+
* worksheet_set_header(worksheet1, "&C&30Hello Big");
|
1932
|
+
* worksheet_set_header(worksheet2, "&C&10Hello Small");
|
1933
|
+
*
|
1934
|
+
* @endcode
|
1935
|
+
*
|
1936
|
+
* You can specify the font of a section of the text by prefixing it with the
|
1937
|
+
* control sequence `&"font,style"` where `fontname` is a font name such as
|
1938
|
+
* Windows font descriptions: "Regular", "Italic", "Bold" or "Bold Italic":
|
1939
|
+
* "Courier New" or "Times New Roman" and `style` is one of the standard
|
1940
|
+
*
|
1941
|
+
* @code
|
1942
|
+
* worksheet_set_header(worksheet1, "&C&\"Courier New,Italic\"Hello");
|
1943
|
+
* worksheet_set_header(worksheet2, "&C&\"Courier New,Bold Italic\"Hello");
|
1944
|
+
* worksheet_set_header(worksheet3, "&C&\"Times New Roman,Regular\"Hello");
|
1945
|
+
*
|
1946
|
+
* @endcode
|
1947
|
+
*
|
1948
|
+
* It is possible to combine all of these features together to create
|
1949
|
+
* sophisticated headers and footers. As an aid to setting up complicated
|
1950
|
+
* headers and footers you can record a page set-up as a macro in Excel and
|
1951
|
+
* look at the format strings that VBA produces. Remember however that VBA
|
1952
|
+
* uses two double quotes `""` to indicate a single double quote. For the last
|
1953
|
+
* example above the equivalent VBA code looks like this:
|
1954
|
+
*
|
1955
|
+
* @code
|
1956
|
+
* .LeftHeader = ""
|
1957
|
+
* .CenterHeader = "&""Times New Roman,Regular""Hello"
|
1958
|
+
* .RightHeader = ""
|
1959
|
+
*
|
1960
|
+
* @endcode
|
1961
|
+
*
|
1962
|
+
* Alternatively you can inspect the header and footer strings in an Excel
|
1963
|
+
* file by unzipping it and grepping the XML sub-files. The following shows
|
1964
|
+
* how to do that using libxml's xmllint to format the XML for clarity:
|
1965
|
+
*
|
1966
|
+
* @code
|
1967
|
+
*
|
1968
|
+
* $ unzip myfile.xlsm -d myfile
|
1969
|
+
* $ xmllint --format `find myfile -name "*.xml" | xargs` | egrep "Header|Footer"
|
1970
|
+
*
|
1971
|
+
* <headerFooter scaleWithDoc="0">
|
1972
|
+
* <oddHeader>&L&P</oddHeader>
|
1973
|
+
* </headerFooter>
|
1974
|
+
*
|
1975
|
+
* @endcode
|
1976
|
+
*
|
1977
|
+
* Note that in this case you need to unescape the Html. In the above example
|
1978
|
+
* the header string would be `&L&P`.
|
1979
|
+
*
|
1980
|
+
* To include a single literal ampersand `&` in a header or footer you should
|
1981
|
+
* use a double ampersand `&&`:
|
1982
|
+
*
|
1983
|
+
* @code
|
1984
|
+
* worksheet_set_header(worksheet, "&CCuriouser && Curiouser - Attorneys at Law");
|
1985
|
+
* @endcode
|
1986
|
+
*
|
1987
|
+
* Note, the header or footer string must be less than 255 characters. Strings
|
1988
|
+
* longer than this will not be written.
|
1989
|
+
*
|
1990
|
+
*/
|
1991
|
+
lxw_error worksheet_set_header(lxw_worksheet *worksheet, const char *string);
|
1992
|
+
|
1993
|
+
/**
|
1994
|
+
* @brief Set the printed page footer caption.
|
1995
|
+
*
|
1996
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
1997
|
+
* @param string The footer string.
|
1998
|
+
*
|
1999
|
+
* @return A #lxw_error code.
|
2000
|
+
*
|
2001
|
+
* The syntax of this function is the same as worksheet_set_header().
|
2002
|
+
*
|
2003
|
+
*/
|
2004
|
+
lxw_error worksheet_set_footer(lxw_worksheet *worksheet, const char *string);
|
2005
|
+
|
2006
|
+
/**
|
2007
|
+
* @brief Set the printed page header caption with additional options.
|
2008
|
+
*
|
2009
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2010
|
+
* @param string The header string.
|
2011
|
+
* @param options Header options.
|
2012
|
+
*
|
2013
|
+
* @return A #lxw_error code.
|
2014
|
+
*
|
2015
|
+
* The syntax of this function is the same as worksheet_set_header() with an
|
2016
|
+
* additional parameter to specify options for the header.
|
2017
|
+
*
|
2018
|
+
* Currently, the only available option is the header margin:
|
2019
|
+
*
|
2020
|
+
* @code
|
2021
|
+
*
|
2022
|
+
* lxw_header_footer_options header_options = { 0.2 };
|
2023
|
+
*
|
2024
|
+
* worksheet_set_header_opt(worksheet, "Some text", &header_options);
|
2025
|
+
*
|
2026
|
+
* @endcode
|
2027
|
+
*
|
2028
|
+
*/
|
2029
|
+
lxw_error worksheet_set_header_opt(lxw_worksheet *worksheet,
|
2030
|
+
const char *string,
|
2031
|
+
lxw_header_footer_options *options);
|
2032
|
+
|
2033
|
+
/**
|
2034
|
+
* @brief Set the printed page footer caption with additional options.
|
2035
|
+
*
|
2036
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2037
|
+
* @param string The footer string.
|
2038
|
+
* @param options Footer options.
|
2039
|
+
*
|
2040
|
+
* @return A #lxw_error code.
|
2041
|
+
*
|
2042
|
+
* The syntax of this function is the same as worksheet_set_header_opt().
|
2043
|
+
*
|
2044
|
+
*/
|
2045
|
+
lxw_error worksheet_set_footer_opt(lxw_worksheet *worksheet,
|
2046
|
+
const char *string,
|
2047
|
+
lxw_header_footer_options *options);
|
2048
|
+
|
2049
|
+
/**
|
2050
|
+
* @brief Set the horizontal page breaks on a worksheet.
|
2051
|
+
*
|
2052
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2053
|
+
* @param breaks Array of page breaks.
|
2054
|
+
*
|
2055
|
+
* @return A #lxw_error code.
|
2056
|
+
*
|
2057
|
+
* The `%worksheet_set_h_pagebreaks()` function adds horizontal page breaks to
|
2058
|
+
* a worksheet. A page break causes all the data that follows it to be printed
|
2059
|
+
* on the next page. Horizontal page breaks act between rows.
|
2060
|
+
*
|
2061
|
+
* The function takes an array of one or more page breaks. The type of the
|
2062
|
+
* array data is @ref lxw_row_t and the last element of the array must be 0:
|
2063
|
+
*
|
2064
|
+
* @code
|
2065
|
+
* lxw_row_t breaks1[] = {20, 0}; // 1 page break. Zero indicates the end.
|
2066
|
+
* lxw_row_t breaks2[] = {20, 40, 60, 80, 0};
|
2067
|
+
*
|
2068
|
+
* worksheet_set_h_pagebreaks(worksheet1, breaks1);
|
2069
|
+
* worksheet_set_h_pagebreaks(worksheet2, breaks2);
|
2070
|
+
* @endcode
|
2071
|
+
*
|
2072
|
+
* To create a page break between rows 20 and 21 you must specify the break at
|
2073
|
+
* row 21. However in zero index notation this is actually row 20:
|
2074
|
+
*
|
2075
|
+
* @code
|
2076
|
+
* // Break between row 20 and 21.
|
2077
|
+
* lxw_row_t breaks[] = {20, 0};
|
2078
|
+
*
|
2079
|
+
* worksheet_set_h_pagebreaks(worksheet, breaks);
|
2080
|
+
* @endcode
|
2081
|
+
*
|
2082
|
+
* There is an Excel limitation of 1023 horizontal page breaks per worksheet.
|
2083
|
+
*
|
2084
|
+
* Note: If you specify the "fit to page" option via the
|
2085
|
+
* `worksheet_fit_to_pages()` function it will override all manual page
|
2086
|
+
* breaks.
|
2087
|
+
*
|
2088
|
+
*/
|
2089
|
+
lxw_error worksheet_set_h_pagebreaks(lxw_worksheet *worksheet,
|
2090
|
+
lxw_row_t breaks[]);
|
2091
|
+
|
2092
|
+
/**
|
2093
|
+
* @brief Set the vertical page breaks on a worksheet.
|
2094
|
+
*
|
2095
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2096
|
+
* @param breaks Array of page breaks.
|
2097
|
+
*
|
2098
|
+
* @return A #lxw_error code.
|
2099
|
+
*
|
2100
|
+
* The `%worksheet_set_v_pagebreaks()` function adds vertical page breaks to a
|
2101
|
+
* worksheet. A page break causes all the data that follows it to be printed
|
2102
|
+
* on the next page. Vertical page breaks act between columns.
|
2103
|
+
*
|
2104
|
+
* The function takes an array of one or more page breaks. The type of the
|
2105
|
+
* array data is @ref lxw_col_t and the last element of the array must be 0:
|
2106
|
+
*
|
2107
|
+
* @code
|
2108
|
+
* lxw_col_t breaks1[] = {20, 0}; // 1 page break. Zero indicates the end.
|
2109
|
+
* lxw_col_t breaks2[] = {20, 40, 60, 80, 0};
|
2110
|
+
*
|
2111
|
+
* worksheet_set_v_pagebreaks(worksheet1, breaks1);
|
2112
|
+
* worksheet_set_v_pagebreaks(worksheet2, breaks2);
|
2113
|
+
* @endcode
|
2114
|
+
*
|
2115
|
+
* To create a page break between columns 20 and 21 you must specify the break
|
2116
|
+
* at column 21. However in zero index notation this is actually column 20:
|
2117
|
+
*
|
2118
|
+
* @code
|
2119
|
+
* // Break between column 20 and 21.
|
2120
|
+
* lxw_col_t breaks[] = {20, 0};
|
2121
|
+
*
|
2122
|
+
* worksheet_set_v_pagebreaks(worksheet, breaks);
|
2123
|
+
* @endcode
|
2124
|
+
*
|
2125
|
+
* There is an Excel limitation of 1023 vertical page breaks per worksheet.
|
2126
|
+
*
|
2127
|
+
* Note: If you specify the "fit to page" option via the
|
2128
|
+
* `worksheet_fit_to_pages()` function it will override all manual page
|
2129
|
+
* breaks.
|
2130
|
+
*
|
2131
|
+
*/
|
2132
|
+
lxw_error worksheet_set_v_pagebreaks(lxw_worksheet *worksheet,
|
2133
|
+
lxw_col_t breaks[]);
|
2134
|
+
|
2135
|
+
/**
|
2136
|
+
* @brief Set the order in which pages are printed.
|
2137
|
+
*
|
2138
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2139
|
+
*
|
2140
|
+
* The `%worksheet_print_across()` function is used to change the default
|
2141
|
+
* print direction. This is referred to by Excel as the sheet "page order":
|
2142
|
+
*
|
2143
|
+
* @code
|
2144
|
+
* worksheet_print_across(worksheet);
|
2145
|
+
* @endcode
|
2146
|
+
*
|
2147
|
+
* The default page order is shown below for a worksheet that extends over 4
|
2148
|
+
* pages. The order is called "down then across":
|
2149
|
+
*
|
2150
|
+
* [1] [3]
|
2151
|
+
* [2] [4]
|
2152
|
+
*
|
2153
|
+
* However, by using the `print_across` function the print order will be
|
2154
|
+
* changed to "across then down":
|
2155
|
+
*
|
2156
|
+
* [1] [2]
|
2157
|
+
* [3] [4]
|
2158
|
+
*
|
2159
|
+
*/
|
2160
|
+
void worksheet_print_across(lxw_worksheet *worksheet);
|
2161
|
+
|
2162
|
+
/**
|
2163
|
+
* @brief Set the worksheet zoom factor.
|
2164
|
+
*
|
2165
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2166
|
+
* @param scale Worksheet zoom factor.
|
2167
|
+
*
|
2168
|
+
* Set the worksheet zoom factor in the range `10 <= zoom <= 400`:
|
2169
|
+
*
|
2170
|
+
* @code
|
2171
|
+
* worksheet_set_zoom(worksheet1, 50);
|
2172
|
+
* worksheet_set_zoom(worksheet2, 75);
|
2173
|
+
* worksheet_set_zoom(worksheet3, 300);
|
2174
|
+
* worksheet_set_zoom(worksheet4, 400);
|
2175
|
+
* @endcode
|
2176
|
+
*
|
2177
|
+
* The default zoom factor is 100. It isn't possible to set the zoom to
|
2178
|
+
* "Selection" because it is calculated by Excel at run-time.
|
2179
|
+
*
|
2180
|
+
* Note, `%worksheet_zoom()` does not affect the scale of the printed
|
2181
|
+
* page. For that you should use `worksheet_set_print_scale()`.
|
2182
|
+
*/
|
2183
|
+
void worksheet_set_zoom(lxw_worksheet *worksheet, uint16_t scale);
|
2184
|
+
|
2185
|
+
/**
|
2186
|
+
* @brief Set the option to display or hide gridlines on the screen and
|
2187
|
+
* the printed page.
|
2188
|
+
*
|
2189
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2190
|
+
* @param option Gridline option.
|
2191
|
+
*
|
2192
|
+
* Display or hide screen and print gridlines using one of the values of
|
2193
|
+
* @ref lxw_gridlines.
|
2194
|
+
*
|
2195
|
+
* @code
|
2196
|
+
* worksheet_gridlines(worksheet1, LXW_HIDE_ALL_GRIDLINES);
|
2197
|
+
*
|
2198
|
+
* worksheet_gridlines(worksheet2, LXW_SHOW_PRINT_GRIDLINES);
|
2199
|
+
* @endcode
|
2200
|
+
*
|
2201
|
+
* The Excel default is that the screen gridlines are on and the printed
|
2202
|
+
* worksheet is off.
|
2203
|
+
*
|
2204
|
+
*/
|
2205
|
+
void worksheet_gridlines(lxw_worksheet *worksheet, uint8_t option);
|
2206
|
+
|
2207
|
+
/**
|
2208
|
+
* @brief Center the printed page horizontally.
|
2209
|
+
*
|
2210
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2211
|
+
*
|
2212
|
+
* Center the worksheet data horizontally between the margins on the printed
|
2213
|
+
* page:
|
2214
|
+
*
|
2215
|
+
* @code
|
2216
|
+
* worksheet_center_horizontally(worksheet);
|
2217
|
+
* @endcode
|
2218
|
+
*
|
2219
|
+
*/
|
2220
|
+
void worksheet_center_horizontally(lxw_worksheet *worksheet);
|
2221
|
+
|
2222
|
+
/**
|
2223
|
+
* @brief Center the printed page vertically.
|
2224
|
+
*
|
2225
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2226
|
+
*
|
2227
|
+
* Center the worksheet data vertically between the margins on the printed
|
2228
|
+
* page:
|
2229
|
+
*
|
2230
|
+
* @code
|
2231
|
+
* worksheet_center_vertically(worksheet);
|
2232
|
+
* @endcode
|
2233
|
+
*
|
2234
|
+
*/
|
2235
|
+
void worksheet_center_vertically(lxw_worksheet *worksheet);
|
2236
|
+
|
2237
|
+
/**
|
2238
|
+
* @brief Set the option to print the row and column headers on the printed
|
2239
|
+
* page.
|
2240
|
+
*
|
2241
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2242
|
+
*
|
2243
|
+
* When printing a worksheet from Excel the row and column headers (the row
|
2244
|
+
* numbers on the left and the column letters at the top) aren't printed by
|
2245
|
+
* default.
|
2246
|
+
*
|
2247
|
+
* This function sets the printer option to print these headers:
|
2248
|
+
*
|
2249
|
+
* @code
|
2250
|
+
* worksheet_print_row_col_headers(worksheet);
|
2251
|
+
* @endcode
|
2252
|
+
*
|
2253
|
+
*/
|
2254
|
+
void worksheet_print_row_col_headers(lxw_worksheet *worksheet);
|
2255
|
+
|
2256
|
+
/**
|
2257
|
+
* @brief Set the number of rows to repeat at the top of each printed page.
|
2258
|
+
*
|
2259
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2260
|
+
* @param first_row First row of repeat range.
|
2261
|
+
* @param last_row Last row of repeat range.
|
2262
|
+
*
|
2263
|
+
* @return A #lxw_error code.
|
2264
|
+
*
|
2265
|
+
* For large Excel documents it is often desirable to have the first row or
|
2266
|
+
* rows of the worksheet print out at the top of each page.
|
2267
|
+
*
|
2268
|
+
* This can be achieved by using this function. The parameters `first_row`
|
2269
|
+
* and `last_row` are zero based:
|
2270
|
+
*
|
2271
|
+
* @code
|
2272
|
+
* worksheet_repeat_rows(worksheet, 0, 0); // Repeat the first row.
|
2273
|
+
* worksheet_repeat_rows(worksheet, 0, 1); // Repeat the first two rows.
|
2274
|
+
* @endcode
|
2275
|
+
*/
|
2276
|
+
lxw_error worksheet_repeat_rows(lxw_worksheet *worksheet, lxw_row_t first_row,
|
2277
|
+
lxw_row_t last_row);
|
2278
|
+
|
2279
|
+
/**
|
2280
|
+
* @brief Set the number of columns to repeat at the top of each printed page.
|
2281
|
+
*
|
2282
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2283
|
+
* @param first_col First column of repeat range.
|
2284
|
+
* @param last_col Last column of repeat range.
|
2285
|
+
*
|
2286
|
+
* @return A #lxw_error code.
|
2287
|
+
*
|
2288
|
+
* For large Excel documents it is often desirable to have the first column or
|
2289
|
+
* columns of the worksheet print out at the left of each page.
|
2290
|
+
*
|
2291
|
+
* This can be achieved by using this function. The parameters `first_col`
|
2292
|
+
* and `last_col` are zero based:
|
2293
|
+
*
|
2294
|
+
* @code
|
2295
|
+
* worksheet_repeat_columns(worksheet, 0, 0); // Repeat the first col.
|
2296
|
+
* worksheet_repeat_columns(worksheet, 0, 1); // Repeat the first two cols.
|
2297
|
+
* @endcode
|
2298
|
+
*/
|
2299
|
+
lxw_error worksheet_repeat_columns(lxw_worksheet *worksheet,
|
2300
|
+
lxw_col_t first_col, lxw_col_t last_col);
|
2301
|
+
|
2302
|
+
/**
|
2303
|
+
* @brief Set the print area for a worksheet.
|
2304
|
+
*
|
2305
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2306
|
+
* @param first_row The first row of the range. (All zero indexed.)
|
2307
|
+
* @param first_col The first column of the range.
|
2308
|
+
* @param last_row The last row of the range.
|
2309
|
+
* @param last_col The last col of the range.
|
2310
|
+
*
|
2311
|
+
* @return A #lxw_error code.
|
2312
|
+
*
|
2313
|
+
* This function is used to specify the area of the worksheet that will be
|
2314
|
+
* printed. The RANGE() macro is often convenient for this.
|
2315
|
+
*
|
2316
|
+
* @code
|
2317
|
+
* worksheet_print_area(worksheet, 0, 0, 41, 10); // A1:K42.
|
2318
|
+
*
|
2319
|
+
* // Same as:
|
2320
|
+
* worksheet_print_area(worksheet, RANGE("A1:K42"));
|
2321
|
+
* @endcode
|
2322
|
+
*
|
2323
|
+
* In order to set a row or column range you must specify the entire range:
|
2324
|
+
*
|
2325
|
+
* @code
|
2326
|
+
* worksheet_print_area(worksheet, RANGE("A1:H1048576")); // Same as A:H.
|
2327
|
+
* @endcode
|
2328
|
+
*/
|
2329
|
+
lxw_error worksheet_print_area(lxw_worksheet *worksheet, lxw_row_t first_row,
|
2330
|
+
lxw_col_t first_col, lxw_row_t last_row,
|
2331
|
+
lxw_col_t last_col);
|
2332
|
+
/**
|
2333
|
+
* @brief Fit the printed area to a specific number of pages both vertically
|
2334
|
+
* and horizontally.
|
2335
|
+
*
|
2336
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2337
|
+
* @param width Number of pages horizontally.
|
2338
|
+
* @param height Number of pages vertically.
|
2339
|
+
*
|
2340
|
+
* The `%worksheet_fit_to_pages()` function is used to fit the printed area to
|
2341
|
+
* a specific number of pages both vertically and horizontally. If the printed
|
2342
|
+
* area exceeds the specified number of pages it will be scaled down to
|
2343
|
+
* fit. This ensures that the printed area will always appear on the specified
|
2344
|
+
* number of pages even if the page size or margins change:
|
2345
|
+
*
|
2346
|
+
* @code
|
2347
|
+
* worksheet_fit_to_pages(worksheet1, 1, 1); // Fit to 1x1 pages.
|
2348
|
+
* worksheet_fit_to_pages(worksheet2, 2, 1); // Fit to 2x1 pages.
|
2349
|
+
* worksheet_fit_to_pages(worksheet3, 1, 2); // Fit to 1x2 pages.
|
2350
|
+
* @endcode
|
2351
|
+
*
|
2352
|
+
* The print area can be defined using the `worksheet_print_area()` function
|
2353
|
+
* as described above.
|
2354
|
+
*
|
2355
|
+
* A common requirement is to fit the printed output to `n` pages wide but
|
2356
|
+
* have the height be as long as necessary. To achieve this set the `height`
|
2357
|
+
* to zero:
|
2358
|
+
*
|
2359
|
+
* @code
|
2360
|
+
* // 1 page wide and as long as necessary.
|
2361
|
+
* worksheet_fit_to_pages(worksheet, 1, 0);
|
2362
|
+
* @endcode
|
2363
|
+
*
|
2364
|
+
* **Note**:
|
2365
|
+
*
|
2366
|
+
* - Although it is valid to use both `%worksheet_fit_to_pages()` and
|
2367
|
+
* `worksheet_set_print_scale()` on the same worksheet Excel only allows one
|
2368
|
+
* of these options to be active at a time. The last function call made will
|
2369
|
+
* set the active option.
|
2370
|
+
*
|
2371
|
+
* - The `%worksheet_fit_to_pages()` function will override any manual page
|
2372
|
+
* breaks that are defined in the worksheet.
|
2373
|
+
*
|
2374
|
+
* - When using `%worksheet_fit_to_pages()` it may also be required to set the
|
2375
|
+
* printer paper size using `worksheet_set_paper()` or else Excel will
|
2376
|
+
* default to "US Letter".
|
2377
|
+
*
|
2378
|
+
*/
|
2379
|
+
void worksheet_fit_to_pages(lxw_worksheet *worksheet, uint16_t width,
|
2380
|
+
uint16_t height);
|
2381
|
+
|
2382
|
+
/**
|
2383
|
+
* @brief Set the start page number when printing.
|
2384
|
+
*
|
2385
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2386
|
+
* @param start_page Starting page number.
|
2387
|
+
*
|
2388
|
+
* The `%worksheet_set_start_page()` function is used to set the number of
|
2389
|
+
* the starting page when the worksheet is printed out:
|
2390
|
+
*
|
2391
|
+
* @code
|
2392
|
+
* // Start print from page 2.
|
2393
|
+
* worksheet_set_start_page(worksheet, 2);
|
2394
|
+
* @endcode
|
2395
|
+
*/
|
2396
|
+
void worksheet_set_start_page(lxw_worksheet *worksheet, uint16_t start_page);
|
2397
|
+
|
2398
|
+
/**
|
2399
|
+
* @brief Set the scale factor for the printed page.
|
2400
|
+
*
|
2401
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2402
|
+
* @param scale Print scale of worksheet to be printed.
|
2403
|
+
*
|
2404
|
+
* This function sets the scale factor of the printed page. The Scale factor
|
2405
|
+
* must be in the range `10 <= scale <= 400`:
|
2406
|
+
*
|
2407
|
+
* @code
|
2408
|
+
* worksheet_set_print_scale(worksheet1, 75);
|
2409
|
+
* worksheet_set_print_scale(worksheet2, 400);
|
2410
|
+
* @endcode
|
2411
|
+
*
|
2412
|
+
* The default scale factor is 100. Note, `%worksheet_set_print_scale()` does
|
2413
|
+
* not affect the scale of the visible page in Excel. For that you should use
|
2414
|
+
* `worksheet_set_zoom()`.
|
2415
|
+
*
|
2416
|
+
* Note that although it is valid to use both `worksheet_fit_to_pages()` and
|
2417
|
+
* `%worksheet_set_print_scale()` on the same worksheet Excel only allows one
|
2418
|
+
* of these options to be active at a time. The last function call made will
|
2419
|
+
* set the active option.
|
2420
|
+
*
|
2421
|
+
*/
|
2422
|
+
void worksheet_set_print_scale(lxw_worksheet *worksheet, uint16_t scale);
|
2423
|
+
|
2424
|
+
/**
|
2425
|
+
* @brief Display the worksheet cells from right to left for some versions of
|
2426
|
+
* Excel.
|
2427
|
+
*
|
2428
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2429
|
+
*
|
2430
|
+
* The `%worksheet_right_to_left()` function is used to change the default
|
2431
|
+
* direction of the worksheet from left-to-right, with the `A1` cell in the
|
2432
|
+
* top left, to right-to-left, with the `A1` cell in the top right.
|
2433
|
+
*
|
2434
|
+
* @code
|
2435
|
+
* worksheet_right_to_left(worksheet1);
|
2436
|
+
* @endcode
|
2437
|
+
*
|
2438
|
+
* This is useful when creating Arabic, Hebrew or other near or far eastern
|
2439
|
+
* worksheets that use right-to-left as the default direction.
|
2440
|
+
*/
|
2441
|
+
void worksheet_right_to_left(lxw_worksheet *worksheet);
|
2442
|
+
|
2443
|
+
/**
|
2444
|
+
* @brief Hide zero values in worksheet cells.
|
2445
|
+
*
|
2446
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2447
|
+
*
|
2448
|
+
* The `%worksheet_hide_zero()` function is used to hide any zero values that
|
2449
|
+
* appear in cells:
|
2450
|
+
*
|
2451
|
+
* @code
|
2452
|
+
* worksheet_hide_zero(worksheet1);
|
2453
|
+
* @endcode
|
2454
|
+
*/
|
2455
|
+
void worksheet_hide_zero(lxw_worksheet *worksheet);
|
2456
|
+
|
2457
|
+
/**
|
2458
|
+
* @brief Set the color of the worksheet tab.
|
2459
|
+
*
|
2460
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2461
|
+
* @param color The tab color.
|
2462
|
+
*
|
2463
|
+
* The `%worksheet_set_tab_color()` function is used to change the color of the worksheet
|
2464
|
+
* tab:
|
2465
|
+
*
|
2466
|
+
* @code
|
2467
|
+
* worksheet_set_tab_color(worksheet1, LXW_COLOR_RED);
|
2468
|
+
* worksheet_set_tab_color(worksheet2, LXW_COLOR_GREEN);
|
2469
|
+
* worksheet_set_tab_color(worksheet3, 0xFF9900); // Orange.
|
2470
|
+
* @endcode
|
2471
|
+
*
|
2472
|
+
* The color should be an RGB integer value, see @ref working_with_colors.
|
2473
|
+
*/
|
2474
|
+
void worksheet_set_tab_color(lxw_worksheet *worksheet, lxw_color_t color);
|
2475
|
+
|
2476
|
+
/**
|
2477
|
+
* @brief Protect elements of a worksheet from modification.
|
2478
|
+
*
|
2479
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2480
|
+
* @param password A worksheet password.
|
2481
|
+
* @param options Worksheet elements to protect.
|
2482
|
+
*
|
2483
|
+
* The `%worksheet_protect()` function protects worksheet elements from modification:
|
2484
|
+
*
|
2485
|
+
* @code
|
2486
|
+
* worksheet_protect(worksheet, "Some Password", options);
|
2487
|
+
* @endcode
|
2488
|
+
*
|
2489
|
+
* The `password` and lxw_protection pointer are both optional:
|
2490
|
+
*
|
2491
|
+
* @code
|
2492
|
+
* worksheet_protect(worksheet1, NULL, NULL);
|
2493
|
+
* worksheet_protect(worksheet2, NULL, my_options);
|
2494
|
+
* worksheet_protect(worksheet3, "password", NULL);
|
2495
|
+
* worksheet_protect(worksheet4, "password", my_options);
|
2496
|
+
* @endcode
|
2497
|
+
*
|
2498
|
+
* Passing a `NULL` password is the same as turning on protection without a
|
2499
|
+
* password. Passing a `NULL` password and `NULL` options, or any other
|
2500
|
+
* combination has the effect of enabling a cell's `locked` and `hidden`
|
2501
|
+
* properties if they have been set.
|
2502
|
+
*
|
2503
|
+
* A *locked* cell cannot be edited and this property is on by default for all
|
2504
|
+
* cells. A *hidden* cell will display the results of a formula but not the
|
2505
|
+
* formula itself. These properties can be set using the format_set_unlocked()
|
2506
|
+
* and format_set_hidden() format functions.
|
2507
|
+
*
|
2508
|
+
* You can specify which worksheet elements you wish to protect by passing a
|
2509
|
+
* lxw_protection pointer in the `options` argument with any or all of the
|
2510
|
+
* following members set:
|
2511
|
+
*
|
2512
|
+
* no_select_locked_cells
|
2513
|
+
* no_select_unlocked_cells
|
2514
|
+
* format_cells
|
2515
|
+
* format_columns
|
2516
|
+
* format_rows
|
2517
|
+
* insert_columns
|
2518
|
+
* insert_rows
|
2519
|
+
* insert_hyperlinks
|
2520
|
+
* delete_columns
|
2521
|
+
* delete_rows
|
2522
|
+
* sort
|
2523
|
+
* autofilter
|
2524
|
+
* pivot_tables
|
2525
|
+
* scenarios
|
2526
|
+
* objects
|
2527
|
+
*
|
2528
|
+
* All parameters are off by default. Individual elements can be protected as
|
2529
|
+
* follows:
|
2530
|
+
*
|
2531
|
+
* @code
|
2532
|
+
* lxw_protection options = {
|
2533
|
+
* .format_cells = 1,
|
2534
|
+
* .insert_hyperlinks = 1,
|
2535
|
+
* .insert_rows = 1,
|
2536
|
+
* .delete_rows = 1,
|
2537
|
+
* .insert_columns = 1,
|
2538
|
+
* .delete_columns = 1,
|
2539
|
+
* };
|
2540
|
+
*
|
2541
|
+
* worksheet_protect(worksheet, NULL, &options);
|
2542
|
+
*
|
2543
|
+
* @endcode
|
2544
|
+
*
|
2545
|
+
* See also the format_set_unlocked() and format_set_hidden() format functions.
|
2546
|
+
*
|
2547
|
+
* **Note:** Worksheet level passwords in Excel offer **very** weak
|
2548
|
+
* protection. They don't encrypt your data and are very easy to
|
2549
|
+
* deactivate. Full workbook encryption is not supported by `libxlsxwriter`
|
2550
|
+
* since it requires a completely different file format and would take several
|
2551
|
+
* man months to implement.
|
2552
|
+
*/
|
2553
|
+
void worksheet_protect(lxw_worksheet *worksheet, const char *password,
|
2554
|
+
lxw_protection *options);
|
2555
|
+
|
2556
|
+
/**
|
2557
|
+
* @brief Set the default row properties.
|
2558
|
+
*
|
2559
|
+
* @param worksheet Pointer to a lxw_worksheet instance to be updated.
|
2560
|
+
* @param height Default row height.
|
2561
|
+
* @param hide_unused_rows Hide unused cells.
|
2562
|
+
*
|
2563
|
+
* The `%worksheet_set_default_row()` function is used to set Excel default
|
2564
|
+
* row properties such as the default height and the option to hide unused
|
2565
|
+
* rows. These parameters are an optimization used by Excel to set row
|
2566
|
+
* properties without generating a very large file with an entry for each row.
|
2567
|
+
*
|
2568
|
+
* To set the default row height:
|
2569
|
+
*
|
2570
|
+
* @code
|
2571
|
+
* worksheet_set_default_row(worksheet, 24, LXW_FALSE);
|
2572
|
+
*
|
2573
|
+
* @endcode
|
2574
|
+
*
|
2575
|
+
* To hide unused rows:
|
2576
|
+
*
|
2577
|
+
* @code
|
2578
|
+
* worksheet_set_default_row(worksheet, 15, LXW_TRUE);
|
2579
|
+
* @endcode
|
2580
|
+
*
|
2581
|
+
* Note, in the previous case we use the default height #LXW_DEF_ROW_HEIGHT =
|
2582
|
+
* 15 so the the height remains unchanged.
|
2583
|
+
*/
|
2584
|
+
void worksheet_set_default_row(lxw_worksheet *worksheet, double height,
|
2585
|
+
uint8_t hide_unused_rows);
|
2586
|
+
|
2587
|
+
lxw_worksheet *lxw_worksheet_new(lxw_worksheet_init_data *init_data);
|
2588
|
+
void lxw_worksheet_free(lxw_worksheet *worksheet);
|
2589
|
+
void lxw_worksheet_assemble_xml_file(lxw_worksheet *worksheet);
|
2590
|
+
void lxw_worksheet_write_single_row(lxw_worksheet *worksheet);
|
2591
|
+
|
2592
|
+
void lxw_worksheet_prepare_image(lxw_worksheet *worksheet,
|
2593
|
+
uint16_t image_ref_id, uint16_t drawing_id,
|
2594
|
+
lxw_image_options *image_data);
|
2595
|
+
|
2596
|
+
void lxw_worksheet_prepare_chart(lxw_worksheet *worksheet,
|
2597
|
+
uint16_t chart_ref_id, uint16_t drawing_id,
|
2598
|
+
lxw_image_options *image_data);
|
2599
|
+
|
2600
|
+
lxw_row *lxw_worksheet_find_row(lxw_worksheet *worksheet, lxw_row_t row_num);
|
2601
|
+
lxw_cell *lxw_worksheet_find_cell(lxw_row *row, lxw_col_t col_num);
|
2602
|
+
|
2603
|
+
/* Declarations required for unit testing. */
|
2604
|
+
#ifdef TESTING
|
2605
|
+
|
2606
|
+
STATIC void _worksheet_xml_declaration(lxw_worksheet *worksheet);
|
2607
|
+
STATIC void _worksheet_write_worksheet(lxw_worksheet *worksheet);
|
2608
|
+
STATIC void _worksheet_write_dimension(lxw_worksheet *worksheet);
|
2609
|
+
STATIC void _worksheet_write_sheet_view(lxw_worksheet *worksheet);
|
2610
|
+
STATIC void _worksheet_write_sheet_views(lxw_worksheet *worksheet);
|
2611
|
+
STATIC void _worksheet_write_sheet_format_pr(lxw_worksheet *worksheet);
|
2612
|
+
STATIC void _worksheet_write_sheet_data(lxw_worksheet *worksheet);
|
2613
|
+
STATIC void _worksheet_write_page_margins(lxw_worksheet *worksheet);
|
2614
|
+
STATIC void _worksheet_write_page_setup(lxw_worksheet *worksheet);
|
2615
|
+
STATIC void _worksheet_write_col_info(lxw_worksheet *worksheet,
|
2616
|
+
lxw_col_options *options);
|
2617
|
+
STATIC void _write_row(lxw_worksheet *worksheet, lxw_row *row, char *spans);
|
2618
|
+
STATIC lxw_row *_get_row_list(struct lxw_table_rows *table,
|
2619
|
+
lxw_row_t row_num);
|
2620
|
+
|
2621
|
+
STATIC void _worksheet_write_merge_cell(lxw_worksheet *worksheet,
|
2622
|
+
lxw_merged_range *merged_range);
|
2623
|
+
STATIC void _worksheet_write_merge_cells(lxw_worksheet *worksheet);
|
2624
|
+
|
2625
|
+
STATIC void _worksheet_write_odd_header(lxw_worksheet *worksheet);
|
2626
|
+
STATIC void _worksheet_write_odd_footer(lxw_worksheet *worksheet);
|
2627
|
+
STATIC void _worksheet_write_header_footer(lxw_worksheet *worksheet);
|
2628
|
+
|
2629
|
+
STATIC void _worksheet_write_print_options(lxw_worksheet *worksheet);
|
2630
|
+
STATIC void _worksheet_write_sheet_pr(lxw_worksheet *worksheet);
|
2631
|
+
STATIC void _worksheet_write_tab_color(lxw_worksheet *worksheet);
|
2632
|
+
STATIC void _worksheet_write_sheet_protection(lxw_worksheet *worksheet);
|
2633
|
+
#endif /* TESTING */
|
2634
|
+
|
2635
|
+
/* *INDENT-OFF* */
|
2636
|
+
#ifdef __cplusplus
|
2637
|
+
}
|
2638
|
+
#endif
|
2639
|
+
/* *INDENT-ON* */
|
2640
|
+
|
2641
|
+
#endif /* __LXW_WORKSHEET_H__ */
|