xlsxwriter 0.2.1.pre.2 → 0.2.3.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +4 -3
- data/ext/xlsxwriter/chart.c +84 -20
- data/ext/xlsxwriter/chart.h +1 -0
- data/ext/xlsxwriter/chartsheet.c +34 -13
- data/ext/xlsxwriter/common.h +5 -5
- data/ext/xlsxwriter/extconf.rb +8 -8
- data/ext/xlsxwriter/libxlsxwriter/License.txt +24 -2
- data/ext/xlsxwriter/libxlsxwriter/Makefile +46 -12
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/app.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/chart.h +196 -30
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/chartsheet.h +3 -3
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/comment.h +76 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/common.h +24 -5
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/content_types.h +5 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/core.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/custom.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/drawing.h +6 -17
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/format.h +20 -6
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/hash_table.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/packager.h +3 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/relationships.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/shared_strings.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/styles.h +11 -5
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/theme.h +1 -1
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/md5.h +43 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/utility.h +42 -3
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/vml.h +55 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/workbook.h +83 -18
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/worksheet.h +1519 -109
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/xmlwriter.h +4 -2
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter.h +3 -2
- data/ext/xlsxwriter/libxlsxwriter/src/Makefile +25 -7
- data/ext/xlsxwriter/libxlsxwriter/src/app.c +1 -1
- data/ext/xlsxwriter/libxlsxwriter/src/chart.c +332 -48
- data/ext/xlsxwriter/libxlsxwriter/src/chartsheet.c +20 -19
- data/ext/xlsxwriter/libxlsxwriter/src/comment.c +443 -0
- data/ext/xlsxwriter/libxlsxwriter/src/content_types.c +20 -1
- data/ext/xlsxwriter/libxlsxwriter/src/core.c +2 -2
- data/ext/xlsxwriter/libxlsxwriter/src/custom.c +1 -1
- data/ext/xlsxwriter/libxlsxwriter/src/drawing.c +58 -20
- data/ext/xlsxwriter/libxlsxwriter/src/format.c +98 -25
- data/ext/xlsxwriter/libxlsxwriter/src/hash_table.c +1 -1
- data/ext/xlsxwriter/libxlsxwriter/src/packager.c +269 -12
- data/ext/xlsxwriter/libxlsxwriter/src/relationships.c +1 -1
- data/ext/xlsxwriter/libxlsxwriter/src/shared_strings.c +2 -4
- data/ext/xlsxwriter/libxlsxwriter/src/styles.c +334 -48
- data/ext/xlsxwriter/libxlsxwriter/src/theme.c +1 -1
- data/ext/xlsxwriter/libxlsxwriter/src/utility.c +71 -8
- data/ext/xlsxwriter/libxlsxwriter/src/vml.c +1032 -0
- data/ext/xlsxwriter/libxlsxwriter/src/workbook.c +343 -27
- data/ext/xlsxwriter/libxlsxwriter/src/worksheet.c +3759 -478
- data/ext/xlsxwriter/libxlsxwriter/src/xmlwriter.c +81 -2
- data/ext/xlsxwriter/libxlsxwriter/third_party/md5/Makefile +42 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/md5/md5.c +291 -0
- data/ext/xlsxwriter/libxlsxwriter/third_party/md5/md5.h +43 -0
- data/ext/xlsxwriter/rich_string.c +28 -9
- data/ext/xlsxwriter/shared_strings.c +75 -0
- data/ext/xlsxwriter/shared_strings.h +15 -0
- data/ext/xlsxwriter/workbook.c +87 -13
- data/ext/xlsxwriter/workbook.h +1 -0
- data/ext/xlsxwriter/workbook_properties.c +2 -2
- data/ext/xlsxwriter/worksheet.c +75 -23
- data/ext/xlsxwriter/worksheet.h +1 -0
- data/ext/xlsxwriter/xlsxwriter.c +2 -0
- data/lib/xlsxwriter/rich_string.rb +0 -2
- data/lib/xlsxwriter/version.rb +1 -1
- data/lib/xlsxwriter/worksheet.rb +2 -2
- data/test/{run-test.rb → run_test.rb} +3 -3
- data/test/support/chart_test.rb +3 -3
- data/test/support/with_xlsx_file.rb +4 -2
- data/test/support/xlsx_comparable.rb +40 -26
- data/test/test_array_formula.rb +42 -0
- data/test/test_autofilter.rb +72 -0
- data/test/{test-chart-area.rb → test_chart_area.rb} +2 -2
- data/test/{test-chart-axis.rb → test_chart_axis.rb} +16 -16
- data/test/test_chart_bar.rb +382 -0
- data/test/test_chart_blank.rb +27 -0
- data/test/{test-chart-column.rb → test_chart_column.rb} +2 -2
- data/test/{test-chart-doughnut.rb → test_chart_doughnut.rb} +2 -2
- data/test/{test-chart-legend.rb → test_chart_legend.rb} +2 -2
- data/test/{test-chart-pie.rb → test_chart_pie.rb} +2 -2
- data/test/{test-chart-scatter.rb → test_chart_scatter.rb} +3 -4
- data/test/{test-chart-size.rb → test_chart_size.rb} +2 -2
- data/test/{test-chart-title.rb → test_chart_title.rb} +3 -3
- data/test/{test-chartsheet.rb → test_chartsheet.rb} +2 -2
- data/test/{test-data.rb → test_data.rb} +1 -1
- data/test/{test-data-validation.rb → test_data_validation.rb} +23 -24
- data/test/{test-default-row.rb → test_default_row.rb} +1 -1
- data/test/{test-defined-name.rb → test_defined_name.rb} +12 -12
- data/test/{test-escapes.rb → test_escapes.rb} +5 -2
- data/test/{test-fit-to-pages.rb → test_fit_to_pages.rb} +6 -6
- data/test/{test-formatting.rb → test_formatting.rb} +10 -10
- data/test/{test-gridlines.rb → test_gridlines.rb} +3 -3
- data/test/{test-hyperlink.rb → test_hyperlink.rb} +22 -11
- data/test/{test-image.rb → test_image.rb} +6 -4
- data/test/{test-macro.rb → test_macro.rb} +1 -1
- data/test/{test-merge-range.rb → test_merge_range.rb} +1 -1
- data/test/{test-misc.rb → test_misc.rb} +2 -2
- data/test/{test-optimize.rb → test_optimize.rb} +2 -4
- data/test/{test-outline.rb → test_outline.rb} +14 -14
- data/test/{test-page-breaks.rb → test_page_breaks.rb} +2 -2
- data/test/{test-page-setup.rb → test_page_setup.rb} +2 -2
- data/test/{test-panes.rb → test_panes.rb} +1 -1
- data/test/{test-print-area.rb → test_print_area.rb} +3 -3
- data/test/{test-print-options.rb → test_print_options.rb} +7 -7
- data/test/{test-print-scale.rb → test_print_scale.rb} +2 -2
- data/test/{test-properties.rb → test_properties.rb} +2 -2
- data/test/{test-protect.rb → test_protect.rb} +3 -3
- data/test/{test-repeat.rb → test_repeat.rb} +3 -3
- data/test/{test-rich-string.rb → test_rich_string.rb} +5 -9
- data/test/{test-row-col-format.rb → test_row_col_format.rb} +1 -1
- data/test/{test-ruby-worksheet.rb → test_ruby_worksheet.rb} +2 -2
- data/test/{test-set-selection.rb → test_set_selection.rb} +2 -2
- data/test/{test-set-start-page.rb → test_set_start_page.rb} +2 -2
- data/test/{test-simple.rb → test_simple.rb} +10 -10
- data/test/{test-types.rb → test_types.rb} +1 -1
- data/test/{xlsx-func-testcase.rb → xlsx_func_testcase.rb} +1 -0
- metadata +127 -106
- data/test/test-array-formula.rb +0 -35
- data/test/test-autofilter.rb +0 -72
- data/test/test-chart-bar.rb +0 -74
- /data/test/{test-errors.rb → test_errors.rb} +0 -0
data/ext/xlsxwriter/workbook.c
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
#include "chartsheet.h"
|
8
8
|
#include "common.h"
|
9
9
|
#include "format.h"
|
10
|
+
#include "shared_strings.h"
|
10
11
|
#include "workbook.h"
|
11
12
|
#include "workbook_properties.h"
|
12
13
|
#include "worksheet.h"
|
@@ -14,16 +15,30 @@
|
|
14
15
|
|
15
16
|
VALUE cWorkbook;
|
16
17
|
|
18
|
+
void workbook_clear(void *p);
|
17
19
|
void workbook_free(void *p);
|
18
20
|
VALUE workbook_release(VALUE self);
|
19
21
|
|
22
|
+
size_t
|
23
|
+
workbook_size(const void *data) {
|
24
|
+
return sizeof(struct workbook);
|
25
|
+
}
|
26
|
+
|
27
|
+
const rb_data_type_t workbook_type = {
|
28
|
+
.wrap_struct_name = "workbook",
|
29
|
+
.function = {
|
30
|
+
.dmark = NULL,
|
31
|
+
.dfree = workbook_free,
|
32
|
+
.dsize = workbook_size,
|
33
|
+
},
|
34
|
+
.data = NULL,
|
35
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
36
|
+
};
|
20
37
|
|
21
38
|
VALUE
|
22
39
|
workbook_alloc(VALUE klass) {
|
23
|
-
VALUE obj;
|
24
40
|
struct workbook *ptr;
|
25
|
-
|
26
|
-
obj = Data_Make_Struct(klass, struct workbook, NULL, workbook_free, ptr);
|
41
|
+
VALUE obj = TypedData_Make_Struct(klass, struct workbook, &workbook_type, ptr);
|
27
42
|
|
28
43
|
ptr->path = NULL;
|
29
44
|
ptr->workbook = NULL;
|
@@ -88,7 +103,7 @@ workbook_init(int argc, VALUE *argv, VALUE self) {
|
|
88
103
|
}
|
89
104
|
}
|
90
105
|
|
91
|
-
|
106
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
92
107
|
|
93
108
|
size_t len = RSTRING_LEN(argv[0]);
|
94
109
|
ptr->path = malloc(len + 1);
|
@@ -119,14 +134,14 @@ workbook_init(int argc, VALUE *argv, VALUE self) {
|
|
119
134
|
VALUE
|
120
135
|
workbook_release(VALUE self) {
|
121
136
|
struct workbook *ptr;
|
122
|
-
|
137
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
123
138
|
|
124
|
-
|
139
|
+
workbook_clear(ptr);
|
125
140
|
return self;
|
126
141
|
}
|
127
142
|
|
128
143
|
void
|
129
|
-
|
144
|
+
workbook_clear(void *p) {
|
130
145
|
struct workbook *ptr = p;
|
131
146
|
|
132
147
|
if (ptr->workbook) {
|
@@ -168,6 +183,11 @@ workbook_free(void *p) {
|
|
168
183
|
}
|
169
184
|
}
|
170
185
|
|
186
|
+
void workbook_free(void *p) {
|
187
|
+
workbook_clear(p);
|
188
|
+
ruby_xfree(p);
|
189
|
+
};
|
190
|
+
|
171
191
|
/* call-seq:
|
172
192
|
* wb.add_worksheet([name]) -> ws
|
173
193
|
* wb.add_worksheet([name]) { |ws| block } -> obj
|
@@ -187,7 +207,7 @@ workbook_add_worksheet_(int argc, VALUE *argv, VALUE self) {
|
|
187
207
|
rb_check_arity(argc, 0, 1);
|
188
208
|
|
189
209
|
struct workbook *ptr;
|
190
|
-
|
210
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
191
211
|
if (ptr->workbook) {
|
192
212
|
worksheet = rb_funcall(cWorksheet, rb_intern("new"), argc + 1, self, argv[0]);
|
193
213
|
}
|
@@ -219,7 +239,7 @@ workbook_add_chartsheet_(int argc, VALUE *argv, VALUE self) {
|
|
219
239
|
rb_check_arity(argc, 0, 1);
|
220
240
|
|
221
241
|
struct workbook *ptr;
|
222
|
-
|
242
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
223
243
|
if (ptr->workbook) {
|
224
244
|
chartsheet = rb_funcall(cChartsheet, rb_intern("new"), argc + 1, self, argv[0]);
|
225
245
|
}
|
@@ -267,7 +287,7 @@ VALUE
|
|
267
287
|
workbook_add_format_(VALUE self, VALUE key, VALUE opts) {
|
268
288
|
struct workbook *ptr;
|
269
289
|
lxw_format *format;
|
270
|
-
|
290
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
271
291
|
|
272
292
|
if (!ptr->formats) {
|
273
293
|
ptr->formats = st_init_numtable();
|
@@ -334,7 +354,7 @@ workbook_add_vba_project_(VALUE self, VALUE filename) {
|
|
334
354
|
VALUE
|
335
355
|
workbook_set_default_xf_indices_(VALUE self) {
|
336
356
|
struct workbook *ptr;
|
337
|
-
|
357
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
338
358
|
lxw_workbook_set_default_xf_indices(ptr->workbook);
|
339
359
|
return self;
|
340
360
|
}
|
@@ -352,7 +372,7 @@ workbook_set_vba_name_(VALUE self, VALUE name) {
|
|
352
372
|
|
353
373
|
/* call-seq: wb.properties -> wb_properties
|
354
374
|
*
|
355
|
-
* Returns
|
375
|
+
* Returns workbook properties accessor object.
|
356
376
|
*
|
357
377
|
* wb.properties.title = 'My awesome sheet'
|
358
378
|
*/
|
@@ -376,6 +396,56 @@ workbook_define_name_(VALUE self, VALUE name, VALUE formula) {
|
|
376
396
|
return self;
|
377
397
|
}
|
378
398
|
|
399
|
+
/* call-seq: wb.unset_default_url_format -> wb
|
400
|
+
*
|
401
|
+
* Unsets default url format
|
402
|
+
*/
|
403
|
+
VALUE
|
404
|
+
workbook_unset_default_url_format_(VALUE self) {
|
405
|
+
struct workbook *ptr;
|
406
|
+
|
407
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
408
|
+
workbook_unset_default_url_format(ptr->workbook);
|
409
|
+
|
410
|
+
return self;
|
411
|
+
}
|
412
|
+
|
413
|
+
/* call-seq: wb.max_url_length -> Integer
|
414
|
+
*/
|
415
|
+
VALUE
|
416
|
+
workbook_max_url_length_(VALUE self) {
|
417
|
+
struct workbook *ptr;
|
418
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
419
|
+
return INT2NUM(ptr->workbook->max_url_length);
|
420
|
+
}
|
421
|
+
|
422
|
+
/* call-seq: wb.max_url_length = 255
|
423
|
+
*/
|
424
|
+
VALUE
|
425
|
+
workbook_max_url_length_set_(VALUE self, VALUE value) {
|
426
|
+
struct workbook *ptr;
|
427
|
+
|
428
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
429
|
+
|
430
|
+
ptr->workbook->max_url_length = NUM2INT(value);
|
431
|
+
|
432
|
+
return value;
|
433
|
+
}
|
434
|
+
|
435
|
+
/* call-seq:
|
436
|
+
* wb.sst.string_count -> 0
|
437
|
+
*
|
438
|
+
* Returns special accessor object for shared strings table.
|
439
|
+
*/
|
440
|
+
VALUE
|
441
|
+
workbook_sst_(VALUE self) {
|
442
|
+
struct workbook *ptr;
|
443
|
+
|
444
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
445
|
+
|
446
|
+
return alloc_shared_strings_table_by_ref(ptr->workbook->sst);
|
447
|
+
}
|
448
|
+
|
379
449
|
/* call-seq:
|
380
450
|
* wb.validate_sheet_name(name) -> true
|
381
451
|
* wb.validate_worksheet_name(name) -> true
|
@@ -399,7 +469,7 @@ workbook_get_format(VALUE self, VALUE key) {
|
|
399
469
|
if (NIL_P(key))
|
400
470
|
return NULL;
|
401
471
|
|
402
|
-
|
472
|
+
TypedData_Get_Struct(self, struct workbook, &workbook_type, ptr);
|
403
473
|
|
404
474
|
if (!ptr->formats)
|
405
475
|
return NULL;
|
@@ -452,9 +522,13 @@ init_xlsxwriter_workbook() {
|
|
452
522
|
rb_define_method(cWorkbook, "define_name", workbook_define_name_, 2);
|
453
523
|
rb_define_method(cWorkbook, "properties", workbook_properties_, 0);
|
454
524
|
rb_define_method(cWorkbook, "set_default_xf_indices", workbook_set_default_xf_indices_, 0);
|
525
|
+
rb_define_method(cWorkbook, "unset_default_url_format", workbook_unset_default_url_format_, 0);
|
455
526
|
rb_define_method(cWorkbook, "validate_sheet_name", workbook_validate_sheet_name_, 1);
|
456
527
|
rb_define_method(cWorkbook, "validate_worksheet_name", workbook_validate_sheet_name_, 1);
|
457
528
|
rb_define_method(cWorkbook, "vba_name=", workbook_set_vba_name_, 1);
|
529
|
+
rb_define_method(cWorkbook, "max_url_length", workbook_max_url_length_, 0);
|
530
|
+
rb_define_method(cWorkbook, "max_url_length=", workbook_max_url_length_set_, 1);
|
531
|
+
rb_define_method(cWorkbook, "sst", workbook_sst_, 0);
|
458
532
|
|
459
533
|
/*
|
460
534
|
* This attribute contains effective font widths used for automatic column
|
data/ext/xlsxwriter/workbook.h
CHANGED
@@ -11,7 +11,7 @@ VALUE
|
|
11
11
|
workbook_properties_init_(VALUE self, VALUE workbook) {
|
12
12
|
struct workbook *wb_ptr;
|
13
13
|
rb_iv_set(self, "@workbook", workbook);
|
14
|
-
|
14
|
+
TypedData_Get_Struct(workbook, struct workbook, &workbook_type, wb_ptr);
|
15
15
|
if (!wb_ptr->properties) {
|
16
16
|
wb_ptr->properties = calloc(1, sizeof(lxw_doc_properties));
|
17
17
|
}
|
@@ -42,7 +42,7 @@ workbook_properties_set_(VALUE self, VALUE key, VALUE value) {
|
|
42
42
|
}
|
43
43
|
|
44
44
|
struct workbook *wb_ptr;
|
45
|
-
|
45
|
+
TypedData_Get_Struct(rb_iv_get(self, "@workbook"), struct workbook, &workbook_type, wb_ptr);
|
46
46
|
lxw_doc_properties *props = wb_ptr->properties;
|
47
47
|
if (!props) {
|
48
48
|
rb_raise(rb_eRuntimeError, "Workbook properties are already freed.");
|
data/ext/xlsxwriter/worksheet.c
CHANGED
@@ -7,15 +7,32 @@
|
|
7
7
|
|
8
8
|
VALUE cWorksheet;
|
9
9
|
|
10
|
+
void worksheet_clear(void *p);
|
10
11
|
void worksheet_free(void *p);
|
11
12
|
|
13
|
+
size_t worksheet_size(const void *data) {
|
14
|
+
return sizeof(struct worksheet);
|
15
|
+
}
|
16
|
+
|
17
|
+
const rb_data_type_t worksheet_type = {
|
18
|
+
.wrap_struct_name = "worksheet",
|
19
|
+
.function =
|
20
|
+
{
|
21
|
+
.dmark = NULL,
|
22
|
+
.dfree = worksheet_free,
|
23
|
+
.dsize = worksheet_size,
|
24
|
+
},
|
25
|
+
.data = NULL,
|
26
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
27
|
+
};
|
28
|
+
|
12
29
|
|
13
30
|
VALUE
|
14
31
|
worksheet_alloc(VALUE klass) {
|
15
32
|
VALUE obj;
|
16
33
|
struct worksheet *ptr;
|
17
34
|
|
18
|
-
obj =
|
35
|
+
obj = TypedData_Make_Struct(klass, struct worksheet, &worksheet_type, ptr);
|
19
36
|
|
20
37
|
ptr->worksheet = NULL;
|
21
38
|
|
@@ -31,7 +48,7 @@ worksheet_init(int argc, VALUE *argv, VALUE self) {
|
|
31
48
|
struct workbook *wb_ptr;
|
32
49
|
struct worksheet *ptr;
|
33
50
|
|
34
|
-
|
51
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
35
52
|
|
36
53
|
rb_check_arity(argc, 1, 2);
|
37
54
|
if (argc == 2) {
|
@@ -66,7 +83,7 @@ worksheet_init(int argc, VALUE *argv, VALUE self) {
|
|
66
83
|
rb_iv_set(self, "@use_auto_width", auto_width);
|
67
84
|
rb_iv_set(self, "@col_auto_widths", rb_ary_new());
|
68
85
|
|
69
|
-
|
86
|
+
TypedData_Get_Struct(argv[0], struct workbook, &workbook_type, wb_ptr);
|
70
87
|
ptr->worksheet = workbook_add_worksheet(wb_ptr->workbook, name);
|
71
88
|
if (!ptr->worksheet)
|
72
89
|
rb_raise(eXlsxWriterError, "worksheet was not created");
|
@@ -77,14 +94,14 @@ worksheet_init(int argc, VALUE *argv, VALUE self) {
|
|
77
94
|
VALUE
|
78
95
|
worksheet_release(VALUE self) {
|
79
96
|
struct worksheet *ptr;
|
80
|
-
|
97
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
81
98
|
|
82
|
-
|
99
|
+
worksheet_clear(ptr);
|
83
100
|
return self;
|
84
101
|
}
|
85
102
|
|
86
103
|
void
|
87
|
-
|
104
|
+
worksheet_clear(void *p) {
|
88
105
|
struct worksheet *ptr = p;
|
89
106
|
|
90
107
|
if (ptr->worksheet) {
|
@@ -92,6 +109,12 @@ worksheet_free(void *p) {
|
|
92
109
|
}
|
93
110
|
}
|
94
111
|
|
112
|
+
void
|
113
|
+
worksheet_free(void *p) {
|
114
|
+
worksheet_clear(p);
|
115
|
+
ruby_xfree(p);
|
116
|
+
}
|
117
|
+
|
95
118
|
/* call-seq:
|
96
119
|
* ws.write_string(cell, value, format = nil) -> self
|
97
120
|
* ws.write_string(row, col, value, format = nil) -> self
|
@@ -314,7 +337,7 @@ worksheet_write_url_(int argc, VALUE *argv, VALUE self) {
|
|
314
337
|
struct worksheet *ptr;
|
315
338
|
VALUE workbook = rb_iv_get(self, "@workbook");
|
316
339
|
lxw_format *format = workbook_get_format(workbook, format_key);
|
317
|
-
|
340
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
318
341
|
if (string || tooltip) {
|
319
342
|
worksheet_write_url_opt(ptr->worksheet, row, col, url_str, format, string, tooltip);
|
320
343
|
} else {
|
@@ -500,7 +523,7 @@ worksheet_set_row_(VALUE self, VALUE row, VALUE opts) {
|
|
500
523
|
options.level = NUM2INT(val);
|
501
524
|
|
502
525
|
struct worksheet *ptr;
|
503
|
-
|
526
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
504
527
|
if (options.hidden || options.collapsed || options.level) {
|
505
528
|
worksheet_set_row_opt(ptr->worksheet, NUM2INT(row), height, format, &options);
|
506
529
|
} else {
|
@@ -547,7 +570,7 @@ worksheet_set_column_(VALUE self, VALUE col_from, VALUE col_to, VALUE opts) {
|
|
547
570
|
options.level = NUM2INT(val);
|
548
571
|
|
549
572
|
struct worksheet *ptr;
|
550
|
-
|
573
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
551
574
|
if (options.hidden || options.collapsed || options.level) {
|
552
575
|
worksheet_set_column_opt(ptr->worksheet, col1, col2, width, format, &options);
|
553
576
|
} else {
|
@@ -589,7 +612,7 @@ worksheet_insert_image_(int argc, VALUE *argv, VALUE self) {
|
|
589
612
|
}
|
590
613
|
|
591
614
|
struct worksheet *ptr;
|
592
|
-
|
615
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
593
616
|
|
594
617
|
if (!NIL_P(opts)) {
|
595
618
|
options = val_to_lxw_image_options(opts, &with_options);
|
@@ -634,7 +657,7 @@ worksheet_insert_image_buffer_(int argc, VALUE *argv, VALUE self) {
|
|
634
657
|
++larg;
|
635
658
|
}
|
636
659
|
struct worksheet *ptr;
|
637
|
-
|
660
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
638
661
|
|
639
662
|
if (!NIL_P(opts)) {
|
640
663
|
options = val_to_lxw_image_options(opts, &with_options);
|
@@ -664,7 +687,7 @@ worksheet_insert_chart_(int argc, VALUE *argv, VALUE self) {
|
|
664
687
|
lxw_row_t row;
|
665
688
|
lxw_col_t col;
|
666
689
|
VALUE chart, opts = Qnil;
|
667
|
-
|
690
|
+
lxw_chart_options options;
|
668
691
|
char with_options = '\0';
|
669
692
|
|
670
693
|
rb_check_arity(argc, 2, 4);
|
@@ -683,13 +706,13 @@ worksheet_insert_chart_(int argc, VALUE *argv, VALUE self) {
|
|
683
706
|
}
|
684
707
|
|
685
708
|
if (!NIL_P(opts)) {
|
686
|
-
options =
|
709
|
+
options = val_to_lxw_chart_options(opts, &with_options);
|
687
710
|
}
|
688
711
|
|
689
712
|
struct worksheet *ptr;
|
690
713
|
struct chart *chart_ptr;
|
691
|
-
|
692
|
-
|
714
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
715
|
+
TypedData_Get_Struct(chart, struct chart, &chart_type, chart_ptr);
|
693
716
|
|
694
717
|
if (with_options) {
|
695
718
|
worksheet_insert_chart_opt(ptr->worksheet, row, col, chart_ptr->chart, &options);
|
@@ -820,7 +843,7 @@ worksheet_freeze_panes_(int argc, VALUE *argv, VALUE self) {
|
|
820
843
|
rb_check_arity(argc, 1, 5);
|
821
844
|
int larg = extract_cell(argc, argv, &row, &col);
|
822
845
|
struct worksheet *ptr;
|
823
|
-
|
846
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
824
847
|
if (larg >= argc) {
|
825
848
|
worksheet_freeze_panes(ptr->worksheet, row, col);
|
826
849
|
} else {
|
@@ -928,7 +951,7 @@ worksheet_set_header_(int argc, VALUE *argv, VALUE self) {
|
|
928
951
|
rb_check_arity(argc, 1, 2);
|
929
952
|
struct _header_options ho = _extract_header_options(argc, argv);
|
930
953
|
struct worksheet *ptr;
|
931
|
-
|
954
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
932
955
|
lxw_error err;
|
933
956
|
if (!ho.with_options) {
|
934
957
|
err = worksheet_set_header(ptr->worksheet, ho.str);
|
@@ -948,7 +971,7 @@ worksheet_set_footer_(int argc, VALUE *argv, VALUE self) {
|
|
948
971
|
struct worksheet *ptr;
|
949
972
|
rb_check_arity(argc, 1, 2);
|
950
973
|
struct _header_options ho = _extract_header_options(argc, argv);
|
951
|
-
|
974
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
952
975
|
lxw_error err;
|
953
976
|
if (!ho.with_options) {
|
954
977
|
err = worksheet_set_footer(ptr->worksheet, ho.str);
|
@@ -1194,7 +1217,7 @@ worksheet_set_default_row_(VALUE self, VALUE height, VALUE hide_unused_rows) {
|
|
1194
1217
|
VALUE
|
1195
1218
|
worksheet_get_horizontal_dpi_(VALUE self) {
|
1196
1219
|
struct worksheet *ptr;
|
1197
|
-
|
1220
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
1198
1221
|
return INT2NUM(ptr->worksheet->horizontal_dpi);
|
1199
1222
|
}
|
1200
1223
|
|
@@ -1205,7 +1228,7 @@ worksheet_get_horizontal_dpi_(VALUE self) {
|
|
1205
1228
|
VALUE
|
1206
1229
|
worksheet_set_horizontal_dpi_(VALUE self, VALUE val) {
|
1207
1230
|
struct worksheet *ptr;
|
1208
|
-
|
1231
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
1209
1232
|
ptr->worksheet->horizontal_dpi = NUM2INT(val);
|
1210
1233
|
return val;
|
1211
1234
|
}
|
@@ -1217,7 +1240,7 @@ worksheet_set_horizontal_dpi_(VALUE self, VALUE val) {
|
|
1217
1240
|
VALUE
|
1218
1241
|
worksheet_get_vertical_dpi_(VALUE self) {
|
1219
1242
|
struct worksheet *ptr;
|
1220
|
-
|
1243
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
1221
1244
|
return INT2NUM(ptr->worksheet->vertical_dpi);
|
1222
1245
|
}
|
1223
1246
|
|
@@ -1228,7 +1251,7 @@ worksheet_get_vertical_dpi_(VALUE self) {
|
|
1228
1251
|
VALUE
|
1229
1252
|
worksheet_set_vertical_dpi_(VALUE self, VALUE val) {
|
1230
1253
|
struct worksheet *ptr;
|
1231
|
-
|
1254
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
1232
1255
|
ptr->worksheet->vertical_dpi = NUM2INT(val);
|
1233
1256
|
return val;
|
1234
1257
|
}
|
@@ -1379,7 +1402,7 @@ worksheet_data_validation_(int argc, VALUE *argv, VALUE self) {
|
|
1379
1402
|
#undef parse_value
|
1380
1403
|
|
1381
1404
|
struct worksheet *ptr;
|
1382
|
-
|
1405
|
+
TypedData_Get_Struct(self, struct worksheet, &worksheet_type, ptr);
|
1383
1406
|
lxw_error err;
|
1384
1407
|
if (range) {
|
1385
1408
|
err = worksheet_data_validation_range(ptr->worksheet, row, col, row2, col2, &data_validation);
|
@@ -1508,6 +1531,25 @@ int extract_range(int argc, VALUE *argv, lxw_row_t *row_from, lxw_col_t *col_fro
|
|
1508
1531
|
setter; \
|
1509
1532
|
} \
|
1510
1533
|
}
|
1534
|
+
lxw_chart_options
|
1535
|
+
val_to_lxw_chart_options(VALUE opts, char *with_options) {
|
1536
|
+
VALUE val;
|
1537
|
+
lxw_chart_options options = {
|
1538
|
+
.x_offset = 0,
|
1539
|
+
.y_offset = 0,
|
1540
|
+
.x_scale = 1.0,
|
1541
|
+
.y_scale = 1.0
|
1542
|
+
};
|
1543
|
+
SET_IMG_OPT("offset", options.x_offset = options.y_offset = NUM2INT(val));
|
1544
|
+
SET_IMG_OPT("x_offset", options.x_offset = NUM2INT(val));
|
1545
|
+
SET_IMG_OPT("y_offset", options.y_offset = NUM2INT(val));
|
1546
|
+
SET_IMG_OPT("scale", options.x_scale = options.y_scale = NUM2DBL(val));
|
1547
|
+
SET_IMG_OPT("x_scale", options.x_scale = NUM2DBL(val));
|
1548
|
+
SET_IMG_OPT("y_scale", options.y_scale = NUM2DBL(val));
|
1549
|
+
SET_IMG_OPT("object_position", options.object_position = NUM2INT(val));
|
1550
|
+
return options;
|
1551
|
+
}
|
1552
|
+
|
1511
1553
|
lxw_image_options
|
1512
1554
|
val_to_lxw_image_options(VALUE opts, char *with_options) {
|
1513
1555
|
VALUE val;
|
@@ -1523,7 +1565,10 @@ val_to_lxw_image_options(VALUE opts, char *with_options) {
|
|
1523
1565
|
SET_IMG_OPT("scale", options.x_scale = options.y_scale = NUM2DBL(val));
|
1524
1566
|
SET_IMG_OPT("x_scale", options.x_scale = NUM2DBL(val));
|
1525
1567
|
SET_IMG_OPT("y_scale", options.y_scale = NUM2DBL(val));
|
1568
|
+
SET_IMG_OPT("object_position", options.object_position = NUM2INT(val));
|
1526
1569
|
SET_IMG_OPT("description", options.description = StringValueCStr(val));
|
1570
|
+
SET_IMG_OPT("url", options.url = StringValueCStr(val));
|
1571
|
+
SET_IMG_OPT("tip", options.tip = StringValueCStr(val));
|
1527
1572
|
return options;
|
1528
1573
|
}
|
1529
1574
|
#undef SET_IMG_OPT
|
@@ -1535,6 +1580,7 @@ init_xlsxwriter_worksheet() {
|
|
1535
1580
|
cWorksheet = rb_define_class_under(mXlsxWriter, "Worksheet", rb_cObject);
|
1536
1581
|
|
1537
1582
|
rb_define_alloc_func(cWorksheet, worksheet_alloc);
|
1583
|
+
rb_define_attr(cWorksheet, "workbook", 1, 0);
|
1538
1584
|
rb_define_method(cWorksheet, "initialize", worksheet_init, -1);
|
1539
1585
|
rb_define_method(cWorksheet, "free", worksheet_release, 0);
|
1540
1586
|
rb_define_method(cWorksheet, "write_string", worksheet_write_string_, -1);
|
@@ -1632,6 +1678,12 @@ init_xlsxwriter_worksheet() {
|
|
1632
1678
|
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_LESS_THAN);
|
1633
1679
|
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_GREATER_THAN_OR_EQUAL_TO);
|
1634
1680
|
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_LESS_THAN_OR_EQUAL_TO);
|
1681
|
+
|
1682
|
+
MAP_LXW_WH_CONST1(OBJECT_POSITION_DEFAULT);
|
1683
|
+
MAP_LXW_WH_CONST1(OBJECT_MOVE_AND_SIZE);
|
1684
|
+
MAP_LXW_WH_CONST1(OBJECT_MOVE_DONT_SIZE);
|
1685
|
+
MAP_LXW_WH_CONST1(OBJECT_DONT_MOVE_DONT_SIZE);
|
1686
|
+
MAP_LXW_WH_CONST1(OBJECT_MOVE_AND_SIZE_AFTER);
|
1635
1687
|
#undef MAP_LXW_WH_CONST1
|
1636
1688
|
#undef MAP_LXW_WH_CONST
|
1637
1689
|
}
|
data/ext/xlsxwriter/worksheet.h
CHANGED
@@ -12,6 +12,7 @@ lxw_col_t value_to_col(VALUE value);
|
|
12
12
|
int extract_cell(int argc, VALUE *argv, lxw_row_t *row, lxw_col_t *col);
|
13
13
|
int extract_range(int argc, VALUE *argv, lxw_row_t *row1, lxw_col_t *col1,
|
14
14
|
lxw_row_t *row2, lxw_col_t *col2);
|
15
|
+
lxw_chart_options val_to_lxw_chart_options(VALUE opts, char *with_options);
|
15
16
|
lxw_image_options val_to_lxw_image_options(VALUE opts, char *with_options);
|
16
17
|
|
17
18
|
void init_xlsxwriter_worksheet();
|
data/ext/xlsxwriter/xlsxwriter.c
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
#include "chartsheet.h"
|
5
5
|
#include "format.h"
|
6
6
|
#include "rich_string.h"
|
7
|
+
#include "shared_strings.h"
|
7
8
|
#include "workbook.h"
|
8
9
|
#include "workbook_properties.h"
|
9
10
|
#include "worksheet.h"
|
@@ -44,4 +45,5 @@ void Init_xlsxwriter() {
|
|
44
45
|
init_xlsxwriter_chart();
|
45
46
|
init_xlsxwriter_chartsheet();
|
46
47
|
init_xlsxwriter_rich_string();
|
48
|
+
init_xlsxwriter_shared_strings_table();
|
47
49
|
}
|
data/lib/xlsxwriter/version.rb
CHANGED
data/lib/xlsxwriter/worksheet.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module XlsxWriter
|
4
|
-
|
5
4
|
class Worksheet
|
6
5
|
# Last row number written with #add_row
|
7
6
|
attr_reader :current_row, :col_auto_widths
|
8
7
|
|
9
8
|
# Thiner characters list used for column width logic mimicking axlsx behaviour
|
10
|
-
THIN_CHARS = '^.acfijklrstxzFIJL()-'
|
9
|
+
THIN_CHARS = '^.acfijklrstxzFIJL()-'
|
11
10
|
|
12
11
|
# Write a +row+. If no +types+ passed XlsxWriter tries to deduce them automatically.
|
13
12
|
#
|
@@ -51,6 +50,7 @@ module XlsxWriter
|
|
51
50
|
write_blank(row_idx, idx, cell_style)
|
52
51
|
when :skip, :empty
|
53
52
|
# write nothing
|
53
|
+
nil
|
54
54
|
when nil
|
55
55
|
case value
|
56
56
|
when Numeric
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
base_dir = File.expand_path(
|
5
|
-
lib_dir = File.join(base_dir,
|
6
|
-
test_dir = File.join(base_dir,
|
4
|
+
base_dir = File.expand_path('..', __dir__)
|
5
|
+
lib_dir = File.join(base_dir, 'lib')
|
6
|
+
test_dir = File.join(base_dir, 'test')
|
7
7
|
|
8
8
|
$LOAD_PATH.unshift(lib_dir)
|
9
9
|
|
data/test/support/chart_test.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ChartTest
|
4
|
-
def chart_test(fname, type, data = self::DATA, &
|
5
|
-
test fname do |wb|
|
4
|
+
def chart_test(fname, type, data = self::DATA, ref_file_name: nil, &_block)
|
5
|
+
test fname, ref_file_name: ref_file_name do |wb|
|
6
6
|
wb.add_worksheet do |ws|
|
7
7
|
data.each { |row| ws.add_row row }
|
8
8
|
|
9
9
|
wb.add_chart(type) do |chart|
|
10
|
-
yield chart
|
10
|
+
yield chart, ws
|
11
11
|
|
12
12
|
ws.insert_chart 'E9', chart
|
13
13
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xlsxwriter'
|
2
4
|
|
3
5
|
module WithXlsxFile
|
4
|
-
def with_xlsx_file(file_path = 'tmp/test.xlsx', **opts)
|
6
|
+
def with_xlsx_file(file_path = 'tmp/test.xlsx', **opts, &block)
|
5
7
|
after = opts.delete :after
|
6
8
|
XlsxWriter::Workbook.open(file_path, opts) do |wb|
|
7
|
-
|
9
|
+
block.call(wb)
|
8
10
|
end
|
9
11
|
after.call if after
|
10
12
|
ensure
|