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,10 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
#ifndef __WORKBOOK_PROPERTIES__
|
4
|
+
#define __WORKBOOK_PROPIRTIES__
|
5
|
+
|
6
|
+
VALUE workbook_properties_init_(VALUE, VALUE);
|
7
|
+
VALUE workbook_properties_set_dir_(VALUE self, VALUE value);
|
8
|
+
VALUE workbook_properties_set_(VALUE self, VALUE key, VALUE value);
|
9
|
+
|
10
|
+
#endif // __WORKBOOK_PROPIRTIES__
|
@@ -0,0 +1,1064 @@
|
|
1
|
+
#include "chart.h"
|
2
|
+
#include "worksheet.h"
|
3
|
+
#include "workbook.h"
|
4
|
+
|
5
|
+
VALUE
|
6
|
+
worksheet_alloc(VALUE klass)
|
7
|
+
{
|
8
|
+
VALUE obj;
|
9
|
+
struct worksheet *ptr;
|
10
|
+
|
11
|
+
obj = Data_Make_Struct(klass, struct worksheet, NULL, worksheet_free, ptr);
|
12
|
+
|
13
|
+
ptr->worksheet = NULL;
|
14
|
+
|
15
|
+
return obj;
|
16
|
+
}
|
17
|
+
|
18
|
+
VALUE
|
19
|
+
worksheet_init(int argc, VALUE *argv, VALUE self) {
|
20
|
+
char *name = NULL;
|
21
|
+
VALUE opts = Qnil;
|
22
|
+
VALUE auto_width = Qtrue;
|
23
|
+
struct workbook *wb_ptr;
|
24
|
+
struct worksheet *ptr;
|
25
|
+
|
26
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
27
|
+
|
28
|
+
if (argc > 2 || argc < 1) {
|
29
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
30
|
+
} else if (argc == 2) {
|
31
|
+
switch (TYPE(argv[1])) {
|
32
|
+
case T_HASH:
|
33
|
+
opts = argv[1];
|
34
|
+
break;
|
35
|
+
case T_STRING:
|
36
|
+
case T_SYMBOL:
|
37
|
+
name = StringValueCStr(argv[1]);
|
38
|
+
break;
|
39
|
+
case T_NIL:
|
40
|
+
break;
|
41
|
+
default:
|
42
|
+
rb_raise(rb_eArgError, "wrong type of name");
|
43
|
+
break;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
if (!NIL_P(opts)) {
|
48
|
+
VALUE val = rb_hash_aref(opts, ID2SYM(rb_intern("auto_width")));
|
49
|
+
if (val == Qfalse) {
|
50
|
+
auto_width = Qfalse;
|
51
|
+
}
|
52
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("name")));
|
53
|
+
if (!NIL_P(val) && !name) {
|
54
|
+
name = StringValueCStr(val);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
rb_iv_set(self, "@workbook", argv[0]);
|
59
|
+
rb_iv_set(self, "@use_auto_width", auto_width);
|
60
|
+
rb_iv_set(self, "@col_auto_widths", rb_ary_new());
|
61
|
+
|
62
|
+
Data_Get_Struct(argv[0], struct workbook, wb_ptr);
|
63
|
+
ptr->worksheet = workbook_add_worksheet(wb_ptr->workbook, name);
|
64
|
+
return self;
|
65
|
+
}
|
66
|
+
|
67
|
+
VALUE
|
68
|
+
worksheet_release(VALUE self) {
|
69
|
+
struct worksheet *ptr;
|
70
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
71
|
+
|
72
|
+
worksheet_free(ptr);
|
73
|
+
return self;
|
74
|
+
}
|
75
|
+
|
76
|
+
void
|
77
|
+
worksheet_free(void *p) {
|
78
|
+
struct worksheet *ptr = p;
|
79
|
+
|
80
|
+
if (ptr->worksheet) {
|
81
|
+
ptr->worksheet = NULL;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE
|
86
|
+
worksheet_write_string_(int argc, VALUE *argv, VALUE self) {
|
87
|
+
lxw_row_t row;
|
88
|
+
lxw_col_t col;
|
89
|
+
VALUE value = Qnil;
|
90
|
+
VALUE format_key = Qnil;
|
91
|
+
|
92
|
+
rb_check_arity(argc, 2, 4);
|
93
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
94
|
+
|
95
|
+
if (larg < argc) {
|
96
|
+
value = argv[larg];
|
97
|
+
++larg;
|
98
|
+
}
|
99
|
+
|
100
|
+
if (larg < argc) {
|
101
|
+
format_key = argv[larg];
|
102
|
+
++larg;
|
103
|
+
}
|
104
|
+
|
105
|
+
const char *str = StringValueCStr(value);
|
106
|
+
struct worksheet *ptr;
|
107
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
108
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
109
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
110
|
+
worksheet_write_string(ptr->worksheet, row, col, str, format);
|
111
|
+
return self;
|
112
|
+
}
|
113
|
+
|
114
|
+
VALUE
|
115
|
+
worksheet_write_number_(int argc, VALUE *argv, VALUE self) {
|
116
|
+
lxw_row_t row;
|
117
|
+
lxw_col_t col;
|
118
|
+
VALUE value = Qnil;
|
119
|
+
VALUE format_key = Qnil;
|
120
|
+
|
121
|
+
rb_check_arity(argc, 2, 4);
|
122
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
123
|
+
|
124
|
+
if (larg < argc) {
|
125
|
+
value = argv[larg];
|
126
|
+
++larg;
|
127
|
+
}
|
128
|
+
|
129
|
+
if (larg < argc) {
|
130
|
+
format_key = argv[larg];
|
131
|
+
++larg;
|
132
|
+
}
|
133
|
+
|
134
|
+
const double num = NUM2DBL(value);
|
135
|
+
struct worksheet *ptr;
|
136
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
137
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
138
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
139
|
+
worksheet_write_number(ptr->worksheet, row, col, num, format);
|
140
|
+
return self;
|
141
|
+
}
|
142
|
+
|
143
|
+
VALUE
|
144
|
+
worksheet_write_formula_(int argc, VALUE *argv, VALUE self) {
|
145
|
+
lxw_row_t row;
|
146
|
+
lxw_col_t col;
|
147
|
+
VALUE value = Qnil;
|
148
|
+
VALUE format_key = Qnil;
|
149
|
+
|
150
|
+
rb_check_arity(argc, 2, 4);
|
151
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
152
|
+
|
153
|
+
if (larg < argc) {
|
154
|
+
value = argv[larg];
|
155
|
+
++larg;
|
156
|
+
}
|
157
|
+
|
158
|
+
if (larg < argc) {
|
159
|
+
format_key = argv[larg];
|
160
|
+
++larg;
|
161
|
+
}
|
162
|
+
|
163
|
+
const char *str = RSTRING_PTR(value);
|
164
|
+
struct worksheet *ptr;
|
165
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
166
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
167
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
168
|
+
worksheet_write_formula(ptr->worksheet, row, col, str, format);
|
169
|
+
return self;
|
170
|
+
}
|
171
|
+
|
172
|
+
VALUE worksheet_write_array_formula_(int argc, VALUE *argv, VALUE self) {
|
173
|
+
lxw_row_t row_from, row_to;
|
174
|
+
lxw_col_t col_from, col_to;
|
175
|
+
const char *str;
|
176
|
+
VALUE format_key = Qnil;
|
177
|
+
|
178
|
+
rb_check_arity(argc, 2, 6);
|
179
|
+
int larg = extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
|
180
|
+
|
181
|
+
if (larg < argc) {
|
182
|
+
str = StringValueCStr(argv[larg]);
|
183
|
+
++larg;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (larg < argc) {
|
187
|
+
format_key = argv[larg];
|
188
|
+
++larg;
|
189
|
+
}
|
190
|
+
|
191
|
+
struct worksheet *ptr;
|
192
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
193
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
194
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
195
|
+
worksheet_write_array_formula(ptr->worksheet, row_from, col_from, row_to, col_to, str, format);
|
196
|
+
return self;
|
197
|
+
}
|
198
|
+
|
199
|
+
VALUE
|
200
|
+
worksheet_write_datetime_(int argc, VALUE *argv, VALUE self) {
|
201
|
+
lxw_row_t row;
|
202
|
+
lxw_col_t col;
|
203
|
+
VALUE value = Qnil;
|
204
|
+
VALUE format_key = Qnil;
|
205
|
+
|
206
|
+
rb_check_arity(argc, 2, 4);
|
207
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
208
|
+
|
209
|
+
if (larg < argc) {
|
210
|
+
value = argv[larg];
|
211
|
+
++larg;
|
212
|
+
}
|
213
|
+
|
214
|
+
if (larg < argc) {
|
215
|
+
format_key = argv[larg];
|
216
|
+
++larg;
|
217
|
+
}
|
218
|
+
|
219
|
+
struct lxw_datetime datetime = value_to_lxw_datetime(value);
|
220
|
+
struct worksheet *ptr;
|
221
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
222
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
223
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
224
|
+
worksheet_write_datetime(ptr->worksheet, row, col, &datetime, format);
|
225
|
+
return self;
|
226
|
+
}
|
227
|
+
|
228
|
+
VALUE
|
229
|
+
worksheet_write_url_(int argc, VALUE *argv, VALUE self) {
|
230
|
+
lxw_row_t row;
|
231
|
+
lxw_col_t col;
|
232
|
+
VALUE url = Qnil; //argv[2];
|
233
|
+
VALUE format_key = Qnil; // argv[3];
|
234
|
+
VALUE opts = Qnil;
|
235
|
+
|
236
|
+
rb_check_arity(argc, 2, 5);
|
237
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
238
|
+
|
239
|
+
if (larg < argc) {
|
240
|
+
url = argv[larg];
|
241
|
+
++larg;
|
242
|
+
}
|
243
|
+
|
244
|
+
const char *url_str = RSTRING_PTR(url);
|
245
|
+
char *string = NULL;
|
246
|
+
char *tooltip = NULL;
|
247
|
+
while (larg < argc) {
|
248
|
+
switch(TYPE(argv[larg])) {
|
249
|
+
case T_HASH:
|
250
|
+
opts = argv[larg];
|
251
|
+
break;
|
252
|
+
case T_SYMBOL: case T_STRING: case T_NIL:
|
253
|
+
format_key = argv[larg];
|
254
|
+
break;
|
255
|
+
default:
|
256
|
+
rb_raise(rb_eTypeError, "Expected Hash, symbol or string but got %"PRIsVALUE, rb_obj_class(argv[larg]));
|
257
|
+
}
|
258
|
+
++larg;
|
259
|
+
}
|
260
|
+
|
261
|
+
if (!NIL_P(opts)) {
|
262
|
+
VALUE val;
|
263
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("string")));
|
264
|
+
if (!NIL_P(val)) {
|
265
|
+
string = StringValueCStr(val);
|
266
|
+
}
|
267
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("tooltip")));
|
268
|
+
if (!NIL_P(val)) {
|
269
|
+
tooltip = StringValueCStr(val);
|
270
|
+
}
|
271
|
+
if (NIL_P(format_key)) {
|
272
|
+
format_key = rb_hash_aref(opts, ID2SYM(rb_intern("format")));
|
273
|
+
}
|
274
|
+
}
|
275
|
+
struct worksheet *ptr;
|
276
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
277
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
278
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
279
|
+
if (string || tooltip) {
|
280
|
+
worksheet_write_url_opt(ptr->worksheet, row, col, url_str, format, string, tooltip);
|
281
|
+
} else {
|
282
|
+
worksheet_write_url(ptr->worksheet, row, col, url_str, format);
|
283
|
+
}
|
284
|
+
return self;
|
285
|
+
}
|
286
|
+
|
287
|
+
VALUE
|
288
|
+
worksheet_write_boolean_(int argc, VALUE *argv, VALUE self) {
|
289
|
+
lxw_row_t row;
|
290
|
+
lxw_col_t col;
|
291
|
+
int bool_value = 0;
|
292
|
+
VALUE format_key = Qnil;
|
293
|
+
|
294
|
+
rb_check_arity(argc, 2, 4);
|
295
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
296
|
+
|
297
|
+
if (larg < argc) {
|
298
|
+
bool_value = argv[larg] && !NIL_P(argv[larg]);
|
299
|
+
++larg;
|
300
|
+
}
|
301
|
+
|
302
|
+
if (larg < argc) {
|
303
|
+
format_key = argv[larg];
|
304
|
+
++larg;
|
305
|
+
}
|
306
|
+
|
307
|
+
struct worksheet *ptr;
|
308
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
309
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
310
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
311
|
+
worksheet_write_boolean(ptr->worksheet, row, col, bool_value, format);
|
312
|
+
return self;
|
313
|
+
}
|
314
|
+
|
315
|
+
VALUE
|
316
|
+
worksheet_write_blank_(int argc, VALUE *argv, VALUE self) {
|
317
|
+
lxw_row_t row;
|
318
|
+
lxw_col_t col;
|
319
|
+
VALUE format_key = Qnil;
|
320
|
+
|
321
|
+
rb_check_arity(argc, 1, 3);
|
322
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
323
|
+
|
324
|
+
if (larg < argc) {
|
325
|
+
format_key = argv[larg];
|
326
|
+
++larg;
|
327
|
+
}
|
328
|
+
|
329
|
+
struct worksheet *ptr;
|
330
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
331
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
332
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
333
|
+
worksheet_write_blank(ptr->worksheet, row, col, format);
|
334
|
+
return self;
|
335
|
+
}
|
336
|
+
|
337
|
+
VALUE worksheet_write_formula_num_(int argc, VALUE *argv, VALUE self) {
|
338
|
+
lxw_row_t row;
|
339
|
+
lxw_col_t col;
|
340
|
+
VALUE formula = Qnil;
|
341
|
+
VALUE value = Qnil;
|
342
|
+
VALUE format_key = Qnil;
|
343
|
+
|
344
|
+
rb_check_arity(argc, 3, 5);
|
345
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
346
|
+
|
347
|
+
if (larg < argc) {
|
348
|
+
formula = argv[larg];
|
349
|
+
++larg;
|
350
|
+
}
|
351
|
+
|
352
|
+
if (larg + 1 < argc) {
|
353
|
+
format_key = argv[larg];
|
354
|
+
++larg;
|
355
|
+
}
|
356
|
+
|
357
|
+
if (larg < argc) {
|
358
|
+
value = argv[larg];
|
359
|
+
++larg;
|
360
|
+
}
|
361
|
+
|
362
|
+
const char *str = RSTRING_PTR(formula);
|
363
|
+
struct worksheet *ptr;
|
364
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
365
|
+
lxw_format *format = workbook_get_format(workbook, format_key);
|
366
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
367
|
+
worksheet_write_formula_num(ptr->worksheet, row, col, str, format, NUM2DBL(value));
|
368
|
+
return self;
|
369
|
+
}
|
370
|
+
|
371
|
+
VALUE
|
372
|
+
worksheet_set_row_(VALUE self, VALUE row, VALUE opts) {
|
373
|
+
double height = LXW_DEF_ROW_HEIGHT;
|
374
|
+
lxw_format *format = NULL;
|
375
|
+
lxw_row_col_options options = {
|
376
|
+
.hidden = 0,
|
377
|
+
.collapsed = 0,
|
378
|
+
.level = 0
|
379
|
+
};
|
380
|
+
VALUE val;
|
381
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
382
|
+
|
383
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("height")));
|
384
|
+
if (val != Qnil)
|
385
|
+
height = NUM2DBL(val);
|
386
|
+
|
387
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("format")));
|
388
|
+
format = workbook_get_format(workbook, val);
|
389
|
+
|
390
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("hide")));
|
391
|
+
if (val != Qnil && val)
|
392
|
+
options.hidden = 1;
|
393
|
+
|
394
|
+
struct worksheet *ptr;
|
395
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
396
|
+
if (options.hidden) {
|
397
|
+
worksheet_set_row_opt(ptr->worksheet, NUM2INT(row), height, format, &options);
|
398
|
+
} else {
|
399
|
+
worksheet_set_row(ptr->worksheet, NUM2INT(row), height, format);
|
400
|
+
}
|
401
|
+
return self;
|
402
|
+
}
|
403
|
+
|
404
|
+
VALUE
|
405
|
+
worksheet_set_column_(VALUE self, VALUE col_from, VALUE col_to, VALUE opts) {
|
406
|
+
double width = LXW_DEF_COL_WIDTH;
|
407
|
+
lxw_format *format = NULL;
|
408
|
+
lxw_row_col_options options = {
|
409
|
+
.hidden = 0,
|
410
|
+
.collapsed = 0,
|
411
|
+
.level = 0
|
412
|
+
};
|
413
|
+
VALUE val;
|
414
|
+
lxw_col_t col1 = value_to_col(col_from);
|
415
|
+
lxw_col_t col2 = value_to_col(col_to);
|
416
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
417
|
+
|
418
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("width")));
|
419
|
+
if (val != Qnil)
|
420
|
+
width = NUM2DBL(val);
|
421
|
+
|
422
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("format")));
|
423
|
+
format = workbook_get_format(workbook, val);
|
424
|
+
|
425
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("hide")));
|
426
|
+
if (val != Qnil && val)
|
427
|
+
options.hidden = 1;
|
428
|
+
|
429
|
+
struct worksheet *ptr;
|
430
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
431
|
+
if (options.hidden) {
|
432
|
+
worksheet_set_column_opt(ptr->worksheet, col1, col2, width, format, &options);
|
433
|
+
} else {
|
434
|
+
worksheet_set_column(ptr->worksheet, col1, col2, width, format);
|
435
|
+
}
|
436
|
+
return self;
|
437
|
+
}
|
438
|
+
|
439
|
+
#define SET_IMG_OPT(key, setter) { \
|
440
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern(key))); \
|
441
|
+
if (!NIL_P(val)) { \
|
442
|
+
with_options = '\1'; \
|
443
|
+
setter; \
|
444
|
+
} \
|
445
|
+
}
|
446
|
+
|
447
|
+
VALUE
|
448
|
+
worksheet_insert_image_(int argc, VALUE *argv, VALUE self) {
|
449
|
+
lxw_row_t row;
|
450
|
+
lxw_col_t col;
|
451
|
+
VALUE fname = Qnil;
|
452
|
+
VALUE opts = Qnil;
|
453
|
+
VALUE val = Qnil;
|
454
|
+
lxw_image_options options = {
|
455
|
+
.x_offset = 0,
|
456
|
+
.y_offset = 0,
|
457
|
+
.x_scale = 1.0,
|
458
|
+
.y_scale = 1.0
|
459
|
+
};
|
460
|
+
char with_options = '\0';
|
461
|
+
|
462
|
+
rb_check_arity(argc, 2, 4);
|
463
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
464
|
+
|
465
|
+
if (larg < argc) {
|
466
|
+
fname = argv[larg];
|
467
|
+
++larg;
|
468
|
+
}
|
469
|
+
|
470
|
+
if (larg < argc) {
|
471
|
+
opts = argv[larg];
|
472
|
+
++larg;
|
473
|
+
}
|
474
|
+
|
475
|
+
struct worksheet *ptr;
|
476
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
477
|
+
|
478
|
+
if (!NIL_P(opts)) {
|
479
|
+
SET_IMG_OPT("offset", options.x_offset = options.y_offset = NUM2INT(val));
|
480
|
+
SET_IMG_OPT("x_offset", options.x_offset = NUM2INT(val));
|
481
|
+
SET_IMG_OPT("y_offset", options.y_offset = NUM2INT(val));
|
482
|
+
SET_IMG_OPT("scale", options.x_scale = options.y_scale = NUM2DBL(val));
|
483
|
+
SET_IMG_OPT("x_scale", options.x_scale = NUM2DBL(val));
|
484
|
+
SET_IMG_OPT("y_scale", options.y_scale = NUM2DBL(val));
|
485
|
+
}
|
486
|
+
|
487
|
+
if (with_options) {
|
488
|
+
worksheet_insert_image_opt(ptr->worksheet, row, col, StringValueCStr(fname), &options);
|
489
|
+
} else {
|
490
|
+
worksheet_insert_image(ptr->worksheet, row, col, StringValueCStr(fname));
|
491
|
+
}
|
492
|
+
|
493
|
+
return self;
|
494
|
+
}
|
495
|
+
|
496
|
+
#undef SET_IMG_OPT
|
497
|
+
|
498
|
+
VALUE
|
499
|
+
worksheet_insert_chart_(int argc, VALUE *argv, VALUE self) {
|
500
|
+
lxw_row_t row;
|
501
|
+
lxw_col_t col;
|
502
|
+
VALUE chart;
|
503
|
+
|
504
|
+
rb_check_arity(argc, 2, 3);
|
505
|
+
int larg = extract_cell(argc, argv, &row, &col);
|
506
|
+
|
507
|
+
if (larg < argc) {
|
508
|
+
chart = argv[larg];
|
509
|
+
++larg;
|
510
|
+
} else {
|
511
|
+
rb_raise(rb_eArgError, "No chart specified");
|
512
|
+
}
|
513
|
+
|
514
|
+
struct worksheet *ptr;
|
515
|
+
struct chart *chart_ptr;
|
516
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
517
|
+
Data_Get_Struct(chart, struct chart, chart_ptr);
|
518
|
+
|
519
|
+
worksheet_insert_chart(ptr->worksheet, row, col, chart_ptr->chart);
|
520
|
+
|
521
|
+
return self;
|
522
|
+
}
|
523
|
+
|
524
|
+
#undef SET_IMG_OPT
|
525
|
+
|
526
|
+
VALUE
|
527
|
+
worksheet_merge_range_(int argc, VALUE *argv, VALUE self) {
|
528
|
+
char *str;
|
529
|
+
lxw_format *format = NULL;
|
530
|
+
lxw_col_t col1, col2;
|
531
|
+
lxw_row_t row1, row2;
|
532
|
+
VALUE workbook = rb_iv_get(self, "@workbook");
|
533
|
+
|
534
|
+
rb_check_arity(argc, 2, 6);
|
535
|
+
int larg = extract_range(argc, argv, &row1, &col1, &row2, &col2);
|
536
|
+
|
537
|
+
if (larg < argc) {
|
538
|
+
str = StringValueCStr(argv[larg]);
|
539
|
+
++larg;
|
540
|
+
}
|
541
|
+
|
542
|
+
if (larg < argc) {
|
543
|
+
format = workbook_get_format(workbook, argv[larg]);
|
544
|
+
++larg;
|
545
|
+
}
|
546
|
+
|
547
|
+
struct worksheet *ptr;
|
548
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
549
|
+
|
550
|
+
worksheet_merge_range(ptr->worksheet, row1, col1, row2, col2, str, format);
|
551
|
+
return self;
|
552
|
+
}
|
553
|
+
|
554
|
+
VALUE
|
555
|
+
worksheet_autofilter_(int argc, VALUE *argv, VALUE self) {
|
556
|
+
lxw_row_t row_from, row_to;
|
557
|
+
lxw_col_t col_from, col_to;
|
558
|
+
|
559
|
+
rb_check_arity(argc, 1, 4);
|
560
|
+
extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
|
561
|
+
|
562
|
+
struct worksheet *ptr;
|
563
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
564
|
+
|
565
|
+
worksheet_autofilter(ptr->worksheet, row_from, col_from, row_to, col_to);
|
566
|
+
return self;
|
567
|
+
}
|
568
|
+
VALUE worksheet_activate_(VALUE self) {
|
569
|
+
struct worksheet *ptr;
|
570
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
571
|
+
worksheet_activate(ptr->worksheet);
|
572
|
+
return self;
|
573
|
+
}
|
574
|
+
VALUE worksheet_select_(VALUE self) {
|
575
|
+
struct worksheet *ptr;
|
576
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
577
|
+
worksheet_select(ptr->worksheet);
|
578
|
+
return self;
|
579
|
+
}
|
580
|
+
|
581
|
+
VALUE
|
582
|
+
worksheet_hide_(VALUE self) {
|
583
|
+
struct worksheet *ptr;
|
584
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
585
|
+
worksheet_hide(ptr->worksheet);
|
586
|
+
return self;
|
587
|
+
}
|
588
|
+
|
589
|
+
VALUE
|
590
|
+
worksheet_set_first_sheet_(VALUE self) {
|
591
|
+
struct worksheet *ptr;
|
592
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
593
|
+
worksheet_set_first_sheet(ptr->worksheet);
|
594
|
+
return self;
|
595
|
+
}
|
596
|
+
VALUE
|
597
|
+
worksheet_freeze_panes_(int argc, VALUE *argv, VALUE self) {
|
598
|
+
rb_check_arity(argc, 2, 5);
|
599
|
+
VALUE row = argv[0];
|
600
|
+
VALUE col = argv[1];
|
601
|
+
struct worksheet *ptr;
|
602
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
603
|
+
if (argc == 2) {
|
604
|
+
worksheet_freeze_panes(ptr->worksheet, NUM2INT(row), value_to_col(col));
|
605
|
+
} else {
|
606
|
+
VALUE row2 = row;
|
607
|
+
VALUE col2 = col;
|
608
|
+
uint8_t type = 0;
|
609
|
+
if (argc > 2)
|
610
|
+
row2 = argv[2];
|
611
|
+
if (argc > 3)
|
612
|
+
col2 = argv[3];
|
613
|
+
if (argc > 4)
|
614
|
+
type = NUM2INT(argv[4]);
|
615
|
+
worksheet_freeze_panes_opt(ptr->worksheet, NUM2INT(row), value_to_col(col),
|
616
|
+
NUM2INT(row2), value_to_col(col2), type);
|
617
|
+
}
|
618
|
+
return self;
|
619
|
+
}
|
620
|
+
|
621
|
+
VALUE
|
622
|
+
worksheet_split_panes_(VALUE self, VALUE vertical, VALUE horizontal) {
|
623
|
+
struct worksheet *ptr;
|
624
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
625
|
+
worksheet_split_panes(ptr->worksheet, NUM2DBL(vertical), NUM2DBL(horizontal));
|
626
|
+
return self;
|
627
|
+
}
|
628
|
+
|
629
|
+
VALUE
|
630
|
+
worksheet_set_selection_(int argc, VALUE *argv, VALUE self) {
|
631
|
+
lxw_row_t row_from, row_to;
|
632
|
+
lxw_col_t col_from, col_to;
|
633
|
+
|
634
|
+
rb_check_arity(argc, 1, 4);
|
635
|
+
extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
|
636
|
+
|
637
|
+
struct worksheet *ptr;
|
638
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
639
|
+
|
640
|
+
worksheet_set_selection(ptr->worksheet, row_from, col_from, row_to, col_to);
|
641
|
+
return self;
|
642
|
+
}
|
643
|
+
|
644
|
+
VALUE
|
645
|
+
worksheet_set_landscape_(VALUE self) {
|
646
|
+
struct worksheet *ptr;
|
647
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
648
|
+
worksheet_set_landscape(ptr->worksheet);
|
649
|
+
return self;
|
650
|
+
}
|
651
|
+
|
652
|
+
VALUE
|
653
|
+
worksheet_set_portrait_(VALUE self) {
|
654
|
+
struct worksheet *ptr;
|
655
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
656
|
+
worksheet_set_portrait(ptr->worksheet);
|
657
|
+
return self;
|
658
|
+
}
|
659
|
+
|
660
|
+
VALUE
|
661
|
+
worksheet_set_page_view_(VALUE self) {
|
662
|
+
struct worksheet *ptr;
|
663
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
664
|
+
worksheet_set_page_view(ptr->worksheet);
|
665
|
+
return self;
|
666
|
+
}
|
667
|
+
|
668
|
+
VALUE
|
669
|
+
worksheet_set_paper_(VALUE self, VALUE paper_type) {
|
670
|
+
struct worksheet *ptr;
|
671
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
672
|
+
worksheet_set_paper(ptr->worksheet, NUM2INT(paper_type));
|
673
|
+
return self;
|
674
|
+
}
|
675
|
+
|
676
|
+
VALUE
|
677
|
+
worksheet_set_margins_(VALUE self, VALUE left, VALUE right, VALUE top, VALUE bottom) {
|
678
|
+
struct worksheet *ptr;
|
679
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
680
|
+
worksheet_set_margins(ptr->worksheet, NUM2DBL(left), NUM2DBL(right), NUM2DBL(top), NUM2DBL(bottom));
|
681
|
+
return self;
|
682
|
+
}
|
683
|
+
|
684
|
+
VALUE
|
685
|
+
worksheet_set_header_(VALUE self, VALUE val, VALUE opts) {
|
686
|
+
const char *str = StringValueCStr(val);
|
687
|
+
lxw_header_footer_options options = { .margin = 0.0 };
|
688
|
+
char with_options = '\0';
|
689
|
+
if (!NIL_P(opts)) {
|
690
|
+
VALUE margin = rb_hash_aref(opts, ID2SYM(rb_intern("margin")));
|
691
|
+
if (!NIL_P(margin)) {
|
692
|
+
with_options = '\1';
|
693
|
+
options.margin = NUM2DBL(margin);
|
694
|
+
}
|
695
|
+
}
|
696
|
+
struct worksheet *ptr;
|
697
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
698
|
+
if (with_options) {
|
699
|
+
worksheet_set_header(ptr->worksheet, str);
|
700
|
+
} else {
|
701
|
+
worksheet_set_header_opt(ptr->worksheet, str, &options);
|
702
|
+
}
|
703
|
+
return self;
|
704
|
+
}
|
705
|
+
|
706
|
+
VALUE
|
707
|
+
worksheet_set_footer_(VALUE self, VALUE val, VALUE opts) {
|
708
|
+
const char *str = StringValueCStr(val);
|
709
|
+
lxw_header_footer_options options = { .margin = 0.0 };
|
710
|
+
char with_options = '\0';
|
711
|
+
if (!NIL_P(opts)) {
|
712
|
+
VALUE margin = rb_hash_aref(opts, ID2SYM(rb_intern("margin")));
|
713
|
+
if (!NIL_P(margin)) {
|
714
|
+
with_options = '\1';
|
715
|
+
options.margin = NUM2DBL(margin);
|
716
|
+
}
|
717
|
+
}
|
718
|
+
struct worksheet *ptr;
|
719
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
720
|
+
if (with_options) {
|
721
|
+
worksheet_set_footer(ptr->worksheet, str);
|
722
|
+
} else {
|
723
|
+
worksheet_set_footer_opt(ptr->worksheet, str, &options);
|
724
|
+
}
|
725
|
+
return self;
|
726
|
+
}
|
727
|
+
|
728
|
+
VALUE
|
729
|
+
worksheet_set_h_pagebreaks_(VALUE self, VALUE val) {
|
730
|
+
const size_t len = RARRAY_LEN(val);
|
731
|
+
lxw_row_t rows[len+1];
|
732
|
+
for (size_t i = 0; i<len; ++i) {
|
733
|
+
rows[i] = NUM2INT(rb_ary_entry(val, i));
|
734
|
+
}
|
735
|
+
rows[len] = 0;
|
736
|
+
struct worksheet *ptr;
|
737
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
738
|
+
worksheet_set_h_pagebreaks(ptr->worksheet, rows);
|
739
|
+
return val;
|
740
|
+
}
|
741
|
+
|
742
|
+
VALUE
|
743
|
+
worksheet_set_v_pagebreaks_(VALUE self, VALUE val) {
|
744
|
+
const size_t len = RARRAY_LEN(val);
|
745
|
+
lxw_col_t cols[len+1];
|
746
|
+
for (size_t i = 0; i<len; ++i) {
|
747
|
+
cols[i] = value_to_col(rb_ary_entry(val, i));
|
748
|
+
}
|
749
|
+
cols[len] = 0;
|
750
|
+
struct worksheet *ptr;
|
751
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
752
|
+
worksheet_set_v_pagebreaks(ptr->worksheet, cols);
|
753
|
+
return val;
|
754
|
+
}
|
755
|
+
|
756
|
+
VALUE
|
757
|
+
worksheet_print_across_(VALUE self) {
|
758
|
+
struct worksheet *ptr;
|
759
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
760
|
+
worksheet_print_across(ptr->worksheet);
|
761
|
+
return self;
|
762
|
+
}
|
763
|
+
|
764
|
+
VALUE
|
765
|
+
worksheet_set_zoom_(VALUE self, VALUE val) {
|
766
|
+
struct worksheet *ptr;
|
767
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
768
|
+
worksheet_set_zoom(ptr->worksheet, NUM2INT(val));
|
769
|
+
return self;
|
770
|
+
}
|
771
|
+
|
772
|
+
VALUE
|
773
|
+
worksheet_gridlines_(VALUE self, VALUE value) {
|
774
|
+
struct worksheet *ptr;
|
775
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
776
|
+
|
777
|
+
worksheet_gridlines(ptr->worksheet, NUM2INT(value));
|
778
|
+
|
779
|
+
return value;
|
780
|
+
}
|
781
|
+
|
782
|
+
VALUE
|
783
|
+
worksheet_center_horizontally_(VALUE self){
|
784
|
+
struct worksheet *ptr;
|
785
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
786
|
+
worksheet_center_horizontally(ptr->worksheet);
|
787
|
+
return self;
|
788
|
+
}
|
789
|
+
|
790
|
+
VALUE
|
791
|
+
worksheet_center_vertically_(VALUE self) {
|
792
|
+
struct worksheet *ptr;
|
793
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
794
|
+
worksheet_center_vertically(ptr->worksheet);
|
795
|
+
return self;
|
796
|
+
}
|
797
|
+
|
798
|
+
VALUE
|
799
|
+
worksheet_print_row_col_headers_(VALUE self) {
|
800
|
+
struct worksheet *ptr;
|
801
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
802
|
+
worksheet_print_row_col_headers(ptr->worksheet);
|
803
|
+
return self;
|
804
|
+
}
|
805
|
+
|
806
|
+
VALUE
|
807
|
+
worksheet_repeat_rows_(VALUE self, VALUE row_from, VALUE row_to) {
|
808
|
+
struct worksheet *ptr;
|
809
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
810
|
+
worksheet_repeat_rows(ptr->worksheet, NUM2INT(row_from), NUM2INT(row_to));
|
811
|
+
return self;
|
812
|
+
}
|
813
|
+
|
814
|
+
VALUE
|
815
|
+
worksheet_repeat_columns_(VALUE self, VALUE col_from, VALUE col_to) {
|
816
|
+
struct worksheet *ptr;
|
817
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
818
|
+
worksheet_repeat_columns(ptr->worksheet, value_to_col(col_from), value_to_col(col_to));
|
819
|
+
return self;
|
820
|
+
}
|
821
|
+
|
822
|
+
VALUE
|
823
|
+
worksheet_print_area_(int argc, VALUE *argv, VALUE self) {
|
824
|
+
lxw_row_t row_from, row_to;
|
825
|
+
lxw_col_t col_from, col_to;
|
826
|
+
|
827
|
+
rb_check_arity(argc, 1, 4);
|
828
|
+
extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
|
829
|
+
|
830
|
+
struct worksheet *ptr;
|
831
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
832
|
+
|
833
|
+
worksheet_print_area(ptr->worksheet, row_from, col_from, row_to, col_to);
|
834
|
+
return self;
|
835
|
+
}
|
836
|
+
|
837
|
+
VALUE
|
838
|
+
worksheet_fit_to_pages_(VALUE self, VALUE width, VALUE height) {
|
839
|
+
struct worksheet *ptr;
|
840
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
841
|
+
worksheet_fit_to_pages(ptr->worksheet, NUM2INT(width), NUM2INT(height));
|
842
|
+
return self;
|
843
|
+
}
|
844
|
+
|
845
|
+
VALUE
|
846
|
+
worksheet_set_start_page_(VALUE self, VALUE start_page) {
|
847
|
+
struct worksheet *ptr;
|
848
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
849
|
+
worksheet_set_start_page(ptr->worksheet, NUM2INT(start_page));
|
850
|
+
return start_page;
|
851
|
+
}
|
852
|
+
|
853
|
+
VALUE
|
854
|
+
worksheet_set_print_scale_(VALUE self, VALUE scale) {
|
855
|
+
struct worksheet *ptr;
|
856
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
857
|
+
worksheet_set_print_scale(ptr->worksheet, NUM2INT(scale));
|
858
|
+
return scale;
|
859
|
+
}
|
860
|
+
|
861
|
+
VALUE
|
862
|
+
worksheet_right_to_left_(VALUE self) {
|
863
|
+
struct worksheet *ptr;
|
864
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
865
|
+
worksheet_right_to_left(ptr->worksheet);
|
866
|
+
return self;
|
867
|
+
}
|
868
|
+
|
869
|
+
VALUE
|
870
|
+
worksheet_hide_zero_(VALUE self) {
|
871
|
+
struct worksheet *ptr;
|
872
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
873
|
+
worksheet_hide_zero(ptr->worksheet);
|
874
|
+
return self;
|
875
|
+
}
|
876
|
+
|
877
|
+
VALUE
|
878
|
+
worksheet_set_tab_color_(VALUE self, VALUE color) {
|
879
|
+
struct worksheet *ptr;
|
880
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
881
|
+
worksheet_set_tab_color(ptr->worksheet, NUM2INT(color));
|
882
|
+
return color;
|
883
|
+
}
|
884
|
+
|
885
|
+
VALUE
|
886
|
+
worksheet_protect_(int argc, VALUE *argv, VALUE self) {
|
887
|
+
rb_check_arity(argc, 0, 2);
|
888
|
+
uint8_t with_options = '\0';
|
889
|
+
VALUE val;
|
890
|
+
VALUE opts = Qnil;
|
891
|
+
lxw_protection options;
|
892
|
+
const char *password = NULL;
|
893
|
+
if (argc > 0 && !NIL_P(argv[0])) {
|
894
|
+
switch (TYPE(argv[0])) {
|
895
|
+
case T_STRING:
|
896
|
+
password = StringValueCStr(argv[0]);
|
897
|
+
break;
|
898
|
+
case T_HASH:
|
899
|
+
opts = argv[0];
|
900
|
+
break;
|
901
|
+
default:
|
902
|
+
rb_raise(rb_eArgError, "Wrong argument %"PRIsVALUE", expected a String or Hash", rb_obj_class(argv[0]));
|
903
|
+
}
|
904
|
+
}
|
905
|
+
|
906
|
+
if (argc > 1) {
|
907
|
+
if (TYPE(argv[1]) == T_HASH) {
|
908
|
+
opts = argv[1];
|
909
|
+
} else {
|
910
|
+
rb_raise(rb_eArgError, "Expected a Hash, but got %"PRIsVALUE, rb_obj_class(argv[1]));
|
911
|
+
}
|
912
|
+
}
|
913
|
+
|
914
|
+
// All options are off by default
|
915
|
+
memset(&options, 0, sizeof options);
|
916
|
+
|
917
|
+
if (!NIL_P(opts)) {
|
918
|
+
#define PR_OPT(field) { \
|
919
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern(#field))); \
|
920
|
+
if (!NIL_P(val) && val) { \
|
921
|
+
options.field = 1; \
|
922
|
+
with_options = 1; \
|
923
|
+
} \
|
924
|
+
}
|
925
|
+
PR_OPT(no_select_locked_cells);
|
926
|
+
PR_OPT(no_select_unlocked_cells);
|
927
|
+
PR_OPT(format_cells);
|
928
|
+
PR_OPT(format_columns);
|
929
|
+
PR_OPT(format_rows);
|
930
|
+
PR_OPT(insert_columns);
|
931
|
+
PR_OPT(insert_rows);
|
932
|
+
PR_OPT(insert_hyperlinks);
|
933
|
+
PR_OPT(delete_columns);
|
934
|
+
PR_OPT(delete_rows);
|
935
|
+
PR_OPT(sort);
|
936
|
+
PR_OPT(autofilter);
|
937
|
+
PR_OPT(pivot_tables);
|
938
|
+
PR_OPT(scenarios);
|
939
|
+
PR_OPT(objects);
|
940
|
+
#undef PR_OPT
|
941
|
+
}
|
942
|
+
struct worksheet *ptr;
|
943
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
944
|
+
if (with_options) {
|
945
|
+
worksheet_protect(ptr->worksheet, password, &options);
|
946
|
+
} else {
|
947
|
+
worksheet_protect(ptr->worksheet, password, NULL);
|
948
|
+
}
|
949
|
+
return self;
|
950
|
+
}
|
951
|
+
|
952
|
+
VALUE
|
953
|
+
worksheet_set_default_row_(VALUE self, VALUE height, VALUE hide_unused_rows) {
|
954
|
+
struct worksheet *ptr;
|
955
|
+
uint8_t hide_ur = !NIL_P(hide_unused_rows) && hide_unused_rows != Qfalse ? 1 : 0;
|
956
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
957
|
+
worksheet_set_default_row(ptr->worksheet, NUM2DBL(height), hide_ur);
|
958
|
+
return self;
|
959
|
+
}
|
960
|
+
|
961
|
+
|
962
|
+
VALUE
|
963
|
+
worksheet_get_vertical_dpi_(VALUE self) {
|
964
|
+
struct worksheet *ptr;
|
965
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
966
|
+
return ptr->worksheet->vertical_dpi;
|
967
|
+
}
|
968
|
+
|
969
|
+
VALUE
|
970
|
+
worksheet_set_vertical_dpi_(VALUE self, VALUE val) {
|
971
|
+
struct worksheet *ptr;
|
972
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
973
|
+
ptr->worksheet->vertical_dpi = NUM2INT(val);
|
974
|
+
return val;
|
975
|
+
}
|
976
|
+
|
977
|
+
|
978
|
+
lxw_col_t
|
979
|
+
value_to_col(VALUE value) {
|
980
|
+
switch (TYPE(value)) {
|
981
|
+
case T_FIXNUM:
|
982
|
+
return NUM2INT(value);
|
983
|
+
case T_STRING:
|
984
|
+
return lxw_name_to_col(RSTRING_PTR(value));
|
985
|
+
default:
|
986
|
+
rb_raise(rb_eTypeError, "Wrong type for col %"PRIsVALUE, rb_obj_class(value));
|
987
|
+
return -1;
|
988
|
+
}
|
989
|
+
}
|
990
|
+
|
991
|
+
int
|
992
|
+
extract_cell(int argc, VALUE *argv, lxw_row_t *row, lxw_col_t *col) {
|
993
|
+
char *str;
|
994
|
+
switch (TYPE(argv[0])) {
|
995
|
+
case T_STRING:
|
996
|
+
str = RSTRING_PTR(argv[0]);
|
997
|
+
if ((str[0] >= 'A' && str[0] <= 'Z') ||
|
998
|
+
(str[0] >= 'a' && str[0] <= 'z')) {
|
999
|
+
// Column in also in argv[0]
|
1000
|
+
(*row) = lxw_name_to_row(str);
|
1001
|
+
(*col) = lxw_name_to_col(str);
|
1002
|
+
return 1;
|
1003
|
+
} else {
|
1004
|
+
if (argc > 1) {
|
1005
|
+
(*row) = atoi(str);
|
1006
|
+
switch(TYPE(argv[1])) {
|
1007
|
+
case T_STRING:
|
1008
|
+
str = RSTRING_PTR(argv[1]);
|
1009
|
+
if ((str[0] >= 'A' && str[0] <= 'Z') ||
|
1010
|
+
(str[0] >= 'a' && str[0] <= 'z')) {
|
1011
|
+
(*col) = lxw_name_to_col(str);
|
1012
|
+
} else {
|
1013
|
+
(*col) = atoi(str);
|
1014
|
+
}
|
1015
|
+
return 2;
|
1016
|
+
case T_FIXNUM:
|
1017
|
+
(*col) = NUM2INT(argv[1]);
|
1018
|
+
return 2;
|
1019
|
+
default:
|
1020
|
+
rb_raise(rb_eArgError, "Cannot extract column info from %"PRIsVALUE,
|
1021
|
+
rb_inspect(argv[1]));
|
1022
|
+
return 0;
|
1023
|
+
}
|
1024
|
+
} else {
|
1025
|
+
rb_raise(rb_eArgError, "Cannot extract column info from %"PRIsVALUE,
|
1026
|
+
rb_inspect(argv[0]));
|
1027
|
+
return 0;
|
1028
|
+
}
|
1029
|
+
}
|
1030
|
+
break;
|
1031
|
+
case T_FIXNUM:
|
1032
|
+
if (argc > 1) {
|
1033
|
+
(*row) = NUM2INT(argv[0]);
|
1034
|
+
(*col) = value_to_col(argv[1]);
|
1035
|
+
return 2;
|
1036
|
+
} else {
|
1037
|
+
rb_raise(rb_eArgError, "Cannot extract column, not enough arguments");
|
1038
|
+
return 0;
|
1039
|
+
}
|
1040
|
+
break;
|
1041
|
+
default:
|
1042
|
+
rb_raise(rb_eTypeError, "Expected string or number, got %"PRIsVALUE, rb_obj_class(argv[0]));
|
1043
|
+
return 0;
|
1044
|
+
}
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
int extract_range(int argc, VALUE *argv, lxw_row_t *row_from, lxw_col_t *col_from,
|
1048
|
+
lxw_row_t *row_to, lxw_col_t *col_to) {
|
1049
|
+
char *str;
|
1050
|
+
if (TYPE(argv[0]) == T_STRING) {
|
1051
|
+
str = RSTRING_PTR(argv[0]);
|
1052
|
+
if (strstr(str, ":")) {
|
1053
|
+
(*row_from) = lxw_name_to_row(str);
|
1054
|
+
(*col_from) = lxw_name_to_col(str);
|
1055
|
+
(*row_to) = lxw_name_to_row_2(str);
|
1056
|
+
(*col_to) = lxw_name_to_col_2(str);
|
1057
|
+
return 1;
|
1058
|
+
}
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
int larg = extract_cell(argc, argv, row_from, col_from);
|
1062
|
+
larg += extract_cell(argc - larg, argv + larg, row_to, col_to);
|
1063
|
+
return larg;
|
1064
|
+
}
|