Class: XlsxWriter::Worksheet
- Inherits:
-
Object
- Object
- XlsxWriter::Worksheet
- Defined in:
- lib/xlsxwriter/worksheet.rb,
ext/xlsxwriter/worksheet.c
Constant Summary collapse
- THIN_CHARS =
Thiner characters list used for column width logic mimicking axlsx behaviour
'^.acfijklrstxzFIJL()-'.freeze
Instance Attribute Summary collapse
-
#col_auto_widths ⇒ Object
readonly
Last row number written with #add_row.
-
#current_row ⇒ Object
readonly
Last row number written with #add_row.
Instance Method Summary collapse
-
#activate ⇒ self
Set the worksheet to be active on opening the workbook.
-
#add_data_validation(*args) ⇒ Object
Adds data validation or limits user input to a list of values.
-
#add_row(row, style: nil, height: nil, types: nil, skip_empty: false) ⇒ Object
Write a
row. -
#apply_auto_widths ⇒ Object
Apply cols automatic widths calculated by #add_row.
-
#autofilter(*args) ⇒ Object
Applies autofilter to the
range. -
#center_horizontally ⇒ Object
Center the worksheet data horizontally between the margins on the printed page.
-
#center_vertically ⇒ Object
Center the worksheet data vertically between the margins on the printed page.
-
#fit_to_pages(width, height) ⇒ self
Fits the printed area to a specific number of pages both vertically and horizontally.
-
#free ⇒ Object
:nodoc:.
-
#freeze_panes(*args) ⇒ Object
Divides the worksheet into horizontal or vertical panes and freezes them.
- #get_column_auto_width(col) ⇒ Object
-
#gridlines=(option) ⇒ Object
Display or hide screen and print gridlines using one of the values XlsxWriter::Worksheet::GRIDLINES_SHOW_SCREEN, GRIDLINES_SHOW_PRINT, GRIDLINES_SHOW_ALL.
-
#h_pagebreaks=(breaks) ⇒ Object
Adds horizontal page
breaksto the worksheet. -
#hide ⇒ self
Hide the worksheet.
-
#hide_zero ⇒ Object
Hides all zero values.
-
#initialize(*args) ⇒ Object
constructor
:nodoc:.
-
#insert_chart(*args) ⇒ Object
Inserts chart from
fnameinto the worksheet (atcell). -
#insert_image(*args) ⇒ Object
Inserts image from
fnameinto the worksheet (atcell). -
#merge_range(*args) ⇒ Object
Merges
range, setting stringvaluewithformat. -
#outline_settings=(opts) ⇒ Object
Sets the Outline and Grouping display properties.
-
#paper=(type) ⇒ Object
Sets the paper
typefor printing. -
#print_across ⇒ Object
Changes the default print direction.
-
#print_area(*args) ⇒ Object
Specifies area of the worksheet to be printed.
-
#print_row_col_headers ⇒ Object
Print rows and column header (wich is disabled by default).
-
#print_scale=(scale) ⇒ Object
Sets the
scalefactor of the printed page (10 <=scale<= 400). -
#protect(password[, opts]) ⇒ self
Protects the worksheet elements from modification.
-
#repeat_columns(col_from, col_to) ⇒ Object
Sets columns to be repeatedly printed out on all pages.
-
#repeat_rows(row_from, row_to) ⇒ Object
Sets rows to be repeatedly printed out on all pages.
-
#right_to_left ⇒ Object
Sets text direction to rtl (e.g. for worksheets on Hebrew or Arabic).
-
#select ⇒ self
Set the worksheet to be selected on openong the workbook.
-
#set_column(col_from, col_to, width: nil, format: nil, hide: nil) ⇒ self
Set properties of the cols range.
-
#set_default_row(height, hide_unuser_rows) ⇒ self
Sets the default row properties for the worksheet.
-
#set_fitst_sheet ⇒ self
Set the sheet to be the first visible in the sheets list (which is placed under the work area in Excel).
-
#set_footer(text, opts) ⇒ Object
See #set_header for params description.
-
#set_header(text, opts) ⇒ self
See libxlsxwriter doc for the
textcontrol characters. -
#set_landscape ⇒ self
Sets print orientation of the worksheet to landscape.
-
#set_margins(left, right, top, bottom) ⇒ Object
Sets the worksheet margins (Numeric) for the printed page.
-
#set_page_view ⇒ self
Sets worksheet displa mode to “Page View/Layout”.
-
#set_portrait ⇒ self
Sets print orientation of the worksheet to portrait.
-
#set_row(row, height: nil, format: nil, hide: false) ⇒ self
Set properties of the row.
-
#set_selection(*args) ⇒ Object
Selects the specified
rangeon the worksheet. -
#split_panes(vertical, horizontal) ⇒ self
Divides the worksheet int vertical and horizontal panes with respective positions from parameters (Numeric).
-
#start_page=(page) ⇒ Object
Set the number of the first printed page.
-
#tab_color=(color) ⇒ Object
Set the tab color (from RGB integer).
-
#h_pagebreaks=(breaks) ⇒ Object
Adds vertical page
breaksto the worksheet. -
#vertical_dpi ⇒ Integer
Returns the vertical dpi.
-
#vertical_dpi=(dpi) ⇒ Object
Sets the vertical dpi.
-
#write_array_formula(*args) ⇒ Object
Writes an array
formulainto a cellrangewithformat. -
#write_blank(*args) ⇒ Object
Make a
cellblank withformat. -
#write_boolean(*args) ⇒ Object
Writes a boolean
valueinto acellwithformat. -
#write_datetime(*args) ⇒ Object
Writes a datetime
valueinto acellwithformat. -
#write_formula(*args) ⇒ Object
Writes a
formulainto acellwithformat. -
#write_formula_num(*args) ⇒ Object
Writes a
formulawithvalueinto acellwithformat. -
#write_number(*args) ⇒ Object
Writes a number
valueinto acellwithformat. -
#write_rich_string(*args) ⇒ Object
Writes a
rich_stringvalue into acell. -
#write_string(*args) ⇒ Object
Writes a string
valueinto acellwithformat. -
#write_url(*args) ⇒ Object
Writes a
urlinto acellwithformat. -
#zoom=(zoom) ⇒ Object
Sets the worksheet zoom factor in the range 10 <=
zoom<= 400.
Constructor Details
#initialize(*args) ⇒ Object
:nodoc:
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'ext/xlsxwriter/worksheet.c', line 26
VALUE
worksheet_init(int argc, VALUE *argv, VALUE self) {
char *name = NULL;
VALUE opts = Qnil;
VALUE auto_width = Qtrue;
struct workbook *wb_ptr;
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (argc > 2 || argc < 1) {
rb_raise(rb_eArgError, "wrong number of arguments");
} else if (argc == 2) {
switch (TYPE(argv[1])) {
case T_HASH:
opts = argv[1];
break;
case T_STRING:
case T_SYMBOL:
name = StringValueCStr(argv[1]);
break;
case T_NIL:
break;
default:
rb_raise(rb_eArgError, "wrong type of name");
break;
}
}
if (!NIL_P(opts)) {
VALUE val = rb_hash_aref(opts, ID2SYM(rb_intern("auto_width")));
if (val == Qfalse) {
auto_width = Qfalse;
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("name")));
if (!NIL_P(val) && !name) {
name = StringValueCStr(val);
}
}
rb_iv_set(self, "@workbook", argv[0]);
rb_iv_set(self, "@use_auto_width", auto_width);
rb_iv_set(self, "@col_auto_widths", rb_ary_new());
Data_Get_Struct(argv[0], struct workbook, wb_ptr);
ptr->worksheet = workbook_add_worksheet(wb_ptr->workbook, name);
if (!ptr->worksheet)
rb_raise(eXlsxWriterError, "worksheet was not created");
return self;
}
|
Instance Attribute Details
#col_auto_widths ⇒ Object (readonly)
Last row number written with #add_row
7 8 9 |
# File 'lib/xlsxwriter/worksheet.rb', line 7 def col_auto_widths @col_auto_widths end |
#current_row ⇒ Object (readonly)
Last row number written with #add_row
7 8 9 |
# File 'lib/xlsxwriter/worksheet.rb', line 7 def current_row @current_row end |
Instance Method Details
#activate ⇒ self
Set the worksheet to be active on opening the workbook.
745 746 747 748 749 750 751 |
# File 'ext/xlsxwriter/worksheet.c', line 745
VALUE
worksheet_activate_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_activate(ptr->worksheet);
return self;
}
|
#add_data_validation(cell, options) ⇒ self #add_data_validation(range, options) ⇒ self #add_data_validation(row, col, options) ⇒ self #add_data_validation(row_from, col_from, row_to, col_to, options) ⇒ self
Adds data validation or limits user input to a list of values.
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 |
# File 'ext/xlsxwriter/worksheet.c', line 1333
VALUE
worksheet_data_validation_(int argc, VALUE *argv, VALUE self) {
lxw_data_validation data_validation = {0};
rb_check_arity(argc, 2, 5);
char range = 0;
if (argc > 3) {
range = 1;
} else if (TYPE(argv[0]) == T_STRING) {
char *str = RSTRING_PTR(argv[0]);
if (strstr(str, ":")) {
range = 1;
} else if ((str[0] >= 'A' && str[0] <= 'Z') ||
(str[0] >= 'a' && str[0] <= 'z'))
range = argc > 2;
}
lxw_row_t row, row2;
lxw_col_t col, col2;
int larg;
if (range) {
larg = extract_range(argc, argv, &row, &col, &row2, &col2);
} else {
larg = extract_cell(argc, argv, &row, &col);
}
if (larg != argc - 1) {
rb_raise(rb_eArgError, "Wrong number of arguments");
}
VALUE opts = argv[larg];
if (TYPE(opts) != T_HASH) {
rb_raise(rb_eTypeError, "Wrong type for options %"PRIsVALUE", Hash expected", rb_obj_class(opts));
}
VALUE val;
val = rb_hash_aref(opts, ID2SYM(rb_intern("validate")));
if (!NIL_P(val)) {
data_validation.validate = NUM2INT(val);
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("criteria")));
if (!NIL_P(val)) {
data_validation.criteria = NUM2INT(val);
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("ignore_blank")));
if (!NIL_P(val) && val) {
data_validation.ignore_blank = LXW_VALIDATION_ON;
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("show_input")));
if (!NIL_P(val) && val) {
data_validation.show_input = LXW_VALIDATION_ON;
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("show_error")));
if (!NIL_P(val) && val) {
data_validation.show_error = LXW_VALIDATION_ON;
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("error_type")));
if (!NIL_P(val)) {
data_validation.error_type = NUM2INT(val);
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("dropdown")));
if (!NIL_P(val) && val) {
data_validation.dropdown = LXW_VALIDATION_ON;
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("input_title")));
if (!NIL_P(val)) {
data_validation.input_title = RSTRING_PTR(val);
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("input_message")));
if (!NIL_P(val)) {
data_validation.input_message = RSTRING_PTR(val);
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("error_title")));
if (!NIL_P(val)) {
data_validation.error_title = RSTRING_PTR(val);
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("error_message")));
if (!NIL_P(val)) {
data_validation.error_message = RSTRING_PTR(val);
}
VALUE is_datetime;
#define parse_array_0(x)
#define parse_array_1(prefix) \
if (TYPE(val) == T_ARRAY) { \
int len = RARRAY_LEN(val); \
int i; \
data_validation.prefix##_list = malloc(sizeof(char *) * (len + 1)); \
data_validation.prefix##_list[len] = NULL; \
for (i = 0; i < len; ++i) { \
data_validation.prefix##_list[i] = RSTRING_PTR(rb_ary_entry(val, i)); \
} \
} else
#define parse_value(prefix, key, handle_array) \
val = rb_hash_aref(opts, ID2SYM(rb_intern(key))); \
if (!NIL_P(val)) { \
switch(TYPE(val)) { \
case T_FLOAT: case T_FIXNUM: case T_BIGNUM: \
data_validation.prefix##_number = NUM2DBL(val); \
break; \
case T_STRING: \
data_validation.prefix##_formula = RSTRING_PTR(val); \
if (data_validation.prefix##_formula[0] != '=') { \
data_validation.prefix##_formula = 0; \
rb_raise(rb_eArgError, "Is not a formula: %"PRIsVALUE, val); \
} \
break; \
default: \
is_datetime = rb_funcall(val, rb_intern("is_a?"), 1, rb_cTime); \
parse_array_##handle_array(prefix) \
if (is_datetime || rb_respond_to(val, rb_intern("to_time"))) { \
if (!is_datetime) \
val = rb_funcall(val, rb_intern("to_time"), 0); \
data_validation.prefix##_datetime = value_to_lxw_datetime(val); \
} else { \
rb_raise(rb_eTypeError, "Cannot handle " key " type %"PRIsVALUE, rb_class_of(val)); \
} \
} \
}
parse_value(minimum, "min", 0);
parse_value(maximum, "max", 0);
parse_value(value, "value", 1);
#undef parse_array_0
#undef parse_array_1
#undef parse_value
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
lxw_error err;
if (range) {
err = worksheet_data_validation_range(ptr->worksheet, row, col, row2, col2, &data_validation);
} else {
err = worksheet_data_validation_cell(ptr->worksheet, row, col, &data_validation);
}
if (data_validation.value_list) {
free(data_validation.value_list);
}
handle_lxw_error(err);
return self;
}
|
#add_row(row, style: nil, height: nil, types: nil, skip_empty: false) ⇒ Object
Write a row. If no types passed XlsxWriter tries to deduce them automatically.
Both types and style may be an array as well as a symbol. In the latter case they are applied to all cells in the row.
height is a Numeric that specifies the row height.
If skip_empty is set to true empty cells are not added to the sheet. Otherwise they are added with type :blank.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/xlsxwriter/worksheet.rb', line 21 def add_row(row, style: nil, height: nil, types: nil, skip_empty: false) row_idx = @current_row ||= 0 @current_row += 1 style_ary = style if style.is_a?(Array) types_ary = types if types.is_a?(Array) row.each_with_index do |value, idx| cell_style = style_ary ? style_ary[idx] : style cell_type = types_ary ? types_ary[idx] : types case cell_type && cell_type.to_sym when :string value = value.to_s write_string(row_idx, idx, value, cell_style) update_col_auto_width(idx, value, cell_style) when :rich_string write_rich_string(row_idx, idx, value, cell_style) when :number write_number(row_idx, idx, value.to_f, cell_style) when :formula write_formula(row_idx, idx, value, cell_style) when :datetime, :date, :time write_datetime(row_idx, idx, value.to_time, cell_style) when :url write_url(row_idx, idx, value, cell_style) update_col_auto_width(idx, value.to_s, cell_style) when :boolean write_boolean(row_idx, idx, value, cell_style) when :blank write_blank(row_idx, idx, cell_style) when :skip, :empty # write nothing when nil case value when Numeric write_number(row_idx, idx, value, cell_style) when TrueClass, FalseClass write_boolean(row_idx, idx, value, cell_style) when Time, (defined?(Date) ? Date : Time) write_datetime(row_idx, idx, value, cell_style) when '', nil write_blank(row_idx, idx, cell_style) unless skip_empty when /\A=/ write_formula(row_idx, idx, value, cell_style) when String write_string(row_idx, idx, value, cell_style) update_col_auto_width(idx, value, cell_style) when RichString write_rich_string(row_idx, idx, value, cell_style) else # assume string value = value.to_s write_string(row_idx, idx, value, cell_style) update_col_auto_width(idx, value, cell_style) end else raise ArgumentError, "Unknown cell type #{cell_type}." end end set_row(row_idx, height: height) if height nil end |
#apply_auto_widths ⇒ Object
Apply cols automatic widths calculated by #add_row.
87 88 89 90 91 |
# File 'lib/xlsxwriter/worksheet.rb', line 87 def apply_auto_widths @col_auto_widths.each_with_index do |width, idx| set_column(idx, idx, width: width) if width end end |
#autofilter(range) ⇒ self #autofilter(cell_from, cell_to) ⇒ self #autofilter(row_from, col_from, row_to, col_to) ⇒ self
Applies autofilter to the range.
ws.autofilter('A1:D5')
ws.autofilter('A1', 'D5')
ws.autofilter(0, 0, 4, 3)
726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'ext/xlsxwriter/worksheet.c', line 726
VALUE
worksheet_autofilter_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row_from, row_to;
lxw_col_t col_from, col_to;
rb_check_arity(argc, 1, 4);
extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_autofilter(ptr->worksheet, row_from, col_from, row_to, col_to);
return self;
}
|
#center_horizontally ⇒ Object
Center the worksheet data horizontally between the margins on the printed page
1056 1057 1058 1059 1060 1061 1062 |
# File 'ext/xlsxwriter/worksheet.c', line 1056
VALUE
worksheet_center_horizontally_(VALUE self){
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_center_horizontally(ptr->worksheet);
return self;
}
|
#center_vertically ⇒ Object
Center the worksheet data vertically between the margins on the printed page
1065 1066 1067 1068 1069 1070 1071 |
# File 'ext/xlsxwriter/worksheet.c', line 1065
VALUE
worksheet_center_vertically_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_center_vertically(ptr->worksheet);
return self;
}
|
#fit_to_pages(width, height) ⇒ self
Fits the printed area to a specific number of pages both vertically and horizontally.
1133 1134 1135 1136 1137 1138 1139 |
# File 'ext/xlsxwriter/worksheet.c', line 1133
VALUE
worksheet_fit_to_pages_(VALUE self, VALUE width, VALUE height) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_fit_to_pages(ptr->worksheet, NUM2INT(width), NUM2INT(height));
return self;
}
|
#free ⇒ Object
:nodoc:
78 79 80 81 82 83 84 85 |
# File 'ext/xlsxwriter/worksheet.c', line 78
VALUE
worksheet_release(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_free(ptr);
return self;
}
|
#freeze_panes(cell) ⇒ self #freeze_panes(row, col) ⇒ self
Divides the worksheet into horizontal or vertical panes and freezes them.
The specified cell is the top left in the right bottom pane.
In order to freeze only rows/cols pass 0 as row or col.
Advanced usage (with 2nd cell and type) is not documented yet.
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
# File 'ext/xlsxwriter/worksheet.c', line 802
VALUE
worksheet_freeze_panes_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row, row2;
lxw_col_t col, col2;
uint8_t type = 0;
rb_check_arity(argc, 1, 5);
int larg = extract_cell(argc, argv, &row, &col);
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (larg >= argc) {
worksheet_freeze_panes(ptr->worksheet, row, col);
} else {
larg += extract_cell(argc - larg, argv + larg, &row2, &col2);
if (larg < argc) {
type = NUM2INT(argv[larg]);
}
worksheet_freeze_panes_opt(ptr->worksheet, row, col, row2, col2, type);
}
return self;
}
|
#get_column_auto_width(col) ⇒ Object
93 94 95 |
# File 'lib/xlsxwriter/worksheet.rb', line 93 def get_column_auto_width(col) @col_auto_widths[extract_column(col)] end |
#gridlines=(option) ⇒ Object
Display or hide screen and print gridlines using one of the values XlsxWriter::Worksheet::GRIDLINES_SHOW_SCREEN, GRIDLINES_SHOW_PRINT, GRIDLINES_SHOW_ALL.
1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File 'ext/xlsxwriter/worksheet.c', line 1045
VALUE
worksheet_gridlines_(VALUE self, VALUE value) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_gridlines(ptr->worksheet, NUM2INT(value));
return value;
}
|
#h_pagebreaks=(breaks) ⇒ Object
Adds horizontal page breaks to the worksheet.
wb.h_pagebreaks = [20, 40, 80]
982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
# File 'ext/xlsxwriter/worksheet.c', line 982
VALUE
worksheet_set_h_pagebreaks_(VALUE self, VALUE val) {
const size_t len = RARRAY_LEN(val);
lxw_row_t rows[len+1];
size_t i;
for (i = 0; i<len; ++i) {
rows[i] = NUM2INT(rb_ary_entry(val, i));
}
rows[len] = 0;
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_h_pagebreaks(ptr->worksheet, rows);
return val;
}
|
#hide ⇒ self
Hide the worksheet.
769 770 771 772 773 774 775 |
# File 'ext/xlsxwriter/worksheet.c', line 769
VALUE
worksheet_hide_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_hide(ptr->worksheet);
return self;
}
|
#hide_zero ⇒ Object
Hides all zero values.
1175 1176 1177 1178 1179 1180 1181 |
# File 'ext/xlsxwriter/worksheet.c', line 1175
VALUE
worksheet_hide_zero_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_hide_zero(ptr->worksheet);
return self;
}
|
#insert_chart(cell, chart, opts = {}) ⇒ self #insert_chart(row, col, chart, opts = {}) ⇒ self
Inserts chart from fname into the worksheet (at cell).
For available opts see #insert_image.
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'ext/xlsxwriter/worksheet.c', line 635
VALUE
worksheet_insert_chart_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE chart, opts = Qnil;
lxw_image_options options;
char with_options = '\0';
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
chart = argv[larg];
++larg;
} else {
rb_raise(rb_eArgError, "No chart specified");
}
if (larg < argc) {
opts = argv[larg];
++larg;
}
if (!NIL_P(opts)) {
options = val_to_lxw_image_options(opts, &with_options);
}
struct worksheet *ptr;
struct chart *chart_ptr;
Data_Get_Struct(self, struct worksheet, ptr);
Data_Get_Struct(chart, struct chart, chart_ptr);
if (with_options) {
worksheet_insert_chart_opt(ptr->worksheet, row, col, chart_ptr->chart, &options);
} else {
worksheet_insert_chart(ptr->worksheet, row, col, chart_ptr->chart);
}
return self;
}
|
#insert_image(cell, fname, opts = {}) ⇒ self #insert_image(row, col, fname, opts = {}) ⇒ self
Inserts image from fname into the worksheet (at cell).
Available opts
- :offset, :x_offset, :y_offset
-
Image offset (
:offsetfor both; Integer). - :scale, :x_scale, :y_scale
-
Image scale (
:scalefor both; Numeric).
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'ext/xlsxwriter/worksheet.c', line 589
VALUE
worksheet_insert_image_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE fname = Qnil;
VALUE opts = Qnil;
lxw_image_options options;
char with_options = '\0';
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
fname = argv[larg];
++larg;
}
if (larg < argc) {
opts = argv[larg];
++larg;
}
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (!NIL_P(opts)) {
options = val_to_lxw_image_options(opts, &with_options);
}
if (with_options) {
worksheet_insert_image_opt(ptr->worksheet, row, col, StringValueCStr(fname), &options);
} else {
worksheet_insert_image(ptr->worksheet, row, col, StringValueCStr(fname));
}
return self;
}
|
#merge_range(range, value = "", format = nil) ⇒ self #merge_range(cell_from, cell_to, value = "", format = nil) ⇒ self #merge_range(row_from, col_from, row_to, col_to, value = "", format = nil) ⇒ self
Merges range, setting string value with format.
ws.merge_range('A1:D5')
ws.merge_range('A1', 'D5', 'Merged cells')
ws.merge_range(0, 0, 4, 3)
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'ext/xlsxwriter/worksheet.c', line 687
VALUE
worksheet_merge_range_(int argc, VALUE *argv, VALUE self) {
char *str = "";
lxw_format *format = NULL;
lxw_col_t col1, col2;
lxw_row_t row1, row2;
VALUE workbook = rb_iv_get(self, "@workbook");
rb_check_arity(argc, 1, 6);
int larg = extract_range(argc, argv, &row1, &col1, &row2, &col2);
if (larg < argc) {
str = StringValueCStr(argv[larg]);
++larg;
}
if (larg < argc) {
format = workbook_get_format(workbook, argv[larg]);
++larg;
}
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_merge_range(ptr->worksheet, row1, col1, row2, col2, str, format);
return self;
}
|
#outline_settings=(opts) ⇒ Object
Sets the Outline and Grouping display properties.
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 |
# File 'ext/xlsxwriter/worksheet.c', line 1272
VALUE
worksheet_outline_settings_(VALUE self, VALUE opts) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
VALUE value;
#define parse_param(name, default) \
value = rb_hash_aref(opts, ID2SYM(rb_intern(#name))); \
uint8_t name = NIL_P(value) ? default : (value ? LXW_TRUE : LXW_FALSE)
parse_param(visible, LXW_TRUE);
parse_param(symbols_below, LXW_TRUE);
parse_param(symbols_right, LXW_TRUE);
parse_param(auto_style, LXW_FALSE);
#undef parse_param
worksheet_outline_settings(ptr->worksheet, visible, symbols_below, symbols_right, auto_style);
return self;
}
|
#paper=(type) ⇒ Object
Sets the paper type for printing. See libxlsxwriter doc for options.
904 905 906 907 908 909 910 |
# File 'ext/xlsxwriter/worksheet.c', line 904
VALUE
worksheet_set_paper_(VALUE self, VALUE paper_type) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_paper(ptr->worksheet, NUM2INT(paper_type));
return self;
}
|
#print_across ⇒ Object
Changes the default print direction
1019 1020 1021 1022 1023 1024 1025 |
# File 'ext/xlsxwriter/worksheet.c', line 1019
VALUE
worksheet_print_across_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_print_across(ptr->worksheet);
return self;
}
|
#print_area(range) ⇒ Object #print_area(cell_from, cell_to) ⇒ Object #print_area(row_from, col_from, row_to, col_to) ⇒ Object
Specifies area of the worksheet to be printed.
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'ext/xlsxwriter/worksheet.c', line 1113
VALUE
worksheet_print_area_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row_from, row_to;
lxw_col_t col_from, col_to;
rb_check_arity(argc, 1, 4);
extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_print_area(ptr->worksheet, row_from, col_from, row_to, col_to);
return self;
}
|
#print_row_col_headers ⇒ Object
Print rows and column header (wich is disabled by default).
1074 1075 1076 1077 1078 1079 1080 |
# File 'ext/xlsxwriter/worksheet.c', line 1074
VALUE
worksheet_print_row_col_headers_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_print_row_col_headers(ptr->worksheet);
return self;
}
|
#print_scale=(scale) ⇒ Object
Sets the scale factor of the printed page (10 <= scale <= 400).
1157 1158 1159 1160 1161 1162 1163 |
# File 'ext/xlsxwriter/worksheet.c', line 1157
VALUE
worksheet_set_print_scale_(VALUE self, VALUE scale) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_print_scale(ptr->worksheet, NUM2INT(scale));
return scale;
}
|
#protect(password[, opts]) ⇒ self
Protects the worksheet elements from modification. See libxlsxwriter doc for options.
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 |
# File 'ext/xlsxwriter/worksheet.c', line 1203
VALUE
worksheet_protect_(int argc, VALUE *argv, VALUE self) {
rb_check_arity(argc, 0, 2);
uint8_t with_options = '\0';
VALUE val;
VALUE opts = Qnil;
// All options are off by default
lxw_protection options = {};
const char *password = NULL;
if (argc > 0 && !NIL_P(argv[0])) {
switch (TYPE(argv[0])) {
case T_STRING:
password = StringValueCStr(argv[0]);
break;
case T_HASH:
opts = argv[0];
break;
default:
rb_raise(rb_eArgError, "Wrong argument %"PRIsVALUE", expected a String or Hash", rb_obj_class(argv[0]));
}
}
if (argc > 1) {
if (TYPE(argv[1]) == T_HASH) {
opts = argv[1];
} else {
rb_raise(rb_eArgError, "Expected a Hash, but got %"PRIsVALUE, rb_obj_class(argv[1]));
}
}
if (!NIL_P(opts)) {
#define PR_OPT(field) { \
val = rb_hash_aref(opts, ID2SYM(rb_intern(#field))); \
if (!NIL_P(val) && val) { \
options.field = 1; \
with_options = 1; \
} \
}
PR_OPT(no_select_locked_cells);
PR_OPT(no_select_unlocked_cells);
PR_OPT(format_cells);
PR_OPT(format_columns);
PR_OPT(format_rows);
PR_OPT(insert_columns);
PR_OPT(insert_rows);
PR_OPT(insert_hyperlinks);
PR_OPT(delete_columns);
PR_OPT(delete_rows);
PR_OPT(sort);
PR_OPT(autofilter);
PR_OPT(pivot_tables);
PR_OPT(scenarios);
PR_OPT(objects);
#undef PR_OPT
}
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (with_options) {
worksheet_protect(ptr->worksheet, password, &options);
} else {
worksheet_protect(ptr->worksheet, password, NULL);
}
return self;
}
|
#repeat_columns(col_from, col_to) ⇒ Object
Sets columns to be repeatedly printed out on all pages.
1098 1099 1100 1101 1102 1103 1104 |
# File 'ext/xlsxwriter/worksheet.c', line 1098
VALUE
worksheet_repeat_columns_(VALUE self, VALUE col_from, VALUE col_to) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_repeat_columns(ptr->worksheet, value_to_col(col_from), value_to_col(col_to));
return self;
}
|
#repeat_rows(row_from, row_to) ⇒ Object
Sets rows to be repeatedly printed out on all pages.
1086 1087 1088 1089 1090 1091 1092 |
# File 'ext/xlsxwriter/worksheet.c', line 1086
VALUE
worksheet_repeat_rows_(VALUE self, VALUE row_from, VALUE row_to) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_repeat_rows(ptr->worksheet, NUM2INT(row_from), NUM2INT(row_to));
return self;
}
|
#right_to_left ⇒ Object
Sets text direction to rtl (e.g. for worksheets on Hebrew or Arabic).
1166 1167 1168 1169 1170 1171 1172 |
# File 'ext/xlsxwriter/worksheet.c', line 1166
VALUE
worksheet_right_to_left_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_right_to_left(ptr->worksheet);
return self;
}
|
#select ⇒ self
Set the worksheet to be selected on openong the workbook.
757 758 759 760 761 762 763 |
# File 'ext/xlsxwriter/worksheet.c', line 757
VALUE
worksheet_select_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_select(ptr->worksheet);
return self;
}
|
#set_column(col_from, col_to, width: nil, format: nil, hide: nil) ⇒ self
Set properties of the cols range.
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'ext/xlsxwriter/worksheet.c', line 536
VALUE
worksheet_set_column_(VALUE self, VALUE col_from, VALUE col_to, VALUE opts) {
double width = LXW_DEF_COL_WIDTH;
lxw_format *format = NULL;
lxw_row_col_options options = {
.hidden = 0,
.collapsed = 0,
.level = 0
};
VALUE val;
lxw_col_t col1 = value_to_col(col_from);
lxw_col_t col2 = value_to_col(col_to);
VALUE workbook = rb_iv_get(self, "@workbook");
val = rb_hash_aref(opts, ID2SYM(rb_intern("width")));
if (val != Qnil)
width = NUM2DBL(val);
val = rb_hash_aref(opts, ID2SYM(rb_intern("format")));
format = workbook_get_format(workbook, val);
val = rb_hash_aref(opts, ID2SYM(rb_intern("hide")));
if (val != Qnil && val)
options.hidden = 1;
val = rb_hash_aref(opts, ID2SYM(rb_intern("collapse")));
if (val != Qnil && val)
options.collapsed = 1;
val = rb_hash_aref(opts, ID2SYM(rb_intern("level")));
if (val != Qnil)
options.level = NUM2INT(val);
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (options.hidden || options.collapsed || options.level) {
worksheet_set_column_opt(ptr->worksheet, col1, col2, width, format, &options);
} else {
worksheet_set_column(ptr->worksheet, col1, col2, width, format);
}
return self;
}
|
#set_default_row(height, hide_unuser_rows) ⇒ self
Sets the default row properties for the worksheet.
1293 1294 1295 1296 1297 1298 1299 1300 |
# File 'ext/xlsxwriter/worksheet.c', line 1293
VALUE
worksheet_set_default_row_(VALUE self, VALUE height, VALUE hide_unused_rows) {
struct worksheet *ptr;
uint8_t hide_ur = !NIL_P(hide_unused_rows) && hide_unused_rows != Qfalse ? 1 : 0;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_default_row(ptr->worksheet, NUM2DBL(height), hide_ur);
return self;
}
|
#set_fitst_sheet ⇒ self
Set the sheet to be the first visible in the sheets list (which is placed under the work area in Excel).
782 783 784 785 786 787 788 |
# File 'ext/xlsxwriter/worksheet.c', line 782
VALUE
worksheet_set_first_sheet_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_first_sheet(ptr->worksheet);
return self;
}
|
#set_footer(text, opts) ⇒ Object
See #set_header for params description.
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'ext/xlsxwriter/worksheet.c', line 954
VALUE
worksheet_set_footer_(VALUE self, VALUE val, VALUE opts) {
const char *str = StringValueCStr(val);
lxw_header_footer_options options = { .margin = 0.0 };
char with_options = '\0';
if (!NIL_P(opts)) {
VALUE margin = rb_hash_aref(opts, ID2SYM(rb_intern("margin")));
if (!NIL_P(margin)) {
with_options = '\1';
options.margin = NUM2DBL(margin);
}
}
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (with_options) {
worksheet_set_footer(ptr->worksheet, str);
} else {
worksheet_set_footer_opt(ptr->worksheet, str, &options);
}
return self;
}
|
#set_header(text, opts) ⇒ self
See libxlsxwriter doc for the text control characters.
Currently the only supported option is :margin (Numeric).
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 |
# File 'ext/xlsxwriter/worksheet.c', line 928
VALUE
worksheet_set_header_(VALUE self, VALUE val, VALUE opts) {
const char *str = StringValueCStr(val);
lxw_header_footer_options options = { .margin = 0.0 };
char with_options = '\0';
if (!NIL_P(opts)) {
VALUE margin = rb_hash_aref(opts, ID2SYM(rb_intern("margin")));
if (!NIL_P(margin)) {
with_options = '\1';
options.margin = NUM2DBL(margin);
}
}
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (with_options) {
worksheet_set_header(ptr->worksheet, str);
} else {
worksheet_set_header_opt(ptr->worksheet, str, &options);
}
return self;
}
|
#set_landscape ⇒ self
Sets print orientation of the worksheet to landscape.
868 869 870 871 872 873 874 |
# File 'ext/xlsxwriter/worksheet.c', line 868
VALUE
worksheet_set_landscape_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_landscape(ptr->worksheet);
return self;
}
|
#set_margins(left, right, top, bottom) ⇒ Object
Sets the worksheet margins (Numeric) for the printed page.
913 914 915 916 917 918 919 |
# File 'ext/xlsxwriter/worksheet.c', line 913
VALUE
worksheet_set_margins_(VALUE self, VALUE left, VALUE right, VALUE top, VALUE bottom) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_margins(ptr->worksheet, NUM2DBL(left), NUM2DBL(right), NUM2DBL(top), NUM2DBL(bottom));
return self;
}
|
#set_page_view ⇒ self
Sets worksheet displa mode to “Page View/Layout”.
892 893 894 895 896 897 898 |
# File 'ext/xlsxwriter/worksheet.c', line 892
VALUE
worksheet_set_page_view_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_page_view(ptr->worksheet);
return self;
}
|
#set_portrait ⇒ self
Sets print orientation of the worksheet to portrait.
880 881 882 883 884 885 886 |
# File 'ext/xlsxwriter/worksheet.c', line 880
VALUE
worksheet_set_portrait_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_portrait(ptr->worksheet);
return self;
}
|
#set_row(row, height: nil, format: nil, hide: false) ⇒ self
Set properties of the row.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'ext/xlsxwriter/worksheet.c', line 491
VALUE
worksheet_set_row_(VALUE self, VALUE row, VALUE opts) {
double height = LXW_DEF_ROW_HEIGHT;
lxw_format *format = NULL;
lxw_row_col_options options = {
.hidden = 0,
.collapsed = 0,
.level = 0
};
VALUE val;
VALUE workbook = rb_iv_get(self, "@workbook");
val = rb_hash_aref(opts, ID2SYM(rb_intern("height")));
if (val != Qnil)
height = NUM2DBL(val);
val = rb_hash_aref(opts, ID2SYM(rb_intern("format")));
format = workbook_get_format(workbook, val);
val = rb_hash_aref(opts, ID2SYM(rb_intern("hide")));
if (val != Qnil && val)
options.hidden = 1;
val = rb_hash_aref(opts, ID2SYM(rb_intern("collapse")));
if (val != Qnil && val)
options.collapsed = 1;
val = rb_hash_aref(opts, ID2SYM(rb_intern("level")));
if (val != Qnil)
options.level = NUM2INT(val);
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (options.hidden || options.collapsed || options.level) {
worksheet_set_row_opt(ptr->worksheet, NUM2INT(row), height, format, &options);
} else {
worksheet_set_row(ptr->worksheet, NUM2INT(row), height, format);
}
return self;
}
|
#set_selection(range) ⇒ self #set_selection(cell_from, cell_to) ⇒ self #set_selection(row_from, col_from, row_to, col_to) ⇒ self
Selects the specified range on the worksheet.
ws.set_selection('A1:G5')
ws.set_selection('A1', 'G5')
ws.set_selection(0, 0, 4, 6)
849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
# File 'ext/xlsxwriter/worksheet.c', line 849
VALUE
worksheet_set_selection_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row_from, row_to;
lxw_col_t col_from, col_to;
rb_check_arity(argc, 1, 4);
extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_selection(ptr->worksheet, row_from, col_from, row_to, col_to);
return self;
}
|
#split_panes(vertical, horizontal) ⇒ self
Divides the worksheet int vertical and horizontal panes with respective positions from parameters (Numeric).
If only one split is desired pass 0 for other.
830 831 832 833 834 835 836 |
# File 'ext/xlsxwriter/worksheet.c', line 830
VALUE
worksheet_split_panes_(VALUE self, VALUE vertical, VALUE horizontal) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_split_panes(ptr->worksheet, NUM2DBL(vertical), NUM2DBL(horizontal));
return self;
}
|
#start_page=(page) ⇒ Object
Set the number of the first printed page.
1145 1146 1147 1148 1149 1150 1151 |
# File 'ext/xlsxwriter/worksheet.c', line 1145
VALUE
worksheet_set_start_page_(VALUE self, VALUE start_page) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_start_page(ptr->worksheet, NUM2INT(start_page));
return start_page;
}
|
#tab_color=(color) ⇒ Object
Set the tab color (from RGB integer).
ws.tab_color = 0xF0F0F0
1189 1190 1191 1192 1193 1194 1195 |
# File 'ext/xlsxwriter/worksheet.c', line 1189
VALUE
worksheet_set_tab_color_(VALUE self, VALUE color) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_tab_color(ptr->worksheet, NUM2INT(color));
return color;
}
|
#h_pagebreaks=(breaks) ⇒ Object
Adds vertical page breaks to the worksheet.
wb.v_pagebreaks = [20, 40, 80]
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'ext/xlsxwriter/worksheet.c', line 1003
VALUE
worksheet_set_v_pagebreaks_(VALUE self, VALUE val) {
const size_t len = RARRAY_LEN(val);
lxw_col_t cols[len+1];
size_t i;
for (i = 0; i<len; ++i) {
cols[i] = value_to_col(rb_ary_entry(val, i));
}
cols[len] = 0;
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_v_pagebreaks(ptr->worksheet, cols);
return val;
}
|
#vertical_dpi ⇒ Integer
Returns the vertical dpi.
1306 1307 1308 1309 1310 1311 |
# File 'ext/xlsxwriter/worksheet.c', line 1306
VALUE
worksheet_get_vertical_dpi_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
return INT2NUM(ptr->worksheet->vertical_dpi);
}
|
#vertical_dpi=(dpi) ⇒ Object
Sets the vertical dpi.
1317 1318 1319 1320 1321 1322 1323 |
# File 'ext/xlsxwriter/worksheet.c', line 1317
VALUE
worksheet_set_vertical_dpi_(VALUE self, VALUE val) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
ptr->worksheet->vertical_dpi = NUM2INT(val);
return val;
}
|
#write_array_formula(range, formula, format = nil) ⇒ self #write_array_formula(cell_from, cell_to, formula, format = nil) ⇒ self #write_array_formula(row_from, col_from, row_to, col_to, formula, format = nil) ⇒ self
Writes an array formula into a cell range with format.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'ext/xlsxwriter/worksheet.c', line 208
VALUE worksheet_write_array_formula_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row_from, row_to;
lxw_col_t col_from, col_to;
const char *str = NULL;
VALUE format_key = Qnil;
rb_check_arity(argc, 2, 6);
int larg = extract_range(argc, argv, &row_from, &col_from, &row_to, &col_to);
if (larg < argc) {
str = StringValueCStr(argv[larg]);
++larg;
} else {
rb_raise(rb_eArgError, "No formula specified");
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_array_formula(ptr->worksheet, row_from, col_from, row_to, col_to, str, format);
return self;
}
|
#write_blank(cell, format = nil) ⇒ self #write_blank(row, col, format = nil) ⇒ self
Make a cell blank with format.
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'ext/xlsxwriter/worksheet.c', line 377
VALUE
worksheet_write_blank_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE format_key = Qnil;
rb_check_arity(argc, 1, 3);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
format_key = argv[larg];
++larg;
}
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_blank(ptr->worksheet, row, col, format);
return self;
}
|
#write_boolean(cell, value, format = nil) ⇒ self #write_boolean(row, col, value, format = nil) ⇒ self
Writes a boolean value into a cell with format.
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'ext/xlsxwriter/worksheet.c', line 343
VALUE
worksheet_write_boolean_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
int bool_value = 0;
VALUE format_key = Qnil;
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
bool_value = argv[larg] && !NIL_P(argv[larg]);
++larg;
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_boolean(ptr->worksheet, row, col, bool_value, format);
return self;
}
|
#write_datetime(cell, value, format = nil) ⇒ self #write_datetime(row, col, value, format = nil) ⇒ self
Writes a datetime value into a cell with format.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'ext/xlsxwriter/worksheet.c', line 243
VALUE
worksheet_write_datetime_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE value = Qnil;
VALUE format_key = Qnil;
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
value = argv[larg];
++larg;
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
struct lxw_datetime datetime = value_to_lxw_datetime(value);
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_datetime(ptr->worksheet, row, col, &datetime, format);
return self;
}
|
#write_formula(cell, formula, format = nil) ⇒ self #write_formula(row, col, formula, format = nil) ⇒ self
Writes a formula into a cell with format.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/xlsxwriter/worksheet.c', line 172
VALUE
worksheet_write_formula_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE value = Qnil;
VALUE format_key = Qnil;
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
value = argv[larg];
++larg;
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
const char *str = RSTRING_PTR(value);
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_formula(ptr->worksheet, row, col, str, format);
return self;
}
|
#write_formula_num(cell, formula, value, format = nil) ⇒ self #write_formula_num(row, col, formula, value, format = nil) ⇒ self
Writes a formula with value into a cell with format.
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'ext/xlsxwriter/worksheet.c', line 405
VALUE
worksheet_write_formula_num_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE formula = Qnil;
VALUE value = Qnil;
VALUE format_key = Qnil;
rb_check_arity(argc, 3, 5);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
formula = argv[larg];
++larg;
}
if (larg < argc) {
value = argv[larg];
++larg;
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
const char *str = RSTRING_PTR(formula);
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_formula_num(ptr->worksheet, row, col, str, format, NUM2DBL(value));
return self;
}
|
#number_string(cell, value, format = nil) ⇒ self #number_string(row, col, value, format = nil) ⇒ self
Writes a number value into a cell with format.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'ext/xlsxwriter/worksheet.c', line 137
VALUE
worksheet_write_number_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE value = Qnil;
VALUE format_key = Qnil;
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
value = argv[larg];
++larg;
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
const double num = NUM2DBL(value);
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_number(ptr->worksheet, row, col, num, format);
return self;
}
|
#write_rich_string(cell, value) ⇒ self #write_rich_string(row, col, value) ⇒ self
Writes a rich_string value into a cell.
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'ext/xlsxwriter/worksheet.c', line 446
VALUE
worksheet_write_rich_string_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE value = Qnil;
VALUE format_key = Qnil;
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
VALUE workbook = rb_iv_get(self, "@workbook");
if (larg < argc) {
value = argv[larg];
if (TYPE(value) == T_ARRAY)
value = rb_funcall(cRichString, rb_intern("new"), 2, workbook, value);
else if (rb_class_of(value) != cRichString) {
rb_raise(rb_eArgError, "Wrong type of value: %"PRIsVALUE, rb_class_of(value));
}
++larg;
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
if (NIL_P(value)) {
rb_raise(rb_eArgError, "No value specified");
}
struct worksheet *ptr;
lxw_format *format = workbook_get_format(workbook, format_key);
lxw_rich_string_tuple **rich_string = serialize_rich_string(value);
if (rich_string) {
Data_Get_Struct(self, struct worksheet, ptr);
lxw_error err = worksheet_write_rich_string(ptr->worksheet, row, col, rich_string, format);
handle_lxw_error(err);
}
return self;
}
|
#write_string(cell, value, format = nil) ⇒ self #write_string(row, col, value, format = nil) ⇒ self
Writes a string value into a cell with format.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/xlsxwriter/worksheet.c', line 102
VALUE
worksheet_write_string_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE value = Qnil;
VALUE format_key = Qnil;
rb_check_arity(argc, 2, 4);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
value = argv[larg];
++larg;
}
if (larg < argc) {
format_key = argv[larg];
++larg;
}
const char *str = StringValueCStr(value);
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_write_string(ptr->worksheet, row, col, str, format);
return self;
}
|
#write_url(cell, url, format = nil, string: nil, tooltip: nil, format: nil) ⇒ self #write_url(row, col, url, format = nil, string: nil, tooltip: nil, format: nil) ⇒ self
Writes a url into a cell with format.
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'ext/xlsxwriter/worksheet.c', line 278
VALUE
worksheet_write_url_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE url = Qnil; //argv[2];
VALUE format_key = Qnil; // argv[3];
VALUE opts = Qnil;
rb_check_arity(argc, 2, 5);
int larg = extract_cell(argc, argv, &row, &col);
if (larg < argc) {
url = argv[larg];
++larg;
}
const char *url_str = RSTRING_PTR(url);
char *string = NULL;
char *tooltip = NULL;
while (larg < argc) {
switch(TYPE(argv[larg])) {
case T_HASH:
opts = argv[larg];
break;
case T_SYMBOL: case T_STRING: case T_NIL:
format_key = argv[larg];
break;
default:
rb_raise(rb_eTypeError, "Expected Hash, symbol or string but got %"PRIsVALUE, rb_obj_class(argv[larg]));
}
++larg;
}
if (!NIL_P(opts)) {
VALUE val;
val = rb_hash_aref(opts, ID2SYM(rb_intern("string")));
if (!NIL_P(val)) {
string = StringValueCStr(val);
}
val = rb_hash_aref(opts, ID2SYM(rb_intern("tooltip")));
if (!NIL_P(val)) {
tooltip = StringValueCStr(val);
}
if (NIL_P(format_key)) {
format_key = rb_hash_aref(opts, ID2SYM(rb_intern("format")));
}
}
struct worksheet *ptr;
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
Data_Get_Struct(self, struct worksheet, ptr);
if (string || tooltip) {
worksheet_write_url_opt(ptr->worksheet, row, col, url_str, format, string, tooltip);
} else {
worksheet_write_url(ptr->worksheet, row, col, url_str, format);
}
return self;
}
|
#zoom=(zoom) ⇒ Object
Sets the worksheet zoom factor in the range 10 <= zoom <= 400.
1031 1032 1033 1034 1035 1036 1037 |
# File 'ext/xlsxwriter/worksheet.c', line 1031
VALUE
worksheet_set_zoom_(VALUE self, VALUE val) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_set_zoom(ptr->worksheet, NUM2INT(val));
return self;
}
|