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 mimicing axlsx behaviour
'^.acfijklrstxzFIJL()-'.freeze
Instance Attribute Summary collapse
-
#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_row(row, style: nil, height: nil, types: nil) ⇒ 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.
-
#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
breaks
to 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
fname
into the worksheet (atcell
). -
#insert_image(*args) ⇒ Object
Inserts image from
fname
into the worksheet (atcell
). -
#merge_range(*args) ⇒ Object
Merges
range
, setting stringvalue
withformat
. -
#paper=(type) ⇒ Object
Sets the paper
type
for 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
scale
factor 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
text
control 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
range
on 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
breaks
to 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
formula
into a cellrange
withformat
. -
#write_blank(*args) ⇒ Object
Make a
cell
blank withformat
. -
#write_boolean(*args) ⇒ Object
Writes a boolean
value
into acell
withformat
. -
#write_datetime(*args) ⇒ Object
Writes a datetime
value
into acell
withformat
. -
#write_formula(*args) ⇒ Object
Writes a
formula
into acell
withformat
. -
#write_formula_num(*args) ⇒ Object
Writes a
formula
withvalue
into acell
withformat
. -
#write_number(*args) ⇒ Object
Writes a number
value
into acell
withformat
. -
#write_string(*args) ⇒ Object
Writes a string
value
into acell
withformat
. -
#write_url(*args) ⇒ Object
Writes a
url
into acell
withformat
. -
#zoom=(zoom) ⇒ Object
Sets the worksheet zoom factor in the range 10 <=
zoom
<= 400.
Constructor Details
#initialize(*args) ⇒ Object
:nodoc:
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 |
# File 'ext/xlsxwriter/worksheet.c', line 24
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);
return self;
}
|
Instance Attribute Details
#current_row ⇒ Object (readonly)
Last row number written with #add_row
3 4 5 |
# File 'lib/xlsxwriter/worksheet.rb', line 3 def current_row @current_row end |
Instance Method Details
#activate ⇒ self
Set the worksheet to be active on opening the workbook.
675 676 677 678 679 680 |
# File 'ext/xlsxwriter/worksheet.c', line 675
VALUE worksheet_activate_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
worksheet_activate(ptr->worksheet);
return self;
}
|
#add_row(row, style: nil, height: nil, types: nil) ⇒ 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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/xlsxwriter/worksheet.rb', line 14 def add_row(row, style: nil, height: nil, types: nil) row_idx = @current_row ||= 0 @current_row += 1 row.each_with_index do |value, idx| cell_style = style.is_a?(Array) ? style[idx] : style cell_type = types.is_a?(Array) ? types[idx] : types case cell_type && cell_type.to_sym when :string write_string(row_idx, idx, value.to_s, cell_style) update_col_auto_width(idx, value.to_s, 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 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 '', nil write_blank(row_idx, idx, cell_style) when /\A=/ write_formula(row_idx, idx, value, cell_style) else if value.is_a?(Time) || (defined?(Date) && value.is_a?(Date)) || (defined?(DateTime) && value.is_a?(DateTime)) write_datetime(row_idx, idx, value.to_time, cell_style) else # assume string write_string(row_idx, idx, value.to_s, cell_style) update_col_auto_width(idx, value.to_s, cell_style) end end else raise ArgumentError, "Unknown cell type #{cell_type}." end set_row(row_idx, height: height) if height nil end end |
#apply_auto_widths ⇒ Object
Apply cols automatic widths calculated by #add_row.
70 71 72 73 74 |
# File 'lib/xlsxwriter/worksheet.rb', line 70 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)
656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'ext/xlsxwriter/worksheet.c', line 656
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
982 983 984 985 986 987 988 |
# File 'ext/xlsxwriter/worksheet.c', line 982
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
991 992 993 994 995 996 997 |
# File 'ext/xlsxwriter/worksheet.c', line 991
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.
1059 1060 1061 1062 1063 1064 1065 |
# File 'ext/xlsxwriter/worksheet.c', line 1059
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:
74 75 76 77 78 79 80 81 |
# File 'ext/xlsxwriter/worksheet.c', line 74
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.
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
# File 'ext/xlsxwriter/worksheet.c', line 730
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;
}
|
#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.
971 972 973 974 975 976 977 978 979 |
# File 'ext/xlsxwriter/worksheet.c', line 971
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]
910 911 912 913 914 915 916 917 918 919 920 921 922 |
# File 'ext/xlsxwriter/worksheet.c', line 910
VALUE
worksheet_set_h_pagebreaks_(VALUE self, VALUE val) {
const size_t len = RARRAY_LEN(val);
lxw_row_t rows[len+1];
for (size_t 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.
697 698 699 700 701 702 703 |
# File 'ext/xlsxwriter/worksheet.c', line 697
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.
1101 1102 1103 1104 1105 1106 1107 |
# File 'ext/xlsxwriter/worksheet.c', line 1101
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.
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'ext/xlsxwriter/worksheet.c', line 565
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 (
:offset
for both; Integer). - :scale, :x_scale, :y_scale
-
Image scale (
:scale
for both; Numeric).
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'ext/xlsxwriter/worksheet.c', line 519
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)
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'ext/xlsxwriter/worksheet.c', line 617
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;
}
|
#paper=(type) ⇒ Object
Sets the paper type
for printing. See libxlsxwriter doc for options.
832 833 834 835 836 837 838 |
# File 'ext/xlsxwriter/worksheet.c', line 832
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
945 946 947 948 949 950 951 |
# File 'ext/xlsxwriter/worksheet.c', line 945
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.
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
# File 'ext/xlsxwriter/worksheet.c', line 1039
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).
1000 1001 1002 1003 1004 1005 1006 |
# File 'ext/xlsxwriter/worksheet.c', line 1000
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).
1083 1084 1085 1086 1087 1088 1089 |
# File 'ext/xlsxwriter/worksheet.c', line 1083
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.
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 |
# File 'ext/xlsxwriter/worksheet.c', line 1129
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.
1024 1025 1026 1027 1028 1029 1030 |
# File 'ext/xlsxwriter/worksheet.c', line 1024
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.
1012 1013 1014 1015 1016 1017 1018 |
# File 'ext/xlsxwriter/worksheet.c', line 1012
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).
1092 1093 1094 1095 1096 1097 1098 |
# File 'ext/xlsxwriter/worksheet.c', line 1092
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.
686 687 688 689 690 691 |
# File 'ext/xlsxwriter/worksheet.c', line 686
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.
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'ext/xlsxwriter/worksheet.c', line 474
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;
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (options.hidden) {
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.
1198 1199 1200 1201 1202 1203 1204 1205 |
# File 'ext/xlsxwriter/worksheet.c', line 1198
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).
710 711 712 713 714 715 716 |
# File 'ext/xlsxwriter/worksheet.c', line 710
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.
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
# File 'ext/xlsxwriter/worksheet.c', line 882
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).
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
# File 'ext/xlsxwriter/worksheet.c', line 856
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.
796 797 798 799 800 801 802 |
# File 'ext/xlsxwriter/worksheet.c', line 796
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.
841 842 843 844 845 846 847 |
# File 'ext/xlsxwriter/worksheet.c', line 841
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”.
820 821 822 823 824 825 826 |
# File 'ext/xlsxwriter/worksheet.c', line 820
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.
808 809 810 811 812 813 814 |
# File 'ext/xlsxwriter/worksheet.c', line 808
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.
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'ext/xlsxwriter/worksheet.c', line 437
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;
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
if (options.hidden) {
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)
777 778 779 780 781 782 783 784 785 786 787 788 789 790 |
# File 'ext/xlsxwriter/worksheet.c', line 777
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.
758 759 760 761 762 763 764 |
# File 'ext/xlsxwriter/worksheet.c', line 758
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.
1071 1072 1073 1074 1075 1076 1077 |
# File 'ext/xlsxwriter/worksheet.c', line 1071
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
1115 1116 1117 1118 1119 1120 1121 |
# File 'ext/xlsxwriter/worksheet.c', line 1115
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]
930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'ext/xlsxwriter/worksheet.c', line 930
VALUE
worksheet_set_v_pagebreaks_(VALUE self, VALUE val) {
const size_t len = RARRAY_LEN(val);
lxw_col_t cols[len+1];
for (size_t 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.
1211 1212 1213 1214 1215 1216 |
# File 'ext/xlsxwriter/worksheet.c', line 1211
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.
1222 1223 1224 1225 1226 1227 1228 |
# File 'ext/xlsxwriter/worksheet.c', line 1222
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
.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'ext/xlsxwriter/worksheet.c', line 204
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;
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;
}
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_datetime(cell, format = nil) ⇒ self #write_datetime(row, col, format = nil) ⇒ self
Make a cell
blank with format
.
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'ext/xlsxwriter/worksheet.c', line 371
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
.
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'ext/xlsxwriter/worksheet.c', line 337
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
.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'ext/xlsxwriter/worksheet.c', line 237
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
.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'ext/xlsxwriter/worksheet.c', line 168
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
.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'ext/xlsxwriter/worksheet.c', line 399
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
.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'ext/xlsxwriter/worksheet.c', line 133
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_string(cell, value, format = nil) ⇒ self #write_string(row, col, value, format = nil) ⇒ self
Writes a string value
into a cell
with format
.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/xlsxwriter/worksheet.c', line 98
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
.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'ext/xlsxwriter/worksheet.c', line 272
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.
957 958 959 960 961 962 963 |
# File 'ext/xlsxwriter/worksheet.c', line 957
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;
}
|