xlsxwriter 0.1.2.pre → 0.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/xlsxwriter/chart.c +7 -0
- data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/common.h +16 -0
- data/ext/xlsxwriter/worksheet.c +230 -2
- data/ext/xlsxwriter/xlsxwriter.c +2 -0
- data/ext/xlsxwriter/xlsxwriter_ext.h +15 -0
- data/lib/xlsxwriter/version.rb +1 -1
- data/test/support/xlsx_comparable.rb +2 -2
- data/test/test-data-validation.rb +107 -0
- data/test/test-default-row.rb +22 -0
- data/test/test-defined-name.rb +5 -0
- data/test/test-fit-to-pages.rb +34 -2
- data/test/test-formatting.rb +53 -0
- data/test/test-image.rb +28 -0
- data/test/test-misc.rb +9 -0
- data/test/test-optimize.rb +34 -0
- data/test/test-outline.rb +125 -0
- data/test/xlsx-func-testcase.rb +4 -3
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 408b3a45c34215b79898280c419cf2adafbde2bf0a4037f11a0432972c7861cf
|
4
|
+
data.tar.gz: d162bd3b0043aa39114baa98a28665fe8931c22e8252f5a0e9040c2a10c62319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 566117022982bb38edc6b2048567a10a5174fae628fa6b47c85324d721ea4e4448360d82c9b8656af85bd0b28639ef9efc3a0c1d625f8b4d1a1dc19c141ac306
|
7
|
+
data.tar.gz: 54c7504e4bcafd1f982a45dbf98ebec925c9880ae8797022920c24c00af5926e51d55ca70d822a1298aa4a3fa13390c4030d17fbe14b7754f3e6aee6a252448d
|
data/ext/xlsxwriter/chart.c
CHANGED
@@ -593,8 +593,15 @@ void init_xlsxwriter_chart() {
|
|
593
593
|
MAP_CHART_CONST(LEGEND_LEFT);
|
594
594
|
MAP_CHART_CONST(LEGEND_TOP);
|
595
595
|
MAP_CHART_CONST(LEGEND_BOTTOM);
|
596
|
+
MAP_CHART_CONST(LEGEND_TOP_RIGHT);
|
596
597
|
MAP_CHART_CONST(LEGEND_OVERLAY_RIGHT);
|
597
598
|
MAP_CHART_CONST(LEGEND_OVERLAY_LEFT);
|
599
|
+
MAP_CHART_CONST(LEGEND_OVERLAY_TOP_RIGHT);
|
600
|
+
|
601
|
+
MAP_CHART_CONST(AXIS_LABEL_ALIGN_CENTER);
|
602
|
+
MAP_CHART_CONST(AXIS_LABEL_ALIGN_LEFT);
|
603
|
+
MAP_CHART_CONST(AXIS_LABEL_ALIGN_RIGHT);
|
604
|
+
|
598
605
|
|
599
606
|
#undef MAP_CHART_CONST
|
600
607
|
}
|
@@ -219,6 +219,8 @@ enum lxw_custom_property_types {
|
|
219
219
|
if (error) \
|
220
220
|
return error;
|
221
221
|
|
222
|
+
#if 0
|
223
|
+
|
222
224
|
#define LXW_WARN(message) \
|
223
225
|
fprintf(stderr, "[WARNING]: " message "\n")
|
224
226
|
|
@@ -268,6 +270,20 @@ enum lxw_custom_property_types {
|
|
268
270
|
return; \
|
269
271
|
}
|
270
272
|
|
273
|
+
#else
|
274
|
+
|
275
|
+
#define LXW_WARN(message) {}
|
276
|
+
#define LXW_WARN_FORMAT(message) {}
|
277
|
+
#define LXW_WARN_FORMAT1(message, var) {}
|
278
|
+
#define LXW_WARN_FORMAT2(message, var1, var2) {}
|
279
|
+
#define LXW_WARN_CAT_AXIS_ONLY(function) {}
|
280
|
+
#define LXW_WARN_VALUE_AXIS_ONLY(function) {}
|
281
|
+
#define LXW_WARN_DATE_AXIS_ONLY(function) {}
|
282
|
+
#define LXW_WARN_CAT_AND_DATE_AXIS_ONLY(function) {}
|
283
|
+
#define LXW_WARN_VALUE_AND_DATE_AXIS_ONLY(function) {}
|
284
|
+
|
285
|
+
#endif
|
286
|
+
|
271
287
|
#ifndef LXW_BIG_ENDIAN
|
272
288
|
#define LXW_UINT32_NETWORK(n) ((((n) & 0xFF) << 24) | \
|
273
289
|
(((n) & 0xFF00) << 8) | \
|
data/ext/xlsxwriter/worksheet.c
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "chart.h"
|
2
2
|
#include "worksheet.h"
|
3
3
|
#include "workbook.h"
|
4
|
+
#include "xlsxwriter_ext.h"
|
4
5
|
|
5
6
|
VALUE cWorksheet;
|
6
7
|
|
@@ -461,9 +462,17 @@ worksheet_set_row_(VALUE self, VALUE row, VALUE opts) {
|
|
461
462
|
if (val != Qnil && val)
|
462
463
|
options.hidden = 1;
|
463
464
|
|
465
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("collapse")));
|
466
|
+
if (val != Qnil && val)
|
467
|
+
options.collapsed = 1;
|
468
|
+
|
469
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("level")));
|
470
|
+
if (val != Qnil)
|
471
|
+
options.level = NUM2INT(val);
|
472
|
+
|
464
473
|
struct worksheet *ptr;
|
465
474
|
Data_Get_Struct(self, struct worksheet, ptr);
|
466
|
-
if (options.hidden) {
|
475
|
+
if (options.hidden || options.collapsed || options.level) {
|
467
476
|
worksheet_set_row_opt(ptr->worksheet, NUM2INT(row), height, format, &options);
|
468
477
|
} else {
|
469
478
|
worksheet_set_row(ptr->worksheet, NUM2INT(row), height, format);
|
@@ -500,9 +509,17 @@ worksheet_set_column_(VALUE self, VALUE col_from, VALUE col_to, VALUE opts) {
|
|
500
509
|
if (val != Qnil && val)
|
501
510
|
options.hidden = 1;
|
502
511
|
|
512
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("collapse")));
|
513
|
+
if (val != Qnil && val)
|
514
|
+
options.collapsed = 1;
|
515
|
+
|
516
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("level")));
|
517
|
+
if (val != Qnil)
|
518
|
+
options.level = NUM2INT(val);
|
519
|
+
|
503
520
|
struct worksheet *ptr;
|
504
521
|
Data_Get_Struct(self, struct worksheet, ptr);
|
505
|
-
if (options.hidden) {
|
522
|
+
if (options.hidden || options.collapsed || options.level) {
|
506
523
|
worksheet_set_column_opt(ptr->worksheet, col1, col2, width, format, &options);
|
507
524
|
} else {
|
508
525
|
worksheet_set_column(ptr->worksheet, col1, col2, width, format);
|
@@ -1195,6 +1212,27 @@ worksheet_protect_(int argc, VALUE *argv, VALUE self) {
|
|
1195
1212
|
return self;
|
1196
1213
|
}
|
1197
1214
|
|
1215
|
+
/* call-seq: ws.outline_settings = { visible: true, symbols_below: true, symbols_right: true, auto_style: false }
|
1216
|
+
*
|
1217
|
+
* Sets the Outline and Grouping display properties.
|
1218
|
+
*/
|
1219
|
+
VALUE
|
1220
|
+
worksheet_outline_settings_(VALUE self, VALUE opts) {
|
1221
|
+
struct worksheet *ptr;
|
1222
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
1223
|
+
VALUE value;
|
1224
|
+
#define parse_param(name, default) \
|
1225
|
+
value = rb_hash_aref(opts, ID2SYM(rb_intern(#name))); \
|
1226
|
+
uint8_t name = NIL_P(value) ? default : (value ? LXW_TRUE : LXW_FALSE)
|
1227
|
+
parse_param(visible, LXW_TRUE);
|
1228
|
+
parse_param(symbols_below, LXW_TRUE);
|
1229
|
+
parse_param(symbols_right, LXW_TRUE);
|
1230
|
+
parse_param(auto_style, LXW_FALSE);
|
1231
|
+
#undef parse_param
|
1232
|
+
worksheet_outline_settings(ptr->worksheet, visible, symbols_below, symbols_right, auto_style);
|
1233
|
+
return self;
|
1234
|
+
}
|
1235
|
+
|
1198
1236
|
/* call-seq: ws.set_default_row(height, hide_unuser_rows) -> self
|
1199
1237
|
*
|
1200
1238
|
* Sets the default row properties for the worksheet.
|
@@ -1231,6 +1269,167 @@ worksheet_set_vertical_dpi_(VALUE self, VALUE val) {
|
|
1231
1269
|
return val;
|
1232
1270
|
}
|
1233
1271
|
|
1272
|
+
/* call-seq:
|
1273
|
+
* ws.add_data_validation(cell, options) -> self
|
1274
|
+
* ws.add_data_validation(range, options) -> self
|
1275
|
+
* ws.add_data_validation(row, col, options) -> self
|
1276
|
+
* ws.add_data_validation(row_from, col_from, row_to, col_to, options) -> self
|
1277
|
+
*
|
1278
|
+
* Adds data validation or limits user input to a list of values.
|
1279
|
+
*/
|
1280
|
+
VALUE
|
1281
|
+
worksheet_data_validation_(int argc, VALUE *argv, VALUE self) {
|
1282
|
+
lxw_data_validation data_validation = {0};
|
1283
|
+
rb_check_arity(argc, 2, 5);
|
1284
|
+
char range = 0;
|
1285
|
+
if (argc > 3) {
|
1286
|
+
range = 1;
|
1287
|
+
} else if (TYPE(argv[0]) == T_STRING) {
|
1288
|
+
char *str = RSTRING_PTR(argv[0]);
|
1289
|
+
if (strstr(str, ":")) {
|
1290
|
+
range = 1;
|
1291
|
+
} else if ((str[0] >= 'A' && str[0] <= 'Z') ||
|
1292
|
+
(str[0] >= 'a' && str[0] <= 'z'))
|
1293
|
+
range = argc > 2;
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
lxw_row_t row, row2;
|
1297
|
+
lxw_col_t col, col2;
|
1298
|
+
int larg;
|
1299
|
+
if (range) {
|
1300
|
+
larg = extract_range(argc, argv, &row, &col, &row2, &col2);
|
1301
|
+
} else {
|
1302
|
+
larg = extract_cell(argc, argv, &row, &col);
|
1303
|
+
}
|
1304
|
+
|
1305
|
+
if (larg != argc - 1) {
|
1306
|
+
rb_raise(rb_eArgError, "Wrong number of arguments");
|
1307
|
+
}
|
1308
|
+
VALUE opts = argv[larg];
|
1309
|
+
if (TYPE(opts) != T_HASH) {
|
1310
|
+
rb_raise(rb_eTypeError, "Wrong type for options %"PRIsVALUE", Hash expected", rb_obj_class(opts));
|
1311
|
+
}
|
1312
|
+
|
1313
|
+
VALUE val;
|
1314
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("validate")));
|
1315
|
+
if (!NIL_P(val)) {
|
1316
|
+
data_validation.validate = NUM2INT(val);
|
1317
|
+
}
|
1318
|
+
|
1319
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("criteria")));
|
1320
|
+
if (!NIL_P(val)) {
|
1321
|
+
data_validation.criteria = NUM2INT(val);
|
1322
|
+
}
|
1323
|
+
|
1324
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("ignore_blank")));
|
1325
|
+
if (!NIL_P(val) && val) {
|
1326
|
+
data_validation.ignore_blank = LXW_VALIDATION_ON;
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("show_input")));
|
1330
|
+
if (!NIL_P(val) && val) {
|
1331
|
+
data_validation.show_input = LXW_VALIDATION_ON;
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("show_error")));
|
1335
|
+
if (!NIL_P(val) && val) {
|
1336
|
+
data_validation.show_error = LXW_VALIDATION_ON;
|
1337
|
+
}
|
1338
|
+
|
1339
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("error_type")));
|
1340
|
+
if (!NIL_P(val)) {
|
1341
|
+
data_validation.error_type = NUM2INT(val);
|
1342
|
+
}
|
1343
|
+
|
1344
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("dropdown")));
|
1345
|
+
if (!NIL_P(val) && val) {
|
1346
|
+
data_validation.dropdown = LXW_VALIDATION_ON;
|
1347
|
+
}
|
1348
|
+
|
1349
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("input_title")));
|
1350
|
+
if (!NIL_P(val)) {
|
1351
|
+
data_validation.input_title = RSTRING_PTR(val);
|
1352
|
+
}
|
1353
|
+
|
1354
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("input_message")));
|
1355
|
+
if (!NIL_P(val)) {
|
1356
|
+
data_validation.input_message = RSTRING_PTR(val);
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("error_title")));
|
1360
|
+
if (!NIL_P(val)) {
|
1361
|
+
data_validation.error_title = RSTRING_PTR(val);
|
1362
|
+
}
|
1363
|
+
|
1364
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern("error_message")));
|
1365
|
+
if (!NIL_P(val)) {
|
1366
|
+
data_validation.error_message = RSTRING_PTR(val);
|
1367
|
+
}
|
1368
|
+
|
1369
|
+
VALUE is_datetime;
|
1370
|
+
#define parse_array_0(x)
|
1371
|
+
#define parse_array_1(prefix) \
|
1372
|
+
if (TYPE(val) == T_ARRAY) { \
|
1373
|
+
int len = RARRAY_LEN(val); \
|
1374
|
+
data_validation.prefix##_list = malloc(sizeof(char *) * (len + 1)); \
|
1375
|
+
data_validation.prefix##_list[len] = NULL; \
|
1376
|
+
for (int i = 0; i < len; ++i) { \
|
1377
|
+
data_validation.prefix##_list[i] = RSTRING_PTR(rb_ary_entry(val, i)); \
|
1378
|
+
} \
|
1379
|
+
} else
|
1380
|
+
|
1381
|
+
#define parse_value(prefix, key, handle_array) \
|
1382
|
+
val = rb_hash_aref(opts, ID2SYM(rb_intern(key))); \
|
1383
|
+
if (!NIL_P(val)) { \
|
1384
|
+
switch(TYPE(val)) { \
|
1385
|
+
case T_FLOAT: case T_FIXNUM: case T_BIGNUM: \
|
1386
|
+
data_validation.prefix##_number = NUM2DBL(val); \
|
1387
|
+
break; \
|
1388
|
+
case T_STRING: \
|
1389
|
+
data_validation.prefix##_formula = RSTRING_PTR(val); \
|
1390
|
+
if (data_validation.prefix##_formula[0] != '=') { \
|
1391
|
+
data_validation.prefix##_formula = 0; \
|
1392
|
+
rb_raise(rb_eArgError, "Is not a formula: %"PRIsVALUE, val); \
|
1393
|
+
} \
|
1394
|
+
break; \
|
1395
|
+
default: \
|
1396
|
+
is_datetime = rb_funcall(val, rb_intern("is_a?"), 1, rb_cTime); \
|
1397
|
+
parse_array_##handle_array(prefix) \
|
1398
|
+
if (is_datetime || rb_respond_to(val, rb_intern("to_time"))) { \
|
1399
|
+
if (!is_datetime) \
|
1400
|
+
val = rb_funcall(val, rb_intern("to_time"), 0); \
|
1401
|
+
data_validation.prefix##_datetime = value_to_lxw_datetime(val); \
|
1402
|
+
} else { \
|
1403
|
+
rb_raise(rb_eTypeError, "Cannot handle " key " type %"PRIsVALUE, rb_class_of(val)); \
|
1404
|
+
} \
|
1405
|
+
} \
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
parse_value(minimum, "min", 0);
|
1409
|
+
parse_value(maximum, "max", 0);
|
1410
|
+
parse_value(value, "value", 1);
|
1411
|
+
|
1412
|
+
#undef parse_array_0
|
1413
|
+
#undef parse_array_1
|
1414
|
+
#undef parse_value
|
1415
|
+
|
1416
|
+
struct worksheet *ptr;
|
1417
|
+
Data_Get_Struct(self, struct worksheet, ptr);
|
1418
|
+
lxw_error err;
|
1419
|
+
if (range) {
|
1420
|
+
err = worksheet_data_validation_range(ptr->worksheet, row, col, row2, col2, &data_validation);
|
1421
|
+
} else {
|
1422
|
+
err = worksheet_data_validation_cell(ptr->worksheet, row, col, &data_validation);
|
1423
|
+
}
|
1424
|
+
|
1425
|
+
if (data_validation.value_list) {
|
1426
|
+
free(data_validation.value_list);
|
1427
|
+
}
|
1428
|
+
|
1429
|
+
handle_xlsxwriter_error(err);
|
1430
|
+
|
1431
|
+
return self;
|
1432
|
+
}
|
1234
1433
|
|
1235
1434
|
lxw_col_t
|
1236
1435
|
value_to_col(VALUE value) {
|
@@ -1402,12 +1601,16 @@ init_xlsxwriter_worksheet() {
|
|
1402
1601
|
rb_define_method(cWorksheet, "hide_zero", worksheet_hide_zero_, 0);
|
1403
1602
|
rb_define_method(cWorksheet, "tab_color=", worksheet_set_tab_color_, 1);
|
1404
1603
|
rb_define_method(cWorksheet, "protect", worksheet_protect_, -1);
|
1604
|
+
rb_define_method(cWorksheet, "outline_settings=", worksheet_outline_settings_, 1);
|
1405
1605
|
rb_define_method(cWorksheet, "set_default_row", worksheet_set_default_row_, 2);
|
1406
1606
|
|
1407
1607
|
rb_define_method(cWorksheet, "vertical_dpi", worksheet_get_vertical_dpi_, 0);
|
1408
1608
|
rb_define_method(cWorksheet, "vertical_dpi=", worksheet_set_vertical_dpi_, 1);
|
1409
1609
|
|
1610
|
+
rb_define_method(cWorksheet, "add_data_validation", worksheet_data_validation_, -1);
|
1611
|
+
|
1410
1612
|
#define MAP_LXW_WH_CONST(name, val_name) rb_define_const(cWorksheet, #name, INT2NUM(LXW_##val_name))
|
1613
|
+
#define MAP_LXW_WH_CONST1(name) MAP_LXW_WH_CONST(name, name)
|
1411
1614
|
MAP_LXW_WH_CONST(DEF_COL_WIDTH, DEF_COL_WIDTH);
|
1412
1615
|
MAP_LXW_WH_CONST(DEF_ROW_HEIGHT, DEF_ROW_HEIGHT);
|
1413
1616
|
|
@@ -1415,5 +1618,30 @@ init_xlsxwriter_worksheet() {
|
|
1415
1618
|
MAP_LXW_WH_CONST(GRIDLINES_SHOW_SCREEN, SHOW_SCREEN_GRIDLINES);
|
1416
1619
|
MAP_LXW_WH_CONST(GRIDLINES_SHOW_PRINT, SHOW_PRINT_GRIDLINES);
|
1417
1620
|
MAP_LXW_WH_CONST(GRIDLINES_SHOW_ALL, SHOW_ALL_GRIDLINES);
|
1621
|
+
|
1622
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_INTEGER);
|
1623
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_INTEGER_FORMULA);
|
1624
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_DECIMAL);
|
1625
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_DECIMAL_FORMULA);
|
1626
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_LIST);
|
1627
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_LIST_FORMULA);
|
1628
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_DATE);
|
1629
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_DATE_FORMULA);
|
1630
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_TIME);
|
1631
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_TIME_FORMULA);
|
1632
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_LENGTH);
|
1633
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_LENGTH_FORMULA);
|
1634
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_CUSTOM_FORMULA);
|
1635
|
+
MAP_LXW_WH_CONST1(VALIDATION_TYPE_ANY);
|
1636
|
+
|
1637
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_BETWEEN);
|
1638
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_NOT_BETWEEN);
|
1639
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_EQUAL_TO);
|
1640
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_NOT_EQUAL_TO);
|
1641
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_GREATER_THAN);
|
1642
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_LESS_THAN);
|
1643
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_GREATER_THAN_OR_EQUAL_TO);
|
1644
|
+
MAP_LXW_WH_CONST1(VALIDATION_CRITERIA_LESS_THAN_OR_EQUAL_TO);
|
1645
|
+
#undef MAP_LXW_WH_CONST1
|
1418
1646
|
#undef MAP_LXW_WH_CONST
|
1419
1647
|
}
|
data/ext/xlsxwriter/xlsxwriter.c
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
|
9
9
|
VALUE mXlsxWriter;
|
10
10
|
VALUE rbLibVersion;
|
11
|
+
VALUE eXlsxWriterError;
|
11
12
|
|
12
13
|
/* Document-module: XlsxWriter
|
13
14
|
*
|
@@ -32,6 +33,7 @@ void Init_xlsxwriter() {
|
|
32
33
|
mXlsxWriter = rb_define_module("XlsxWriter");
|
33
34
|
rbLibVersion = rb_str_new_cstr(lxw_version());
|
34
35
|
rb_define_const(mXlsxWriter, "LIBRARY_VERSION", rbLibVersion);
|
36
|
+
eXlsxWriterError = rb_define_class_id_under(mXlsxWriter, rb_intern("Error"), rb_eStandardError);
|
35
37
|
|
36
38
|
init_xlsxwriter_workbook();
|
37
39
|
init_xlsxwriter_workbook_properties();
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
#ifndef XLSXWRITER_H
|
4
|
+
#define XLSXWRITER_H
|
5
|
+
|
6
|
+
extern VALUE mXlsxWriter;
|
7
|
+
extern VALUE eXlsxWriterError;
|
8
|
+
|
9
|
+
inline void handle_xlsxwriter_error(lxw_error err) {
|
10
|
+
if (err) {
|
11
|
+
rb_raise(eXlsxWriterError, lxw_strerror(err));
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
#endif /* XLSXWRITER_H */
|
data/lib/xlsxwriter/version.rb
CHANGED
@@ -18,7 +18,7 @@ module XlsxComparable
|
|
18
18
|
|
19
19
|
if %w(.png .jpeg .bmp .bin).include?(File.extname(exp_entry.name))
|
20
20
|
exp_xml_str.force_encoding('BINARY')
|
21
|
-
assert_equal(
|
21
|
+
assert_equal(exp_xml_str, got_xml_str)
|
22
22
|
next
|
23
23
|
end
|
24
24
|
|
@@ -60,7 +60,7 @@ module XlsxComparable
|
|
60
60
|
exp_xml = _sort_rel_file_data(exp_xml)
|
61
61
|
end
|
62
62
|
|
63
|
-
assert_equal
|
63
|
+
assert_equal exp_xml, got_xml
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative './xlsx-func-testcase'
|
5
|
+
|
6
|
+
class TestDataValidation < XlsxWriterTestCase
|
7
|
+
test 'data_validation01' do |wb|
|
8
|
+
wb.add_worksheet
|
9
|
+
.add_data_validation 'C2', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
10
|
+
value: %w(Foo Bar Baz)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'data_validation02' do |wb|
|
14
|
+
wb.add_worksheet
|
15
|
+
.add_data_validation 1, 2, validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
16
|
+
value: %w(Foo Bar Baz),
|
17
|
+
input_title: 'This is the input title',
|
18
|
+
input_message: 'This is the input message'
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'data_validation03' do |wb|
|
22
|
+
wb.add_worksheet
|
23
|
+
.add_data_validation('C2', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
24
|
+
value: %w(Foo Bar Baz),
|
25
|
+
input_title: 'This is the input title',
|
26
|
+
input_message: 'This is the input message')
|
27
|
+
.add_data_validation('D6', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
28
|
+
value: %w(Foobar Foobas Foobat Foobau Foobav Foobaw Foobax
|
29
|
+
Foobay Foobaz Foobba Foobbb Foobbc Foobbd Foobbe
|
30
|
+
Foobbf Foobbg Foobbh Foobbi Foobbj Foobbk Foobbl
|
31
|
+
Foobbm Foobbn Foobbo Foobbp Foobbq Foobbr Foobbs
|
32
|
+
Foobbt Foobbu Foobbv Foobbw Foobbx Foobby Foobbz
|
33
|
+
Foobca End),
|
34
|
+
input_title: 'This is the longest input title1',
|
35
|
+
input_message: 'This is the longest input message ' + 'a' * 221)
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'data_validation04', ref_file_name: 'data_validation02' do |wb|
|
39
|
+
ws = wb.add_worksheet
|
40
|
+
.add_data_validation('C2', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
41
|
+
value: %w(Foo Bar Baz),
|
42
|
+
input_title: 'This is the input title',
|
43
|
+
input_message: 'This is the input message')
|
44
|
+
assert_raise(XlsxWriter::Error.new('Parameter exceeds Excel\'s limit of 32 characters.')) do
|
45
|
+
ws.add_data_validation('D6', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
46
|
+
value: %w(Foobar Foobas Foobat Foobau Foobav Foobaw Foobax
|
47
|
+
Foobay Foobaz Foobba Foobbb Foobbc Foobbd Foobbe
|
48
|
+
Foobbf Foobbg Foobbh Foobbi Foobbj Foobbk Foobbl
|
49
|
+
Foobbm Foobbn Foobbo Foobbp Foobbq Foobbr Foobbs
|
50
|
+
Foobbt Foobbu Foobbv Foobbw Foobbx Foobby Foobbz
|
51
|
+
Foobca End),
|
52
|
+
input_title: 'This is the longest input title12',
|
53
|
+
input_message: 'This is the longest input message ' + 'a' * 221)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'data_validation05', ref_file_name: 'data_validation02' do |wb|
|
58
|
+
ws = wb.add_worksheet
|
59
|
+
.add_data_validation('C2', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
60
|
+
value: %w(Foo Bar Baz),
|
61
|
+
input_title: 'This is the input title',
|
62
|
+
input_message: 'This is the input message')
|
63
|
+
assert_raise(XlsxWriter::Error.new('Parameter exceeds Excel\'s limit of 255 characters.')) do
|
64
|
+
ws.add_data_validation('D6', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
65
|
+
value: %w(Foobar Foobas Foobat Foobau Foobav Foobaw Foobax
|
66
|
+
Foobay Foobaz Foobba Foobbb Foobbc Foobbd Foobbe
|
67
|
+
Foobbf Foobbg Foobbh Foobbi Foobbj Foobbk Foobbl
|
68
|
+
Foobbm Foobbn Foobbo Foobbp Foobbq Foobbr Foobbs
|
69
|
+
Foobbt Foobbu Foobbv Foobbw Foobbx Foobby Foobbz
|
70
|
+
Foobca End),
|
71
|
+
input_title: 'This is the longest input title1',
|
72
|
+
input_message: 'This is the longest input message ' + 'a' * 222)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'data_validation06', ref_file_name: 'data_validation02' do |wb|
|
77
|
+
ws = wb.add_worksheet
|
78
|
+
.add_data_validation('C2', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
79
|
+
value: %w(Foo Bar Baz),
|
80
|
+
input_title: 'This is the input title',
|
81
|
+
input_message: 'This is the input message')
|
82
|
+
assert_raise(XlsxWriter::Error.new('Parameter exceeds Excel\'s limit of 255 characters.')) do
|
83
|
+
ws.add_data_validation('D6', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
84
|
+
value: %w(Foobar Foobas Foobat Foobau Foobav Foobaw Foobax
|
85
|
+
Foobay Foobaz Foobba Foobbb Foobbc Foobbd Foobbe
|
86
|
+
Foobbf Foobbg Foobbh Foobbi Foobbj Foobbk Foobbl
|
87
|
+
Foobbm Foobbn Foobbo Foobbp Foobbq Foobbr Foobbs
|
88
|
+
Foobbt Foobbu Foobbv Foobbw Foobbx Foobby Foobbz
|
89
|
+
Foobca End1),
|
90
|
+
input_title: 'This is the longest input title1',
|
91
|
+
input_message: 'This is the longest input message ' + 'a' * 221)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'data_validation07' do |wb|
|
96
|
+
wb.add_worksheet
|
97
|
+
.add_data_validation 'C2', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_LIST,
|
98
|
+
value: %w(coffee café)
|
99
|
+
end
|
100
|
+
|
101
|
+
test 'data_validation08' do |wb|
|
102
|
+
wb.add_worksheet
|
103
|
+
.add_data_validation 'C2:C2', validate: XlsxWriter::Worksheet::VALIDATION_TYPE_ANY,
|
104
|
+
input_title: 'This is the input title',
|
105
|
+
input_message: 'This is the input message'
|
106
|
+
end
|
107
|
+
end
|
data/test/test-default-row.rb
CHANGED
@@ -12,6 +12,28 @@ class TestDefaultRow < XlsxWriterTestCase
|
|
12
12
|
ws.write_string(9, 'A', 'Bar', nil)
|
13
13
|
end
|
14
14
|
|
15
|
+
test 'default_row02' do |wb|
|
16
|
+
ws = wb.add_worksheet
|
17
|
+
|
18
|
+
ws.set_default_row(15, true)
|
19
|
+
|
20
|
+
ws.write_string('A1', 'Foo', nil)
|
21
|
+
ws.write_string('A10', 'Bar', nil)
|
22
|
+
|
23
|
+
(1..8).each { |i| ws.set_row i, height: 15 }
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'default_row03' do |wb|
|
27
|
+
ws = wb.add_worksheet
|
28
|
+
|
29
|
+
ws.set_default_row(24, true)
|
30
|
+
|
31
|
+
ws.write_string('A1', 'Foo', nil)
|
32
|
+
ws.write_string('A10', 'Bar', nil)
|
33
|
+
|
34
|
+
(1..8).each { |i| ws.set_row i, height: 24 }
|
35
|
+
end
|
36
|
+
|
15
37
|
test 'default_row05' do |wb|
|
16
38
|
ws = wb.add_worksheet
|
17
39
|
|
data/test/test-defined-name.rb
CHANGED
@@ -29,6 +29,11 @@ class TestDefinedName < XlsxWriterTestCase
|
|
29
29
|
wb.define_name "_Fog", "=Sheet1!$A$1"
|
30
30
|
end
|
31
31
|
|
32
|
+
test 'defined_name02' do |wb|
|
33
|
+
wb.add_worksheet 'sheet One'
|
34
|
+
wb.define_name "Sales", "='sheet One'!$G$1:$H$10"
|
35
|
+
end
|
36
|
+
|
32
37
|
test 'defined_name03' do |wb, t|
|
33
38
|
t.ignore_elements = { 'xl/worksheets/sheet1.xml' => [ '<pageMargins' ] }
|
34
39
|
wb.add_worksheet('sheet One')
|
data/test/test-fit-to-pages.rb
CHANGED
@@ -3,21 +3,53 @@
|
|
3
3
|
require_relative './xlsx-func-testcase'
|
4
4
|
|
5
5
|
class TestFitToPages < XlsxWriterTestCase
|
6
|
+
test 'fit_to_pages01' do |wb, t|
|
7
|
+
t.ignore_elements = { 'xl/worksheets/sheet1.xml' => [ '<pageMargins' ] }
|
8
|
+
|
9
|
+
ws = wb.add_worksheet
|
10
|
+
ws.fit_to_pages 1, 1
|
11
|
+
ws.paper = 9
|
12
|
+
ws.vertical_dpi = 200
|
13
|
+
ws.write_string 'A1', 'Foo'
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'fit_to_pages02' do |wb, t|
|
17
|
+
t.ignore_elements = { 'xl/worksheets/sheet1.xml' => [ '<pageMargins' ] }
|
18
|
+
|
19
|
+
ws = wb.add_worksheet
|
20
|
+
ws.fit_to_pages 2, 1
|
21
|
+
ws.paper = 9
|
22
|
+
ws.vertical_dpi = 200
|
23
|
+
ws.write_string 'A1', 'Foo'
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'fit_to_pages03' do |wb, t|
|
27
|
+
t.ignore_elements = { 'xl/worksheets/sheet1.xml' => [ '<pageMargins' ] }
|
28
|
+
|
29
|
+
ws = wb.add_worksheet
|
30
|
+
ws.fit_to_pages 1, 2
|
31
|
+
ws.paper = 9
|
32
|
+
ws.vertical_dpi = 200
|
33
|
+
ws.write_string 'A1', 'Foo'
|
34
|
+
end
|
35
|
+
|
6
36
|
test 'fit_to_pages04' do |wb, t|
|
7
37
|
t.ignore_elements = { 'xl/worksheets/sheet1.xml' => [ '<pageMargins' ] }
|
38
|
+
|
8
39
|
ws = wb.add_worksheet
|
9
40
|
ws.fit_to_pages(3, 2)
|
10
41
|
ws.paper = 9
|
11
42
|
ws.vertical_dpi = 200
|
12
|
-
ws.write_string 0, 'A', 'Foo'
|
43
|
+
ws.write_string 0, 'A', 'Foo'
|
13
44
|
end
|
14
45
|
|
15
46
|
test 'fit_to_pages05' do |wb, t|
|
16
47
|
t.ignore_elements = { 'xl/worksheets/sheet1.xml' => [ '<pageMargins' ] }
|
48
|
+
|
17
49
|
ws = wb.add_worksheet
|
18
50
|
ws.fit_to_pages(1, 0)
|
19
51
|
ws.paper = 9
|
20
52
|
ws.vertical_dpi = 200
|
21
|
-
ws.write_string 0, 'A', 'Foo'
|
53
|
+
ws.write_string 0, 'A', 'Foo'
|
22
54
|
end
|
23
55
|
end
|
data/test/test-formatting.rb
CHANGED
@@ -136,4 +136,57 @@ class TestFormatting < XlsxWriterTestCase
|
|
136
136
|
ws.write_string(1, 'D', 'test', :top_left)
|
137
137
|
ws.write_string(1, 'F', 'test', :top_bottom)
|
138
138
|
end
|
139
|
+
|
140
|
+
test 'format15' do |wb|
|
141
|
+
wb
|
142
|
+
.add_format(:format1, bold: true)
|
143
|
+
.add_format(:format2, bold: true, num_format_index: 1)
|
144
|
+
.add_worksheet
|
145
|
+
.write_number('A1', 1, :format1)
|
146
|
+
.write_number('A2', 2, :format2)
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'format50' do |wb|
|
150
|
+
wb
|
151
|
+
.add_format(:format1, num_format: '#,##0.00000')
|
152
|
+
.add_format(:format2, num_format: '#,##0.0')
|
153
|
+
.add_worksheet
|
154
|
+
.set_column('A', 'A', width: 12)
|
155
|
+
.write_number('A1', 1234.5, :format1)
|
156
|
+
.write_number('A2', 1234.5, :format2)
|
157
|
+
end
|
158
|
+
|
159
|
+
test 'format51' do |wb|
|
160
|
+
wb.add_format(:numf1, num_format: '0.0')
|
161
|
+
.add_format(:numf3, num_format: '0.000')
|
162
|
+
.add_format(:numf4, num_format: '0.0000')
|
163
|
+
.add_format(:numf5, num_format: '0.00000')
|
164
|
+
.add_worksheet
|
165
|
+
.set_column(0, 0, width: 12)
|
166
|
+
.write_number(0, 0, 123.456, :numf1)
|
167
|
+
.write_number(1, 0, 123.456, :numf3)
|
168
|
+
.write_number(2, 0, 123.456, :numf4)
|
169
|
+
.write_number(3, 0, 123.456, :numf5)
|
170
|
+
end
|
171
|
+
|
172
|
+
test 'format52' do |wb|
|
173
|
+
wb.add_format(:numf1, num_format: '0.0')
|
174
|
+
.add_format(:numf3, num_format: '0.000')
|
175
|
+
.add_format(:numf4, num_format: '0.0000')
|
176
|
+
.add_format(:numf5, num_format: '0.00000')
|
177
|
+
.add_format(:numf1_bold, num_format: '0.0', bold: true)
|
178
|
+
.add_format(:numf3_bold, num_format: '0.000', bold: true)
|
179
|
+
.add_format(:numf4_bold, num_format: '0.0000', bold: true)
|
180
|
+
.add_format(:numf5_bold, num_format: '0.00000', bold: true)
|
181
|
+
.add_worksheet
|
182
|
+
.set_column(0, 0, width: 12)
|
183
|
+
.write_number(0, 0, 123.456, :numf1)
|
184
|
+
.write_number(1, 0, 123.456, :numf3)
|
185
|
+
.write_number(2, 0, 123.456, :numf4)
|
186
|
+
.write_number(3, 0, 123.456, :numf5)
|
187
|
+
.write_number(4, 0, 123.456, :numf1_bold)
|
188
|
+
.write_number(5, 0, 123.456, :numf3_bold)
|
189
|
+
.write_number(6, 0, 123.456, :numf4_bold)
|
190
|
+
.write_number(7, 0, 123.456, :numf5_bold)
|
191
|
+
end
|
139
192
|
end
|
data/test/test-image.rb
CHANGED
@@ -83,4 +83,32 @@ class TestImage < XlsxWriterTestCase
|
|
83
83
|
test 'image29' do |wb|
|
84
84
|
wb.add_worksheet.insert_image(0, 10, image_path('red_208.png'), x_offset: -210, y_offset: 1)
|
85
85
|
end
|
86
|
+
|
87
|
+
test 'image36' do |wb|
|
88
|
+
wb.add_worksheet.insert_image('E9', image_path('happy.jpg'))
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'image44' do |wb|
|
92
|
+
wb.add_worksheet
|
93
|
+
.insert_image('E9', image_path('red.png'))
|
94
|
+
.set_row(8, height: 30)
|
95
|
+
end
|
96
|
+
|
97
|
+
test 'image45' do |wb|
|
98
|
+
wb.add_worksheet
|
99
|
+
.insert_image('E9', image_path('red.png'))
|
100
|
+
.set_row(8, height: 30, hide: true)
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'image46' do |wb|
|
104
|
+
wb.add_worksheet
|
105
|
+
.insert_image('E9', image_path('red.png'), x_offset: 0, y_offset: 4)
|
106
|
+
.set_row(8, height: 30, hide: true)
|
107
|
+
end
|
108
|
+
|
109
|
+
test 'image47' do |wb|
|
110
|
+
wb.add_worksheet
|
111
|
+
.insert_image('E9', image_path('red.png'))
|
112
|
+
.set_row(9, hide: true)
|
113
|
+
end
|
86
114
|
end
|
data/test/test-misc.rb
CHANGED
@@ -21,6 +21,15 @@ class TestMisc < XlsxWriterTestCase
|
|
21
21
|
wb.add_worksheet
|
22
22
|
end
|
23
23
|
|
24
|
+
test 'shared_strings01' do |wb|
|
25
|
+
ws = wb.add_worksheet
|
26
|
+
ws.write_string(0, 0, '_x0000_')
|
27
|
+
(1...127).each_with_object(String.new("")) do |i, s|
|
28
|
+
s[0] = i.chr
|
29
|
+
ws.write_string(i, 0, s) unless i == 34
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
24
33
|
test 'gh42_01' do |wb|
|
25
34
|
wb.add_worksheet.write_string(0, 0, "\xe5\x9b\xbe\x14\xe5\x9b\xbe", nil)
|
26
35
|
end
|
data/test/test-optimize.rb
CHANGED
@@ -31,4 +31,38 @@ class TestOptimize < XlsxWriterTestCase
|
|
31
31
|
.write_string(4, 'E', 'Foo ', nil)
|
32
32
|
.write_string(6, 'A', "\tFoo\t", nil)
|
33
33
|
end
|
34
|
+
|
35
|
+
test('optimize22', constant_memory: true) do |wb|
|
36
|
+
wb
|
37
|
+
.add_format(:bold, bold: true)
|
38
|
+
.add_worksheet
|
39
|
+
.set_column(0, 0, width: 36, format: :bold)
|
40
|
+
end
|
41
|
+
|
42
|
+
test('optimize23', constant_memory: true) do |wb|
|
43
|
+
wb
|
44
|
+
.add_format(:bold, bold: true)
|
45
|
+
.add_worksheet
|
46
|
+
.set_row(0, height: 20, format: :bold)
|
47
|
+
end
|
48
|
+
|
49
|
+
test('optimize24', constant_memory: true) do |wb|
|
50
|
+
wb
|
51
|
+
.add_format(:bold, bold: true)
|
52
|
+
.add_worksheet
|
53
|
+
.set_row(0, height: 20, format: :bold)
|
54
|
+
.write_string(0, 0, 'Foo')
|
55
|
+
end
|
56
|
+
|
57
|
+
test('optimize25', constant_memory: true) do |wb|
|
58
|
+
wb
|
59
|
+
.add_format(:bold, bold: true)
|
60
|
+
.add_worksheet
|
61
|
+
.set_row(0, height: 20, format: :bold)
|
62
|
+
.write_string(2, 0, 'Foo')
|
63
|
+
end
|
64
|
+
|
65
|
+
test('optimize26', constant_memory: true) do |wb|
|
66
|
+
wb.add_worksheet.write_string(2, 2, 'café')
|
67
|
+
end
|
34
68
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './xlsx-func-testcase'
|
4
|
+
|
5
|
+
class TestOutline < XlsxWriterTestCase
|
6
|
+
test 'outline01' do |wb, t|
|
7
|
+
t.ignore_files << 'xl/calcChain.xml' << '[Content_Types].xml' << 'xl/_rels/workbook.xml.rels'
|
8
|
+
|
9
|
+
wb.add_format(:bold, bold: true)
|
10
|
+
ws = wb.add_worksheet 'Outlined Rows'
|
11
|
+
ws.set_column('A', 'A', width: 20)
|
12
|
+
(1..10).each do |i|
|
13
|
+
ws.set_row i, level: (i % 5 == 0 ? 1 : 2)
|
14
|
+
end
|
15
|
+
|
16
|
+
write_common_data(ws)
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'outline02' do |wb, t|
|
20
|
+
t.ignore_files << 'xl/calcChain.xml' << '[Content_Types].xml' << 'xl/_rels/workbook.xml.rels'
|
21
|
+
|
22
|
+
wb.add_format(:bold, bold: true)
|
23
|
+
ws = wb.add_worksheet 'Collapsed Rows'
|
24
|
+
(1..10).each do |i|
|
25
|
+
ws.set_row i, level: (i % 5 == 0 ? 1 : 2), hide: true
|
26
|
+
end
|
27
|
+
ws.set_row 11, collapse: true
|
28
|
+
|
29
|
+
ws.set_column('A', 'A', width: 20)
|
30
|
+
ws.set_selection('A14:A14')
|
31
|
+
|
32
|
+
write_common_data(ws)
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'outline03' do |wb, t|
|
36
|
+
t.ignore_files << 'xl/calcChain.xml' << '[Content_Types].xml' << 'xl/_rels/workbook.xml.rels'
|
37
|
+
|
38
|
+
wb.add_format(:bold, bold: true)
|
39
|
+
ws = wb.add_worksheet 'Outline Columns'
|
40
|
+
|
41
|
+
%w(Month Jan Feb Mar Apr May Jun Total).each_with_index { |s, i| ws.write_string 0, i, s }
|
42
|
+
[
|
43
|
+
['North', [50, 20, 15, 25, 65, 80]],
|
44
|
+
['South', [10, 20, 30, 50, 50, 50]],
|
45
|
+
['East', [45, 75, 50, 15, 75, 100]],
|
46
|
+
['West', [15, 15, 55, 35, 20, 50]],
|
47
|
+
].each_with_index do |(d, vals), i|
|
48
|
+
ws.write_string(i+1, 0, d)
|
49
|
+
vals.each_with_index { |v, j| ws.write_number(i+1, j+1, v) }
|
50
|
+
ws.write_formula_num(i+1, vals.size + 1, "=SUM(B#{i+2}:G#{i+2})", vals.reduce(:+))
|
51
|
+
end
|
52
|
+
ws.write_formula_num('H6', "=SUM(H2:H5)", 1015, :bold)
|
53
|
+
ws.set_row 0, format: :bold
|
54
|
+
ws.set_column 'A', 'A', width: 10, format: :bold
|
55
|
+
ws.set_column 'H', 'H', width: 10
|
56
|
+
ws.set_column 'B', 'G', width: 6, level: 1
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'outline04' do |wb, t|
|
60
|
+
t.ignore_files << 'xl/calcChain.xml' << '[Content_Types].xml' << 'xl/_rels/workbook.xml.rels'
|
61
|
+
|
62
|
+
ws = wb.add_worksheet 'Outline levels'
|
63
|
+
13.times { |i| ws.write_string i, 0, "Level #{(i > 6 ? 13 - i : i + 1)}" }
|
64
|
+
13.times { |i| ws.set_row i, level: (i > 6 ? 13 - i : i + 1) }
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'outline05' do |wb, t|
|
68
|
+
t.ignore_files << 'xl/calcChain.xml' << '[Content_Types].xml' << 'xl/_rels/workbook.xml.rels'
|
69
|
+
|
70
|
+
wb.add_format(:bold, bold: true)
|
71
|
+
ws = wb.add_worksheet 'Collapsed Rows'
|
72
|
+
ws.set_column('A', 'A', width: 20)
|
73
|
+
ws.set_selection 'A14:A14'
|
74
|
+
(1..10).each do |i|
|
75
|
+
ws.set_row i, level: (i % 5 == 0 ? 1 : 2), hide: true, collapse: (i % 5 == 0)
|
76
|
+
end
|
77
|
+
ws.set_row 11, collapse: true
|
78
|
+
|
79
|
+
write_common_data(ws)
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'outline06' do |wb, t|
|
83
|
+
t.ignore_files << 'xl/calcChain.xml' << '[Content_Types].xml' << 'xl/_rels/workbook.xml.rels'
|
84
|
+
|
85
|
+
wb.add_format(:bold, bold: true)
|
86
|
+
ws = wb.add_worksheet 'Outlined Rows'
|
87
|
+
ws.outline_settings = { visible: false, symbols_below: false, symbols_right: false, auto_style: true }
|
88
|
+
ws.set_column('A', 'A', width: 20)
|
89
|
+
(1..10).each do |i|
|
90
|
+
ws.set_row i, level: (i % 5 == 0 ? 1 : 2)
|
91
|
+
end
|
92
|
+
|
93
|
+
write_common_data(ws)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def write_common_data(ws)
|
99
|
+
ws
|
100
|
+
.write_string('A1', 'Region', :bold)
|
101
|
+
.write_string('A2', 'North')
|
102
|
+
.write_string('A3', 'North')
|
103
|
+
.write_string('A4', 'North')
|
104
|
+
.write_string('A5', 'North')
|
105
|
+
.write_string('A6', 'North Total', :bold)
|
106
|
+
.write_string('B1', 'Sales', :bold)
|
107
|
+
.write_number('B2', 1000)
|
108
|
+
.write_number('B3', 1200)
|
109
|
+
.write_number('B4', 900)
|
110
|
+
.write_number('B5', 1200)
|
111
|
+
.write_formula_num('B6', '=SUBTOTAL(9,B2:B5)', 4300, :bold)
|
112
|
+
.write_string('A7', 'South')
|
113
|
+
.write_string('A8', 'South')
|
114
|
+
.write_string('A9', 'South')
|
115
|
+
.write_string('A10', 'South')
|
116
|
+
.write_string('A11', 'South Total', :bold)
|
117
|
+
.write_number('B7', 400)
|
118
|
+
.write_number('B8', 600)
|
119
|
+
.write_number('B9', 500)
|
120
|
+
.write_number('B10', 600)
|
121
|
+
.write_formula_num('B11', '=SUBTOTAL(9,B7:B10)', 2100, :bold)
|
122
|
+
.write_string('A12', 'Grand Total', :bold)
|
123
|
+
.write_formula_num('B12', '=SUBTOTAL(9,B2:B10)', 6400, :bold)
|
124
|
+
end
|
125
|
+
end
|
data/test/xlsx-func-testcase.rb
CHANGED
@@ -17,12 +17,13 @@ class XlsxWriterTestCase < Test::Unit::TestCase
|
|
17
17
|
def self.test(name, opts=nil, &block)
|
18
18
|
define_method(:"test_#{name}") do
|
19
19
|
file_path = "tmp/#{name}.xlsx"
|
20
|
-
|
20
|
+
ref_name = opts && opts.delete(:ref_file_name) || name
|
21
|
+
ref_file_path = "ext/xlsxwriter/libxlsxwriter/test/functional/xlsx_files/#{ref_name}.xlsx"
|
21
22
|
begin
|
22
23
|
tc = XlsxWriterTestCaseConfig.new
|
23
24
|
args = [file_path, opts].compact
|
24
25
|
XlsxWriter::Workbook.open(*args) do |wb|
|
25
|
-
|
26
|
+
instance_exec(wb, tc, &block)
|
26
27
|
end
|
27
28
|
|
28
29
|
assert_xlsx_equal file_path, ref_file_path, tc.ignore_files, tc.ignore_elements
|
@@ -32,7 +33,7 @@ class XlsxWriterTestCase < Test::Unit::TestCase
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
+
def image_path(path)
|
36
37
|
File.expand_path(File.join('../../ext/xlsxwriter/libxlsxwriter/test/functional/src/images', path), __FILE__)
|
37
38
|
end
|
38
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlsxwriter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick H
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- ext/xlsxwriter/worksheet.c
|
137
137
|
- ext/xlsxwriter/worksheet.h
|
138
138
|
- ext/xlsxwriter/xlsxwriter.c
|
139
|
+
- ext/xlsxwriter/xlsxwriter_ext.h
|
139
140
|
- lib/xlsxwriter.rb
|
140
141
|
- lib/xlsxwriter/version.rb
|
141
142
|
- lib/xlsxwriter/worksheet.rb
|
@@ -152,6 +153,7 @@ files:
|
|
152
153
|
- test/test-chart-scatter.rb
|
153
154
|
- test/test-chart-size.rb
|
154
155
|
- test/test-chart-title.rb
|
156
|
+
- test/test-data-validation.rb
|
155
157
|
- test/test-data.rb
|
156
158
|
- test/test-default-row.rb
|
157
159
|
- test/test-defined-name.rb
|
@@ -165,6 +167,7 @@ files:
|
|
165
167
|
- test/test-merge-range.rb
|
166
168
|
- test/test-misc.rb
|
167
169
|
- test/test-optimize.rb
|
170
|
+
- test/test-outline.rb
|
168
171
|
- test/test-page-breaks.rb
|
169
172
|
- test/test-page-setup.rb
|
170
173
|
- test/test-panes.rb
|
@@ -234,6 +237,7 @@ test_files:
|
|
234
237
|
- test/test-chart-size.rb
|
235
238
|
- test/test-hyperlink.rb
|
236
239
|
- test/test-array-formula.rb
|
240
|
+
- test/test-outline.rb
|
237
241
|
- test/test-print-options.rb
|
238
242
|
- test/test-optimize.rb
|
239
243
|
- test/test-print-scale.rb
|
@@ -244,4 +248,5 @@ test_files:
|
|
244
248
|
- test/test-chart-title.rb
|
245
249
|
- test/test-fit-to-pages.rb
|
246
250
|
- test/test-properties.rb
|
251
|
+
- test/test-data-validation.rb
|
247
252
|
- test/test-data.rb
|