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()-'
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.
- #workbook ⇒ Object readonly
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
breaks
to the worksheet. -
#hide ⇒ self
Hide the worksheet.
-
#hide_zero ⇒ Object
Hides all zero values.
-
#horizontal_dpi ⇒ Integer
Returns the horizontal dpi.
-
#horizontal_dpi=(dpi) ⇒ Object
Sets the horizontal dpi.
-
#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
). -
#insert_image_buffer(*args) ⇒ Object
Adds data validation or limits user input to a list of values.
-
#merge_range(*args) ⇒ Object
Merges
range
, setting stringvalue
withformat
. -
#outline_settings=(opts) ⇒ Object
Sets the Outline and Grouping display properties.
-
#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 opening 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. -
#vba_name=(name) ⇒ Object
Set the VBA name for 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_rich_string(*args) ⇒ Object
Writes a
rich_string
value into acell
. -
#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:
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 |
# 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);
rb_check_arity(argc, 1, 2);
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
6 7 8 |
# File 'lib/xlsxwriter/worksheet.rb', line 6 def col_auto_widths @col_auto_widths end |
#current_row ⇒ Object (readonly)
Last row number written with #add_row
6 7 8 |
# File 'lib/xlsxwriter/worksheet.rb', line 6 def current_row @current_row end |
#workbook ⇒ Object (readonly)
Instance Method Details
#activate ⇒ self
Set the worksheet to be active on opening the workbook.
766 767 768 769 770 |
# File 'ext/xlsxwriter/worksheet.c', line 766 VALUE worksheet_activate_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, activate); 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.
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 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 |
# File 'ext/xlsxwriter/worksheet.c', line 1244
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
.
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/xlsxwriter/worksheet.rb', line 20 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 nil 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)
750 751 752 753 754 755 756 757 758 759 760 |
# File 'ext/xlsxwriter/worksheet.c', line 750
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);
LXW_NO_RESULT_CALL(worksheet, autofilter, 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
1030 1031 1032 1033 1034 |
# File 'ext/xlsxwriter/worksheet.c', line 1030 VALUE worksheet_center_horizontally_(VALUE self){ LXW_NO_RESULT_CALL(worksheet, center_horizontally); return self; } |
#center_vertically ⇒ Object
Center the worksheet data vertically between the margins on the printed page
1037 1038 1039 1040 1041 |
# File 'ext/xlsxwriter/worksheet.c', line 1037 VALUE worksheet_center_vertically_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, center_vertically); return self; } |
#fit_to_pages(width, height) ⇒ self
Fits the printed area to a specific number of pages both vertically and horizontally.
1094 1095 1096 1097 1098 |
# File 'ext/xlsxwriter/worksheet.c', line 1094
VALUE
worksheet_fit_to_pages_(VALUE self, VALUE width, VALUE height) {
LXW_NO_RESULT_CALL(worksheet, fit_to_pages, NUM2INT(width), NUM2INT(height));
return self;
}
|
#free ⇒ Object
:nodoc:
77 78 79 80 81 82 83 84 |
# File 'ext/xlsxwriter/worksheet.c', line 77
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.
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
# File 'ext/xlsxwriter/worksheet.c', line 815
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.
1023 1024 1025 1026 1027 |
# File 'ext/xlsxwriter/worksheet.c', line 1023
VALUE
worksheet_gridlines_(VALUE self, VALUE value) {
LXW_NO_RESULT_CALL(worksheet, gridlines, NUM2INT(value));
return value;
}
|
#h_pagebreaks=(breaks) ⇒ Object
Adds horizontal page breaks
to the worksheet.
wb.h_pagebreaks = [20, 40, 80]
968 969 970 971 972 973 974 975 976 977 978 979 |
# File 'ext/xlsxwriter/worksheet.c', line 968
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;
LXW_NO_RESULT_CALL(worksheet, set_h_pagebreaks, rows);
return val;
}
|
#hide ⇒ self
Hide the worksheet.
786 787 788 789 790 |
# File 'ext/xlsxwriter/worksheet.c', line 786 VALUE worksheet_hide_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, hide); return self; } |
#hide_zero ⇒ Object
Hides all zero values.
1128 1129 1130 1131 1132 |
# File 'ext/xlsxwriter/worksheet.c', line 1128 VALUE worksheet_hide_zero_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, hide_zero); return self; } |
#horizontal_dpi ⇒ Integer
Returns the horizontal dpi.
1194 1195 1196 1197 1198 1199 |
# File 'ext/xlsxwriter/worksheet.c', line 1194
VALUE
worksheet_get_horizontal_dpi_(VALUE self) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
return INT2NUM(ptr->worksheet->horizontal_dpi);
}
|
#horizontal_dpi=(dpi) ⇒ Object
Sets the horizontal dpi.
1205 1206 1207 1208 1209 1210 1211 |
# File 'ext/xlsxwriter/worksheet.c', line 1205
VALUE
worksheet_set_horizontal_dpi_(VALUE self, VALUE val) {
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
ptr->worksheet->horizontal_dpi = NUM2INT(val);
return val;
}
|
#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.
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
# File 'ext/xlsxwriter/worksheet.c', line 662
VALUE
worksheet_insert_chart_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE chart, opts = Qnil;
lxw_chart_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_chart_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).
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 605 |
# File 'ext/xlsxwriter/worksheet.c', line 569
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;
}
|
#insert_image_buffer(cell, data, options) ⇒ self #insert_image_buffer(row, col, data, options) ⇒ self
Adds data validation or limits user input to a list of values.
613 614 615 616 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 644 645 646 647 648 649 650 651 652 |
# File 'ext/xlsxwriter/worksheet.c', line 613
VALUE
worksheet_insert_image_buffer_(int argc, VALUE *argv, VALUE self) {
lxw_row_t row;
lxw_col_t col;
VALUE data = 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) {
data = argv[larg];
++larg;
} else {
rb_raise(rb_eArgError, "Cannot embed image without data");
}
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);
}
lxw_error error;
if (with_options) {
error = worksheet_insert_image_buffer_opt(ptr->worksheet, row, col, (const unsigned char *) RSTRING_PTR(data), RSTRING_LEN(data), &options);
} else {
error = worksheet_insert_image_buffer(ptr->worksheet, row, col, (const unsigned char *) RSTRING_PTR(data), RSTRING_LEN(data));
}
handle_lxw_error(error);
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)
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'ext/xlsxwriter/worksheet.c', line 714
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;
}
LXW_NO_RESULT_CALL(worksheet, merge_range, row1, col1, row2, col2, str, format);
return self;
}
|
#outline_settings=(opts) ⇒ Object
Sets the Outline and Grouping display properties.
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 |
# File 'ext/xlsxwriter/worksheet.c', line 1164
VALUE
worksheet_outline_settings_(VALUE self, VALUE opts) {
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
LXW_NO_RESULT_CALL(worksheet, outline_settings, visible, symbols_below, symbols_right, auto_style);
return self;
}
|
#paper=(type) ⇒ Object
Sets the paper type
for printing. See libxlsxwriter doc for options.
906 907 908 909 910 |
# File 'ext/xlsxwriter/worksheet.c', line 906
VALUE
worksheet_set_paper_(VALUE self, VALUE paper_type) {
LXW_NO_RESULT_CALL(worksheet, set_paper, NUM2INT(paper_type));
return self;
}
|
#print_across ⇒ Object
Changes the default print direction
1001 1002 1003 1004 1005 |
# File 'ext/xlsxwriter/worksheet.c', line 1001 VALUE worksheet_print_across_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, print_across); 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.
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 |
# File 'ext/xlsxwriter/worksheet.c', line 1077
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);
LXW_NO_RESULT_CALL(worksheet, print_area, 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).
1044 1045 1046 1047 1048 |
# File 'ext/xlsxwriter/worksheet.c', line 1044 VALUE worksheet_print_row_col_headers_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, print_row_col_headers); return self; } |
#print_scale=(scale) ⇒ Object
Sets the scale
factor of the printed page (10 <= scale
<= 400).
1114 1115 1116 1117 1118 |
# File 'ext/xlsxwriter/worksheet.c', line 1114
VALUE
worksheet_set_print_scale_(VALUE self, VALUE scale) {
LXW_NO_RESULT_CALL(worksheet, set_print_scale, NUM2INT(scale));
return scale;
}
|
#protect(password[, opts]) ⇒ self
Protects the worksheet elements from modification. See libxlsxwriter doc for options.
1152 1153 1154 1155 1156 1157 1158 |
# File 'ext/xlsxwriter/worksheet.c', line 1152
VALUE
worksheet_protect_(int argc, VALUE *argv, VALUE self) {
rb_check_arity(argc, 0, 2);
struct _protect_options po = _extract_protect_options(argc, argv);
LXW_NO_RESULT_CALL(worksheet, protect, po.password, (po.with_options ? &po.options : NULL));
return self;
}
|
#repeat_columns(col_from, col_to) ⇒ Object
Sets columns to be repeatedly printed out on all pages.
1064 1065 1066 1067 1068 |
# File 'ext/xlsxwriter/worksheet.c', line 1064
VALUE
worksheet_repeat_columns_(VALUE self, VALUE col_from, VALUE col_to) {
LXW_NO_RESULT_CALL(worksheet, repeat_columns, 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.
1054 1055 1056 1057 1058 |
# File 'ext/xlsxwriter/worksheet.c', line 1054
VALUE
worksheet_repeat_rows_(VALUE self, VALUE row_from, VALUE row_to) {
LXW_NO_RESULT_CALL(worksheet, repeat_rows, 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).
1121 1122 1123 1124 1125 |
# File 'ext/xlsxwriter/worksheet.c', line 1121 VALUE worksheet_right_to_left_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, right_to_left); return self; } |
#select ⇒ self
Set the worksheet to be selected on opening the workbook.
776 777 778 779 780 |
# File 'ext/xlsxwriter/worksheet.c', line 776 VALUE worksheet_select_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, select); return self; } |
#set_column(col_from, col_to, width: nil, format: nil, hide: nil) ⇒ self
Set properties of the cols range.
516 517 518 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 556 557 |
# File 'ext/xlsxwriter/worksheet.c', line 516
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.
1183 1184 1185 1186 1187 1188 |
# File 'ext/xlsxwriter/worksheet.c', line 1183
VALUE
worksheet_set_default_row_(VALUE self, VALUE height, VALUE hide_unused_rows) {
uint8_t hide_ur = !NIL_P(hide_unused_rows) && hide_unused_rows != Qfalse ? 1 : 0;
LXW_NO_RESULT_CALL(worksheet, set_default_row, 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).
797 798 799 800 801 |
# File 'ext/xlsxwriter/worksheet.c', line 797 VALUE worksheet_set_first_sheet_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, set_first_sheet); return self; } |
#set_footer(text, opts) ⇒ Object
See #set_header for params description.
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 |
# File 'ext/xlsxwriter/worksheet.c', line 946
VALUE
worksheet_set_footer_(int argc, VALUE *argv, VALUE self) {
struct worksheet *ptr;
rb_check_arity(argc, 1, 2);
struct _header_options ho = _extract_header_options(argc, argv);
Data_Get_Struct(self, struct worksheet, ptr);
lxw_error err;
if (!ho.with_options) {
err = worksheet_set_footer(ptr->worksheet, ho.str);
} else {
err = worksheet_set_footer_opt(ptr->worksheet, ho.str, &ho.options);
}
handle_lxw_error(err);
return self;
}
|
#set_header(text[, opts]) ⇒ self
See libxlsxwriter doc for the text
control characters.
Currently the only supported option is :margin
(Numeric).
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
# File 'ext/xlsxwriter/worksheet.c', line 926
VALUE
worksheet_set_header_(int argc, VALUE *argv, VALUE self) {
rb_check_arity(argc, 1, 2);
struct _header_options ho = _extract_header_options(argc, argv);
struct worksheet *ptr;
Data_Get_Struct(self, struct worksheet, ptr);
lxw_error err;
if (!ho.with_options) {
err = worksheet_set_header(ptr->worksheet, ho.str);
} else {
err = worksheet_set_header_opt(ptr->worksheet, ho.str, &ho.options);
}
handle_lxw_error(err);
return self;
}
|
#set_landscape ⇒ self
Sets print orientation of the worksheet to landscape.
876 877 878 879 880 |
# File 'ext/xlsxwriter/worksheet.c', line 876 VALUE worksheet_set_landscape_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, set_landscape); return self; } |
#set_margins(left, right, top, bottom) ⇒ Object
Sets the worksheet margins (Numeric) for the printed page.
913 914 915 916 917 |
# File 'ext/xlsxwriter/worksheet.c', line 913
VALUE
worksheet_set_margins_(VALUE self, VALUE left, VALUE right, VALUE top, VALUE bottom) {
LXW_NO_RESULT_CALL(worksheet, set_margins, NUM2DBL(left), NUM2DBL(right), NUM2DBL(top), NUM2DBL(bottom));
return self;
}
|
#set_page_view ⇒ self
Sets worksheet displa mode to “Page View/Layout”.
896 897 898 899 900 |
# File 'ext/xlsxwriter/worksheet.c', line 896 VALUE worksheet_set_page_view_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, set_page_view); return self; } |
#set_portrait ⇒ self
Sets print orientation of the worksheet to portrait.
886 887 888 889 890 |
# File 'ext/xlsxwriter/worksheet.c', line 886 VALUE worksheet_set_portrait_(VALUE self) { LXW_NO_RESULT_CALL(worksheet, set_portrait); return self; } |
#set_row(row, height: nil, format: nil, hide: false) ⇒ self
Set properties of the row.
471 472 473 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 508 509 510 |
# File 'ext/xlsxwriter/worksheet.c', line 471
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)
860 861 862 863 864 865 866 867 868 869 870 |
# File 'ext/xlsxwriter/worksheet.c', line 860
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);
LXW_NO_RESULT_CALL(worksheet, set_selection, 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.
843 844 845 846 847 |
# File 'ext/xlsxwriter/worksheet.c', line 843
VALUE
worksheet_split_panes_(VALUE self, VALUE vertical, VALUE horizontal) {
LXW_NO_RESULT_CALL(worksheet, split_panes, NUM2DBL(vertical), NUM2DBL(horizontal));
return self;
}
|
#start_page=(page) ⇒ Object
Set the number of the first printed page.
1104 1105 1106 1107 1108 |
# File 'ext/xlsxwriter/worksheet.c', line 1104
VALUE
worksheet_set_start_page_(VALUE self, VALUE start_page) {
LXW_NO_RESULT_CALL(worksheet, set_start_page, NUM2INT(start_page));
return start_page;
}
|
#tab_color=(color) ⇒ Object
Set the tab color (from RGB integer).
ws.tab_color = 0xF0F0F0
1140 1141 1142 1143 1144 |
# File 'ext/xlsxwriter/worksheet.c', line 1140
VALUE
worksheet_set_tab_color_(VALUE self, VALUE color) {
LXW_NO_RESULT_CALL(worksheet, set_tab_color, NUM2INT(color));
return color;
}
|
#h_pagebreaks=(breaks) ⇒ Object
Adds vertical page breaks
to the worksheet.
wb.v_pagebreaks = [20, 40, 80]
987 988 989 990 991 992 993 994 995 996 997 998 |
# File 'ext/xlsxwriter/worksheet.c', line 987
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;
LXW_NO_RESULT_CALL(worksheet, set_v_pagebreaks, cols);
return val;
}
|
#vba_name=(name) ⇒ Object
Set the VBA name for the worksheet.
1403 1404 1405 1406 1407 |
# File 'ext/xlsxwriter/worksheet.c', line 1403
VALUE
worksheet_set_vba_name_(VALUE self, VALUE name) {
LXW_ERR_RESULT_CALL(worksheet, set_vba_name, StringValueCStr(name));
return name;
}
|
#vertical_dpi ⇒ Integer
Returns the vertical dpi.
1217 1218 1219 1220 1221 1222 |
# File 'ext/xlsxwriter/worksheet.c', line 1217
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.
1228 1229 1230 1231 1232 1233 1234 |
# File 'ext/xlsxwriter/worksheet.c', line 1228
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
.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'ext/xlsxwriter/worksheet.c', line 201
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;
}
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_array_formula, 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
.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'ext/xlsxwriter/worksheet.c', line 364
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;
}
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_blank, 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
.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'ext/xlsxwriter/worksheet.c', line 332
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;
}
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_boolean, 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
.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'ext/xlsxwriter/worksheet.c', line 234
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);
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_datetime, 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
.
167 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 |
# File 'ext/xlsxwriter/worksheet.c', line 167
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);
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_formula, 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
.
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/xlsxwriter/worksheet.c', line 390
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);
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_formula_num, 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
.
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 |
# File 'ext/xlsxwriter/worksheet.c', line 134
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);
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_number, 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
.
429 430 431 432 433 434 435 436 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 |
# File 'ext/xlsxwriter/worksheet.c', line 429
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");
}
lxw_format *format = workbook_get_format(workbook, format_key);
lxw_rich_string_tuple **rich_string = serialize_rich_string(value);
if (rich_string) {
LXW_ERR_RESULT_CALL(worksheet, write_rich_string, row, col, rich_string, 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
.
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 126 |
# File 'ext/xlsxwriter/worksheet.c', line 101
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);
VALUE workbook = rb_iv_get(self, "@workbook");
lxw_format *format = workbook_get_format(workbook, format_key);
LXW_NO_RESULT_CALL(worksheet, write_string, 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
.
267 268 269 270 271 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 |
# File 'ext/xlsxwriter/worksheet.c', line 267
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.
1011 1012 1013 1014 1015 |
# File 'ext/xlsxwriter/worksheet.c', line 1011
VALUE
worksheet_set_zoom_(VALUE self, VALUE val) {
LXW_NO_RESULT_CALL(worksheet, set_zoom, NUM2INT(val));
return self;
}
|