-
-
Notifications
You must be signed in to change notification settings - Fork 321
/
worksheet.h
3307 lines (3087 loc) · 114 KB
/
worksheet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* libxlsxwriter
*
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
*/
/**
* @page worksheet_page The Worksheet object
*
* The Worksheet object represents an Excel worksheet. It handles
* operations such as writing data to cells or formatting worksheet
* layout.
*
* See @ref worksheet.h for full details of the functionality.
*
* @file worksheet.h
*
* @brief Functions related to adding data and formatting to a worksheet.
*
* The Worksheet object represents an Excel worksheet. It handles
* operations such as writing data to cells or formatting worksheet
* layout.
*
* A Worksheet object isn't created directly. Instead a worksheet is
* created by calling the workbook_add_worksheet() function from a
* Workbook object:
*
* @code
* #include "xlsxwriter.h"
*
* int main() {
*
* lxw_workbook *workbook = workbook_new("filename.xlsx");
* lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
*
* worksheet_write_string(worksheet, 0, 0, "Hello Excel", NULL);
*
* return workbook_close(workbook);
* }
* @endcode
*
*/
#ifndef __LXW_WORKSHEET_H__
#define __LXW_WORKSHEET_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "shared_strings.h"
#include "chart.h"
#include "drawing.h"
#include "common.h"
#include "format.h"
#include "styles.h"
#include "utility.h"
#define LXW_ROW_MAX 1048576
#define LXW_COL_MAX 16384
#define LXW_COL_META_MAX 128
#define LXW_HEADER_FOOTER_MAX 255
#define LXW_MAX_NUMBER_URLS 65530
#define LXW_PANE_NAME_LENGTH 12 /* bottomRight + 1 */
/* The Excel 2007 specification says that the maximum number of page
* breaks is 1026. However, in practice it is actually 1023. */
#define LXW_BREAKS_MAX 1023
/** Default column width in Excel */
#define LXW_DEF_COL_WIDTH (double)8.43
/** Default row height in Excel */
#define LXW_DEF_ROW_HEIGHT (double)15.0
/** Gridline options using in `worksheet_gridlines()`. */
enum lxw_gridlines {
/** Hide screen and print gridlines. */
LXW_HIDE_ALL_GRIDLINES = 0,
/** Show screen gridlines. */
LXW_SHOW_SCREEN_GRIDLINES,
/** Show print gridlines. */
LXW_SHOW_PRINT_GRIDLINES,
/** Show screen and print gridlines. */
LXW_SHOW_ALL_GRIDLINES
};
/** Data validation property values. */
enum lxw_validation_boolean {
LXW_VALIDATION_DEFAULT,
/** Turn a data validation property off. */
LXW_VALIDATION_OFF,
/** Turn a data validation property on. Data validation properties are
* generally on by default. */
LXW_VALIDATION_ON
};
/** Data validation types. */
enum lxw_validation_types {
LXW_VALIDATION_TYPE_NONE,
/** Restrict cell input to whole/integer numbers only. */
LXW_VALIDATION_TYPE_INTEGER,
/** Restrict cell input to whole/integer numbers only, using a cell
* reference. */
LXW_VALIDATION_TYPE_INTEGER_FORMULA,
/** Restrict cell input to decimal numbers only. */
LXW_VALIDATION_TYPE_DECIMAL,
/** Restrict cell input to decimal numbers only, using a cell
* reference. */
LXW_VALIDATION_TYPE_DECIMAL_FORMULA,
/** Restrict cell input to a list of strings in a dropdown. */
LXW_VALIDATION_TYPE_LIST,
/** Restrict cell input to a list of strings in a dropdown, using a
* cell range. */
LXW_VALIDATION_TYPE_LIST_FORMULA,
/** Restrict cell input to date values only, using a lxw_datetime type. */
LXW_VALIDATION_TYPE_DATE,
/** Restrict cell input to date values only, using a cell reference. */
LXW_VALIDATION_TYPE_DATE_FORMULA,
/* Restrict cell input to date values only, as a serial number.
* Undocumented. */
LXW_VALIDATION_TYPE_DATE_NUMBER,
/** Restrict cell input to time values only, using a lxw_datetime type. */
LXW_VALIDATION_TYPE_TIME,
/** Restrict cell input to time values only, using a cell reference. */
LXW_VALIDATION_TYPE_TIME_FORMULA,
/* Restrict cell input to time values only, as a serial number.
* Undocumented. */
LXW_VALIDATION_TYPE_TIME_NUMBER,
/** Restrict cell input to strings of defined length, using a cell
* reference. */
LXW_VALIDATION_TYPE_LENGTH,
/** Restrict cell input to strings of defined length, using a cell
* reference. */
LXW_VALIDATION_TYPE_LENGTH_FORMULA,
/** Restrict cell to input controlled by a custom formula that returns
* `TRUE/FALSE`. */
LXW_VALIDATION_TYPE_CUSTOM_FORMULA,
/** Allow any type of input. Mainly only useful for pop-up messages. */
LXW_VALIDATION_TYPE_ANY
};
/** Data validation criteria uses to control the selection of data. */
enum lxw_validation_criteria {
LXW_VALIDATION_CRITERIA_NONE,
/** Select data between two values. */
LXW_VALIDATION_CRITERIA_BETWEEN,
/** Select data that is not between two values. */
LXW_VALIDATION_CRITERIA_NOT_BETWEEN,
/** Select data equal to a value. */
LXW_VALIDATION_CRITERIA_EQUAL_TO,
/** Select data not equal to a value. */
LXW_VALIDATION_CRITERIA_NOT_EQUAL_TO,
/** Select data greater than a value. */
LXW_VALIDATION_CRITERIA_GREATER_THAN,
/** Select data less than a value. */
LXW_VALIDATION_CRITERIA_LESS_THAN,
/** Select data greater than or equal to a value. */
LXW_VALIDATION_CRITERIA_GREATER_THAN_OR_EQUAL_TO,
/** Select data less than or equal to a value. */
LXW_VALIDATION_CRITERIA_LESS_THAN_OR_EQUAL_TO
};
/** Data validation error types for pop-up messages. */
enum lxw_validation_error_types {
/** Show a "Stop" data validation pop-up message. This is the default. */
LXW_VALIDATION_ERROR_TYPE_STOP,
/** Show an "Error" data validation pop-up message. */
LXW_VALIDATION_ERROR_TYPE_WARNING,
/** Show an "Information" data validation pop-up message. */
LXW_VALIDATION_ERROR_TYPE_INFORMATION
};
enum cell_types {
NUMBER_CELL = 1,
STRING_CELL,
INLINE_STRING_CELL,
INLINE_RICH_STRING_CELL,
FORMULA_CELL,
ARRAY_FORMULA_CELL,
BLANK_CELL,
BOOLEAN_CELL,
HYPERLINK_URL,
HYPERLINK_INTERNAL,
HYPERLINK_EXTERNAL
};
enum pane_types {
NO_PANES = 0,
FREEZE_PANES,
SPLIT_PANES,
FREEZE_SPLIT_PANES
};
/* Define the tree.h RB structs for the red-black head types. */
RB_HEAD(lxw_table_cells, lxw_cell);
/* Define a RB_TREE struct manually to add extra members. */
struct lxw_table_rows {
struct lxw_row *rbh_root;
struct lxw_row *cached_row;
lxw_row_t cached_row_num;
};
/* Wrapper around RB_GENERATE_STATIC from tree.h to avoid unused function
* warnings and to avoid portability issues with the _unused attribute. */
#define LXW_RB_GENERATE_ROW(name, type, field, cmp) \
RB_GENERATE_INSERT_COLOR(name, type, field, static) \
RB_GENERATE_REMOVE_COLOR(name, type, field, static) \
RB_GENERATE_INSERT(name, type, field, cmp, static) \
RB_GENERATE_REMOVE(name, type, field, static) \
RB_GENERATE_FIND(name, type, field, cmp, static) \
RB_GENERATE_NEXT(name, type, field, static) \
RB_GENERATE_MINMAX(name, type, field, static) \
/* Add unused struct to allow adding a semicolon */ \
struct lxw_rb_generate_row{int unused;}
#define LXW_RB_GENERATE_CELL(name, type, field, cmp) \
RB_GENERATE_INSERT_COLOR(name, type, field, static) \
RB_GENERATE_REMOVE_COLOR(name, type, field, static) \
RB_GENERATE_INSERT(name, type, field, cmp, static) \
RB_GENERATE_REMOVE(name, type, field, static) \
RB_GENERATE_FIND(name, type, field, cmp, static) \
RB_GENERATE_NEXT(name, type, field, static) \
RB_GENERATE_MINMAX(name, type, field, static) \
/* Add unused struct to allow adding a semicolon */ \
struct lxw_rb_generate_cell{int unused;}
STAILQ_HEAD(lxw_merged_ranges, lxw_merged_range);
STAILQ_HEAD(lxw_selections, lxw_selection);
STAILQ_HEAD(lxw_data_validations, lxw_data_validation);
STAILQ_HEAD(lxw_image_data, lxw_image_options);
STAILQ_HEAD(lxw_chart_data, lxw_image_options);
/**
* @brief Options for rows and columns.
*
* Options struct for the worksheet_set_column() and worksheet_set_row()
* functions.
*
* It has the following members:
*
* * `hidden`
* * `level`
* * `collapsed`
*
* The members of this struct are explained in @ref ww_outlines_grouping.
*
*/
typedef struct lxw_row_col_options {
/** Hide the row/column */
uint8_t hidden;
uint8_t level;
uint8_t collapsed;
} lxw_row_col_options;
typedef struct lxw_col_options {
lxw_col_t firstcol;
lxw_col_t lastcol;
double width;
lxw_format *format;
uint8_t hidden;
uint8_t level;
uint8_t collapsed;
} lxw_col_options;
typedef struct lxw_merged_range {
lxw_row_t first_row;
lxw_row_t last_row;
lxw_col_t first_col;
lxw_col_t last_col;
STAILQ_ENTRY (lxw_merged_range) list_pointers;
} lxw_merged_range;
typedef struct lxw_repeat_rows {
uint8_t in_use;
lxw_row_t first_row;
lxw_row_t last_row;
} lxw_repeat_rows;
typedef struct lxw_repeat_cols {
uint8_t in_use;
lxw_col_t first_col;
lxw_col_t last_col;
} lxw_repeat_cols;
typedef struct lxw_print_area {
uint8_t in_use;
lxw_row_t first_row;
lxw_row_t last_row;
lxw_col_t first_col;
lxw_col_t last_col;
} lxw_print_area;
typedef struct lxw_autofilter {
uint8_t in_use;
lxw_row_t first_row;
lxw_row_t last_row;
lxw_col_t first_col;
lxw_col_t last_col;
} lxw_autofilter;
typedef struct lxw_panes {
uint8_t type;
lxw_row_t first_row;
lxw_col_t first_col;
lxw_row_t top_row;
lxw_col_t left_col;
double x_split;
double y_split;
} lxw_panes;
typedef struct lxw_selection {
char pane[LXW_PANE_NAME_LENGTH];
char active_cell[LXW_MAX_CELL_RANGE_LENGTH];
char sqref[LXW_MAX_CELL_RANGE_LENGTH];
STAILQ_ENTRY (lxw_selection) list_pointers;
} lxw_selection;
/**
* @brief Worksheet data validation options.
*/
typedef struct lxw_data_validation {
/**
* Set the validation type. Should be a #lxw_validation_types value.
*/
uint8_t validate;
/**
* Set the validation criteria type to select the data. Should be a
* #lxw_validation_criteria value.
*/
uint8_t criteria;
/** Controls whether a data validation is not applied to blank data in the
* cell. Should be a #lxw_validation_boolean value. It is on by
* default.
*/
uint8_t ignore_blank;
/**
* This parameter is used to toggle on and off the 'Show input message
* when cell is selected' option in the Excel data validation dialog. When
* the option is off an input message is not displayed even if it has been
* set using input_message. Should be a #lxw_validation_boolean value. It
* is on by default.
*/
uint8_t show_input;
/**
* This parameter is used to toggle on and off the 'Show error alert
* after invalid data is entered' option in the Excel data validation
* dialog. When the option is off an error message is not displayed even
* if it has been set using error_message. Should be a
* #lxw_validation_boolean value. It is on by default.
*/
uint8_t show_error;
/**
* This parameter is used to specify the type of error dialog that is
* displayed. Should be a #lxw_validation_error_types value.
*/
uint8_t error_type;
/**
* This parameter is used to toggle on and off the 'In-cell dropdown'
* option in the Excel data validation dialog. When the option is on a
* dropdown list will be shown for list validations. Should be a
* #lxw_validation_boolean value. It is on by default.
*/
uint8_t dropdown;
uint8_t is_between;
/**
* This parameter is used to set the limiting value to which the criteria
* is applied using a whole or decimal number.
*/
double value_number;
/**
* This parameter is used to set the limiting value to which the criteria
* is applied using a cell reference. It is valid for any of the
* `_FORMULA` validation types.
*/
char *value_formula;
/**
* This parameter is used to set a list of strings for a drop down list.
* The list should be a `NULL` terminated array of char* strings:
*
* @code
* char *list[] = {"open", "high", "close", NULL};
*
* data_validation->validate = LXW_VALIDATION_TYPE_LIST;
* data_validation->value_list = list;
* @endcode
*
* The `value_formula` parameter can also be used to specify a list from
* an Excel cell range.
*
* Note, the string list is restricted by Excel to 255 characters,
* including comma separators.
*/
char **value_list;
/**
* This parameter is used to set the limiting value to which the date or
* time criteria is applied using a #lxw_datetime struct.
*/
lxw_datetime value_datetime;
/**
* This parameter is the same as `value_number` but for the minimum value
* when a `BETWEEN` criteria is used.
*/
double minimum_number;
/**
* This parameter is the same as `value_formula` but for the minimum value
* when a `BETWEEN` criteria is used.
*/
char *minimum_formula;
/**
* This parameter is the same as `value_datetime` but for the minimum value
* when a `BETWEEN` criteria is used.
*/
lxw_datetime minimum_datetime;
/**
* This parameter is the same as `value_number` but for the maximum value
* when a `BETWEEN` criteria is used.
*/
double maximum_number;
/**
* This parameter is the same as `value_formula` but for the maximum value
* when a `BETWEEN` criteria is used.
*/
char *maximum_formula;
/**
* This parameter is the same as `value_datetime` but for the maximum value
* when a `BETWEEN` criteria is used.
*/
lxw_datetime maximum_datetime;
/**
* The input_title parameter is used to set the title of the input message
* that is displayed when a cell is entered. It has no default value and
* is only displayed if the input message is displayed. See the
* `input_message` parameter below.
*
* The maximum title length is 32 characters.
*/
char *input_title;
/**
* The input_message parameter is used to set the input message that is
* displayed when a cell is entered. It has no default value.
*
* The message can be split over several lines using newlines. The maximum
* message length is 255 characters.
*/
char *input_message;
/**
* The error_title parameter is used to set the title of the error message
* that is displayed when the data validation criteria is not met. The
* default error title is 'Microsoft Excel'. The maximum title length is
* 32 characters.
*/
char *error_title;
/**
* The error_message parameter is used to set the error message that is
* displayed when a cell is entered. The default error message is "The
* value you entered is not valid. A user has restricted values that can
* be entered into the cell".
*
* The message can be split over several lines using newlines. The maximum
* message length is 255 characters.
*/
char *error_message;
char sqref[LXW_MAX_CELL_RANGE_LENGTH];
STAILQ_ENTRY (lxw_data_validation) list_pointers;
} lxw_data_validation;
/**
* @brief Options for inserted images
*
* Options for modifying images inserted via `worksheet_insert_image_opt()`.
*
*/
typedef struct lxw_image_options {
/** Offset from the left of the cell in pixels. */
int32_t x_offset;
/** Offset from the top of the cell in pixels. */
int32_t y_offset;
/** X scale of the image as a decimal. */
double x_scale;
/** Y scale of the image as a decimal. */
double y_scale;
lxw_row_t row;
lxw_col_t col;
char *filename;
char *description;
char *url;
char *tip;
uint8_t anchor;
/* Internal metadata. */
FILE *stream;
uint8_t image_type;
uint8_t is_image_buffer;
unsigned char *image_buffer;
size_t image_buffer_size;
double width;
double height;
char *extension;
double x_dpi;
double y_dpi;
lxw_chart *chart;
STAILQ_ENTRY (lxw_image_options) list_pointers;
} lxw_image_options;
/**
* @brief Header and footer options.
*
* Optional parameters used in the worksheet_set_header_opt() and
* worksheet_set_footer_opt() functions.
*
*/
typedef struct lxw_header_footer_options {
/** Header or footer margin in inches. Excel default is 0.3. */
double margin;
} lxw_header_footer_options;
/**
* @brief Worksheet protection options.
*/
typedef struct lxw_protection {
/** Turn off selection of locked cells. This in on in Excel by default.*/
uint8_t no_select_locked_cells;
/** Turn off selection of unlocked cells. This in on in Excel by default.*/
uint8_t no_select_unlocked_cells;
/** Prevent formatting of cells. */
uint8_t format_cells;
/** Prevent formatting of columns. */
uint8_t format_columns;
/** Prevent formatting of rows. */
uint8_t format_rows;
/** Prevent insertion of columns. */
uint8_t insert_columns;
/** Prevent insertion of rows. */
uint8_t insert_rows;
/** Prevent insertion of hyperlinks. */
uint8_t insert_hyperlinks;
/** Prevent deletion of columns. */
uint8_t delete_columns;
/** Prevent deletion of rows. */
uint8_t delete_rows;
/** Prevent sorting data. */
uint8_t sort;
/** Prevent filtering data. */
uint8_t autofilter;
/** Prevent insertion of pivot tables. */
uint8_t pivot_tables;
/** Protect scenarios. */
uint8_t scenarios;
/** Protect drawing objects. Worksheets only. */
uint8_t objects;
/** Turn off chartsheet content protection. */
uint8_t no_content;
/** Turn off chartsheet objects. */
uint8_t no_objects;
uint8_t no_sheet;
uint8_t is_configured;
char hash[5];
} lxw_protection;
/**
* @brief Struct to represent a rich string format/string pair.
*
* Arrays of this struct are used to define "rich" multi-format strings that
* are passed to `worksheet_write_rich_string()`. Each struct represents a
* fragment of the rich multi-format string with a lxw_format to define the
* format for the string part. If the string fragment is unformatted then
* `NULL` can be used for the format.
*/
typedef struct lxw_rich_string_tuple {
/** The format for a string fragment in a rich string. NULL if the string
* isn't formatted. */
lxw_format *format;
/** The string fragment. */
char *string;
} lxw_rich_string_tuple;
/**
* @brief Struct to represent an Excel worksheet.
*
* The members of the lxw_worksheet struct aren't modified directly. Instead
* the worksheet properties are set by calling the functions shown in
* worksheet.h.
*/
typedef struct lxw_worksheet {
FILE *file;
FILE *optimize_tmpfile;
struct lxw_table_rows *table;
struct lxw_table_rows *hyperlinks;
struct lxw_cell **array;
struct lxw_merged_ranges *merged_ranges;
struct lxw_selections *selections;
struct lxw_data_validations *data_validations;
struct lxw_image_data *image_data;
struct lxw_chart_data *chart_data;
lxw_row_t dim_rowmin;
lxw_row_t dim_rowmax;
lxw_col_t dim_colmin;
lxw_col_t dim_colmax;
lxw_sst *sst;
char *name;
char *quoted_name;
char *tmpdir;
uint32_t index;
uint8_t active;
uint8_t selected;
uint8_t hidden;
uint16_t *active_sheet;
uint16_t *first_sheet;
uint8_t is_chartsheet;
lxw_col_options **col_options;
uint16_t col_options_max;
double *col_sizes;
uint16_t col_sizes_max;
lxw_format **col_formats;
uint16_t col_formats_max;
uint8_t col_size_changed;
uint8_t row_size_changed;
uint8_t optimize;
struct lxw_row *optimize_row;
uint16_t fit_height;
uint16_t fit_width;
uint16_t horizontal_dpi;
uint16_t hlink_count;
uint16_t page_start;
uint16_t print_scale;
uint16_t rel_count;
uint16_t vertical_dpi;
uint16_t zoom;
uint8_t filter_on;
uint8_t fit_page;
uint8_t hcenter;
uint8_t orientation;
uint8_t outline_changed;
uint8_t outline_on;
uint8_t outline_style;
uint8_t outline_below;
uint8_t outline_right;
uint8_t page_order;
uint8_t page_setup_changed;
uint8_t page_view;
uint8_t paper_size;
uint8_t print_gridlines;
uint8_t print_headers;
uint8_t print_options_changed;
uint8_t right_to_left;
uint8_t screen_gridlines;
uint8_t show_zeros;
uint8_t vba_codename;
uint8_t vcenter;
uint8_t zoom_scale_normal;
uint8_t num_validations;
lxw_color_t tab_color;
double margin_left;
double margin_right;
double margin_top;
double margin_bottom;
double margin_header;
double margin_footer;
double default_row_height;
uint32_t default_row_pixels;
uint32_t default_col_pixels;
uint8_t default_row_zeroed;
uint8_t default_row_set;
uint8_t outline_row_level;
uint8_t outline_col_level;
uint8_t header_footer_changed;
char header[LXW_HEADER_FOOTER_MAX];
char footer[LXW_HEADER_FOOTER_MAX];
struct lxw_repeat_rows repeat_rows;
struct lxw_repeat_cols repeat_cols;
struct lxw_print_area print_area;
struct lxw_autofilter autofilter;
uint16_t merged_range_count;
lxw_row_t *hbreaks;
lxw_col_t *vbreaks;
uint16_t hbreaks_count;
uint16_t vbreaks_count;
struct lxw_rel_tuples *external_hyperlinks;
struct lxw_rel_tuples *external_drawing_links;
struct lxw_rel_tuples *drawing_links;
struct lxw_panes panes;
struct lxw_protection protection;
lxw_drawing *drawing;
STAILQ_ENTRY (lxw_worksheet) list_pointers;
} lxw_worksheet;
/*
* Worksheet initialization data.
*/
typedef struct lxw_worksheet_init_data {
uint32_t index;
uint8_t hidden;
uint8_t optimize;
uint16_t *active_sheet;
uint16_t *first_sheet;
lxw_sst *sst;
char *name;
char *quoted_name;
char *tmpdir;
} lxw_worksheet_init_data;
/* Struct to represent a worksheet row. */
typedef struct lxw_row {
lxw_row_t row_num;
double height;
lxw_format *format;
uint8_t hidden;
uint8_t level;
uint8_t collapsed;
uint8_t row_changed;
uint8_t data_changed;
uint8_t height_changed;
struct lxw_table_cells *cells;
/* tree management pointers for tree.h. */
RB_ENTRY (lxw_row) tree_pointers;
} lxw_row;
/* Struct to represent a worksheet cell. */
typedef struct lxw_cell {
lxw_row_t row_num;
lxw_col_t col_num;
enum cell_types type;
lxw_format *format;
union {
double number;
int32_t string_id;
char *string;
} u;
double formula_result;
char *user_data1;
char *user_data2;
char *sst_string;
/* List pointers for tree.h. */
RB_ENTRY (lxw_cell) tree_pointers;
} lxw_cell;
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* @brief Write a number to a worksheet cell.
*
* @param worksheet pointer to a lxw_worksheet instance to be updated.
* @param row The zero indexed row number.
* @param col The zero indexed column number.
* @param number The number to write to the cell.
* @param format A pointer to a Format instance or NULL.
*
* @return A #lxw_error code.
*
* The `worksheet_write_number()` function writes numeric types to the cell
* specified by `row` and `column`:
*
* @code
* worksheet_write_number(worksheet, 0, 0, 123456, NULL);
* worksheet_write_number(worksheet, 1, 0, 2.3451, NULL);
* @endcode
*
* @image html write_number01.png
*
* The native data type for all numbers in Excel is a IEEE-754 64-bit
* double-precision floating point, which is also the default type used by
* `%worksheet_write_number`.
*
* The `format` parameter is used to apply formatting to the cell. This
* parameter can be `NULL` to indicate no formatting or it can be a
* @ref format.h "Format" object.
*
* @code
* lxw_format *format = workbook_add_format(workbook);
* format_set_num_format(format, "$#,##0.00");
*
* worksheet_write_number(worksheet, 0, 0, 1234.567, format);
* @endcode
*
* @image html write_number02.png
*
* @note Excel doesn't support `NaN`, `Inf` or `-Inf` as a number value. If
* you are writing data that contains these values then your application
* should convert them to a string or handle them in some other way.
*
*/
lxw_error worksheet_write_number(lxw_worksheet *worksheet,
lxw_row_t row,
lxw_col_t col, double number,
lxw_format *format);
/**
* @brief Write a string to a worksheet cell.
*
* @param worksheet pointer to a lxw_worksheet instance to be updated.
* @param row The zero indexed row number.
* @param col The zero indexed column number.
* @param string String to write to cell.
* @param format A pointer to a Format instance or NULL.
*
* @return A #lxw_error code.
*
* The `%worksheet_write_string()` function writes a string to the cell
* specified by `row` and `column`:
*
* @code
* worksheet_write_string(worksheet, 0, 0, "This phrase is English!", NULL);
* @endcode
*
* @image html write_string01.png
*
* The `format` parameter is used to apply formatting to the cell. This
* parameter can be `NULL` to indicate no formatting or it can be a
* @ref format.h "Format" object:
*
* @code
* lxw_format *format = workbook_add_format(workbook);
* format_set_bold(format);
*
* worksheet_write_string(worksheet, 0, 0, "This phrase is Bold!", format);
* @endcode
*
* @image html write_string02.png
*
* Unicode strings are supported in UTF-8 encoding. This generally requires
* that your source file is UTF-8 encoded or that the data has been read from
* a UTF-8 source:
*
* @code
* worksheet_write_string(worksheet, 0, 0, "Это фраза на русском!", NULL);
* @endcode
*
* @image html write_string03.png
*
*/
lxw_error worksheet_write_string(lxw_worksheet *worksheet,
lxw_row_t row,
lxw_col_t col, const char *string,
lxw_format *format);
/**
* @brief Write a formula to a worksheet cell.
*
* @param worksheet pointer to a lxw_worksheet instance to be updated.
* @param row The zero indexed row number.
* @param col The zero indexed column number.
* @param formula Formula string to write to cell.
* @param format A pointer to a Format instance or NULL.
*
* @return A #lxw_error code.
*
* The `%worksheet_write_formula()` function writes a formula or function to
* the cell specified by `row` and `column`:
*
* @code
* worksheet_write_formula(worksheet, 0, 0, "=B3 + 6", NULL);
* worksheet_write_formula(worksheet, 1, 0, "=SIN(PI()/4)", NULL);
* worksheet_write_formula(worksheet, 2, 0, "=SUM(A1:A2)", NULL);
* worksheet_write_formula(worksheet, 3, 0, "=IF(A3>1,\"Yes\", \"No\")", NULL);
* worksheet_write_formula(worksheet, 4, 0, "=AVERAGE(1, 2, 3, 4)", NULL);
* worksheet_write_formula(worksheet, 5, 0, "=DATEVALUE(\"1-Jan-2013\")", NULL);
* @endcode
*
* @image html write_formula01.png
*
* The `format` parameter is used to apply formatting to the cell. This
* parameter can be `NULL` to indicate no formatting or it can be a
* @ref format.h "Format" object.
*
* Libxlsxwriter doesn't calculate the value of a formula and instead stores a
* default value of `0`. The correct formula result is displayed in Excel, as
* shown in the example above, since it recalculates the formulas when it loads
* the file. For cases where this is an issue see the
* `worksheet_write_formula_num()` function and the discussion in that section.
*
* Formulas must be written with the US style separator/range operator which
* is a comma (not semi-colon). Therefore a formula with multiple values
* should be written as follows:
*
* @code
* // OK.
* worksheet_write_formula(worksheet, 0, 0, "=SUM(1, 2, 3)", NULL);
*
* // NO. Error on load.
* worksheet_write_formula(worksheet, 1, 0, "=SUM(1; 2; 3)", NULL);
* @endcode
*
* See also @ref working_with_formulas.
*/