Class: XlsxWriter::Worksheet

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
72
73
# 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);
  if (!ptr->worksheet)
    rb_raise(rb_eRuntimeError, "worksheet was not created");
  return self;
}

Instance Attribute Details

#current_rowObject (readonly)

Last row number written with #add_row



5
6
7
# File 'lib/xlsxwriter/worksheet.rb', line 5

def current_row
  @current_row
end

Instance Method Details

#activateself

Set the worksheet to be active on opening the workbook.

Returns:

  • (self)


677
678
679
680
681
682
# File 'ext/xlsxwriter/worksheet.c', line 677

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, 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.



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
68
69
70
71
72
73
74
# File 'lib/xlsxwriter/worksheet.rb', line 19

def add_row(row, style: nil, height: nil, types: nil, skip_empty: false)
  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 :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 '', nil
        write_blank(row_idx, idx, cell_style) unless skip_empty
      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
  end

  set_row(row_idx, height: height) if height

  nil
end

#apply_auto_widthsObject

Apply cols automatic widths calculated by #add_row.



77
78
79
80
81
# File 'lib/xlsxwriter/worksheet.rb', line 77

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)

Overloads:

  • #autofilter(range) ⇒ self

    Returns:

    • (self)
  • #autofilter(cell_from, cell_to) ⇒ self

    Returns:

    • (self)
  • #autofilter(row_from, col_from, row_to, col_to) ⇒ self

    Returns:

    • (self)


658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'ext/xlsxwriter/worksheet.c', line 658

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_horizontallyObject

Center the worksheet data horizontally between the margins on the printed page



984
985
986
987
988
989
990
# File 'ext/xlsxwriter/worksheet.c', line 984

VALUE
worksheet_center_horizontally_(VALUE self){
  struct worksheet *ptr;
  Data_Get_Struct(self, struct worksheet, ptr);
  worksheet_center_horizontally(ptr->worksheet);
  return self;
}

#center_verticallyObject

Center the worksheet data vertically between the margins on the printed page



993
994
995
996
997
998
999
# File 'ext/xlsxwriter/worksheet.c', line 993

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.

Returns:

  • (self)


1061
1062
1063
1064
1065
1066
1067
# File 'ext/xlsxwriter/worksheet.c', line 1061

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;
}

#freeObject

:nodoc:



76
77
78
79
80
81
82
83
# File 'ext/xlsxwriter/worksheet.c', line 76

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.

Overloads:

  • #freeze_panes(cell) ⇒ self

    Returns:

    • (self)
  • #freeze_panes(row, col) ⇒ self

    Returns:

    • (self)


732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'ext/xlsxwriter/worksheet.c', line 732

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.



973
974
975
976
977
978
979
980
981
# File 'ext/xlsxwriter/worksheet.c', line 973

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]


912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'ext/xlsxwriter/worksheet.c', line 912

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;
}

#hideself

Hide the worksheet.

Returns:

  • (self)


699
700
701
702
703
704
705
# File 'ext/xlsxwriter/worksheet.c', line 699

VALUE
worksheet_hide_(VALUE self) {
  struct worksheet *ptr;
  Data_Get_Struct(self, struct worksheet, ptr);
  worksheet_hide(ptr->worksheet);
  return self;
}

#hide_zeroObject

Hides all zero values.



1103
1104
1105
1106
1107
1108
1109
# File 'ext/xlsxwriter/worksheet.c', line 1103

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.

Overloads:

  • #insert_chart(cell, chart, opts = {}) ⇒ self

    Returns:

    • (self)
  • #insert_chart(row, col, chart, opts = {}) ⇒ self

    Returns:

    • (self)


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
605
606
# File 'ext/xlsxwriter/worksheet.c', line 567

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).

Overloads:

  • #insert_image(cell, fname, opts = {}) ⇒ self

    Returns:

    • (self)
  • #insert_image(row, col, fname, opts = {}) ⇒ self

    Returns:

    • (self)


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 521

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)

Overloads:

  • #merge_range(range, value = "", format = nil) ⇒ self

    Returns:

    • (self)
  • #merge_range(cell_from, cell_to, value = "", format = nil) ⇒ self

    Returns:

    • (self)
  • #merge_range(row_from, col_from, row_to, col_to, value = "", format = nil) ⇒ self

    Returns:

    • (self)


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
# File 'ext/xlsxwriter/worksheet.c', line 619

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.



834
835
836
837
838
839
840
# File 'ext/xlsxwriter/worksheet.c', line 834

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;
}

Changes the default print direction



947
948
949
950
951
952
953
# File 'ext/xlsxwriter/worksheet.c', line 947

VALUE
worksheet_print_across_(VALUE self) {
  struct worksheet *ptr;
  Data_Get_Struct(self, struct worksheet, ptr);
  worksheet_print_across(ptr->worksheet);
  return self;
}

Specifies area of the worksheet to be printed.



1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
# File 'ext/xlsxwriter/worksheet.c', line 1041

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 rows and column header (wich is disabled by default).



1002
1003
1004
1005
1006
1007
1008
# File 'ext/xlsxwriter/worksheet.c', line 1002

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;
}

Sets the scale factor of the printed page (10 <= scale <= 400).



1085
1086
1087
1088
1089
1090
1091
# File 'ext/xlsxwriter/worksheet.c', line 1085

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.

Returns:

  • (self)


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
1193
1194
# File 'ext/xlsxwriter/worksheet.c', line 1131

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.



1026
1027
1028
1029
1030
1031
1032
# File 'ext/xlsxwriter/worksheet.c', line 1026

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.



1014
1015
1016
1017
1018
1019
1020
# File 'ext/xlsxwriter/worksheet.c', line 1014

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_leftObject

Sets text direction to rtl (e.g. for worksheets on Hebrew or Arabic).



1094
1095
1096
1097
1098
1099
1100
# File 'ext/xlsxwriter/worksheet.c', line 1094

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;
}

#selectself

Set the worksheet to be selected on openong the workbook.

Returns:

  • (self)


688
689
690
691
692
693
# File 'ext/xlsxwriter/worksheet.c', line 688

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.

Returns:

  • (self)


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
# File 'ext/xlsxwriter/worksheet.c', line 476

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.

Returns:

  • (self)


1200
1201
1202
1203
1204
1205
1206
1207
# File 'ext/xlsxwriter/worksheet.c', line 1200

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_sheetself

Set the sheet to be the first visible in the sheets list (which is placed under the work area in Excel).

Returns:

  • (self)


712
713
714
715
716
717
718
# File 'ext/xlsxwriter/worksheet.c', line 712

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;
}

See #set_header for params description.



884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
# File 'ext/xlsxwriter/worksheet.c', line 884

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).

Returns:

  • (self)


858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'ext/xlsxwriter/worksheet.c', line 858

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_landscapeself

Sets print orientation of the worksheet to landscape.

Returns:

  • (self)


798
799
800
801
802
803
804
# File 'ext/xlsxwriter/worksheet.c', line 798

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.



843
844
845
846
847
848
849
# File 'ext/xlsxwriter/worksheet.c', line 843

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_viewself

Sets worksheet displa mode to “Page View/Layout”.

Returns:

  • (self)


822
823
824
825
826
827
828
# File 'ext/xlsxwriter/worksheet.c', line 822

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_portraitself

Sets print orientation of the worksheet to portrait.

Returns:

  • (self)


810
811
812
813
814
815
816
# File 'ext/xlsxwriter/worksheet.c', line 810

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.

Returns:

  • (self)


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
469
470
# File 'ext/xlsxwriter/worksheet.c', line 439

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)

Overloads:

  • #set_selection(range) ⇒ self

    Returns:

    • (self)
  • #set_selection(cell_from, cell_to) ⇒ self

    Returns:

    • (self)
  • #set_selection(row_from, col_from, row_to, col_to) ⇒ self

    Returns:

    • (self)


779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'ext/xlsxwriter/worksheet.c', line 779

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.

Returns:

  • (self)


760
761
762
763
764
765
766
# File 'ext/xlsxwriter/worksheet.c', line 760

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.



1073
1074
1075
1076
1077
1078
1079
# File 'ext/xlsxwriter/worksheet.c', line 1073

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


1117
1118
1119
1120
1121
1122
1123
# File 'ext/xlsxwriter/worksheet.c', line 1117

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]


932
933
934
935
936
937
938
939
940
941
942
943
944
# File 'ext/xlsxwriter/worksheet.c', line 932

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_dpiInteger

Returns the vertical dpi.

Returns:

  • (Integer)


1213
1214
1215
1216
1217
1218
# File 'ext/xlsxwriter/worksheet.c', line 1213

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.



1224
1225
1226
1227
1228
1229
1230
# File 'ext/xlsxwriter/worksheet.c', line 1224

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.

Overloads:

  • #write_array_formula(range, formula, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_array_formula(cell_from, cell_to, formula, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_array_formula(row_from, col_from, row_to, col_to, formula, format = nil) ⇒ self

    Returns:

    • (self)


206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'ext/xlsxwriter/worksheet.c', line 206

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.

Overloads:

  • #write_datetime(cell, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_datetime(row, col, format = nil) ⇒ self

    Returns:

    • (self)


373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'ext/xlsxwriter/worksheet.c', line 373

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.

Overloads:

  • #write_boolean(cell, value, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_boolean(row, col, value, format = nil) ⇒ self

    Returns:

    • (self)


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
364
365
# File 'ext/xlsxwriter/worksheet.c', line 339

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.

Overloads:

  • #write_datetime(cell, value, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_datetime(row, col, value, format = nil) ⇒ self

    Returns:

    • (self)


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
265
266
# File 'ext/xlsxwriter/worksheet.c', line 239

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.

Overloads:

  • #write_formula(cell, formula, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_formula(row, col, formula, format = nil) ⇒ self

    Returns:

    • (self)


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
196
197
# File 'ext/xlsxwriter/worksheet.c', line 170

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.

Overloads:

  • #write_formula_num(cell, formula, value, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_formula_num(row, col, formula, value, format = nil) ⇒ self

    Returns:

    • (self)


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
432
433
# File 'ext/xlsxwriter/worksheet.c', line 401

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.

Overloads:

  • #number_string(cell, value, format = nil) ⇒ self

    Returns:

    • (self)
  • #number_string(row, col, value, format = nil) ⇒ self

    Returns:

    • (self)


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
161
162
# File 'ext/xlsxwriter/worksheet.c', line 135

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.

Overloads:

  • #write_string(cell, value, format = nil) ⇒ self

    Returns:

    • (self)
  • #write_string(row, col, value, format = nil) ⇒ self

    Returns:

    • (self)


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
126
127
# File 'ext/xlsxwriter/worksheet.c', line 100

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.

Overloads:

  • #write_url(cell, url, format = nil, string: nil, tooltip: nil, format: nil) ⇒ self

    Returns:

    • (self)
  • #write_url(row, col, url, format = nil, string: nil, tooltip: nil, format: nil) ⇒ self

    Returns:

    • (self)


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
330
331
# File 'ext/xlsxwriter/worksheet.c', line 274

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.



959
960
961
962
963
964
965
# File 'ext/xlsxwriter/worksheet.c', line 959

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;
}