xlsxwriter 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,9 @@
3
3
  #ifndef __WORKBOOK_PROPERTIES__
4
4
  #define __WORKBOOK_PROPIRTIES__
5
5
 
6
- VALUE workbook_properties_init_(VALUE, VALUE);
7
- VALUE workbook_properties_set_dir_(VALUE self, VALUE value);
8
- VALUE workbook_properties_set_(VALUE self, VALUE key, VALUE value);
6
+ void
7
+ init_xlsxwriter_workbook_properties();
8
+
9
+ extern VALUE cWorkbookProperties;
9
10
 
10
11
  #endif // __WORKBOOK_PROPIRTIES__
@@ -2,6 +2,11 @@
2
2
  #include "worksheet.h"
3
3
  #include "workbook.h"
4
4
 
5
+ VALUE cWorksheet;
6
+
7
+ void worksheet_free(void *p);
8
+
9
+
5
10
  VALUE
6
11
  worksheet_alloc(VALUE klass)
7
12
  {
@@ -15,6 +20,7 @@ worksheet_alloc(VALUE klass)
15
20
  return obj;
16
21
  }
17
22
 
23
+ /* :nodoc: */
18
24
  VALUE
19
25
  worksheet_init(int argc, VALUE *argv, VALUE self) {
20
26
  char *name = NULL;
@@ -64,6 +70,7 @@ worksheet_init(int argc, VALUE *argv, VALUE self) {
64
70
  return self;
65
71
  }
66
72
 
73
+ /* :nodoc: */
67
74
  VALUE
68
75
  worksheet_release(VALUE self) {
69
76
  struct worksheet *ptr;
@@ -82,6 +89,12 @@ worksheet_free(void *p) {
82
89
  }
83
90
  }
84
91
 
92
+ /* call-seq:
93
+ * ws.write_string(cell, value, format = nil) -> self
94
+ * ws.write_string(row, col, value, format = nil) -> self
95
+ *
96
+ * Writes a string +value+ into a +cell+ with +format+.
97
+ */
85
98
  VALUE
86
99
  worksheet_write_string_(int argc, VALUE *argv, VALUE self) {
87
100
  lxw_row_t row;
@@ -111,6 +124,12 @@ worksheet_write_string_(int argc, VALUE *argv, VALUE self) {
111
124
  return self;
112
125
  }
113
126
 
127
+ /* call-seq:
128
+ * ws.number_string(cell, value, format = nil) -> self
129
+ * ws.number_string(row, col, value, format = nil) -> self
130
+ *
131
+ * Writes a number +value+ into a +cell+ with +format+.
132
+ */
114
133
  VALUE
115
134
  worksheet_write_number_(int argc, VALUE *argv, VALUE self) {
116
135
  lxw_row_t row;
@@ -140,6 +159,12 @@ worksheet_write_number_(int argc, VALUE *argv, VALUE self) {
140
159
  return self;
141
160
  }
142
161
 
162
+ /* call-seq:
163
+ * ws.write_formula(cell, formula, format = nil) -> self
164
+ * ws.write_formula(row, col, formula, format = nil) -> self
165
+ *
166
+ * Writes a +formula+ into a +cell+ with +format+.
167
+ */
143
168
  VALUE
144
169
  worksheet_write_formula_(int argc, VALUE *argv, VALUE self) {
145
170
  lxw_row_t row;
@@ -169,6 +194,13 @@ worksheet_write_formula_(int argc, VALUE *argv, VALUE self) {
169
194
  return self;
170
195
  }
171
196
 
197
+ /* call-seq:
198
+ * ws.write_array_formula(range, formula, format = nil) -> self
199
+ * ws.write_array_formula(cell_from, cell_to, formula, format = nil) -> self
200
+ * ws.write_array_formula(row_from, col_from, row_to, col_to, formula, format = nil) -> self
201
+ *
202
+ * Writes an array +formula+ into a cell +range+ with +format+.
203
+ */
172
204
  VALUE worksheet_write_array_formula_(int argc, VALUE *argv, VALUE self) {
173
205
  lxw_row_t row_from, row_to;
174
206
  lxw_col_t col_from, col_to;
@@ -196,6 +228,12 @@ VALUE worksheet_write_array_formula_(int argc, VALUE *argv, VALUE self) {
196
228
  return self;
197
229
  }
198
230
 
231
+ /* call-seq:
232
+ * ws.write_datetime(cell, value, format = nil) -> self
233
+ * ws.write_datetime(row, col, value, format = nil) -> self
234
+ *
235
+ * Writes a datetime +value+ into a +cell+ with +format+.
236
+ */
199
237
  VALUE
200
238
  worksheet_write_datetime_(int argc, VALUE *argv, VALUE self) {
201
239
  lxw_row_t row;
@@ -225,6 +263,12 @@ worksheet_write_datetime_(int argc, VALUE *argv, VALUE self) {
225
263
  return self;
226
264
  }
227
265
 
266
+ /* call-seq:
267
+ * ws.write_url(cell, url, format = nil, string: nil, tooltip: nil, format: nil) -> self
268
+ * ws.write_url(row, col, url, format = nil, string: nil, tooltip: nil, format: nil) -> self
269
+ *
270
+ * Writes a +url+ into a +cell+ with +format+.
271
+ */
228
272
  VALUE
229
273
  worksheet_write_url_(int argc, VALUE *argv, VALUE self) {
230
274
  lxw_row_t row;
@@ -284,6 +328,12 @@ worksheet_write_url_(int argc, VALUE *argv, VALUE self) {
284
328
  return self;
285
329
  }
286
330
 
331
+ /* call-seq:
332
+ * ws.write_boolean(cell, value, format = nil) -> self
333
+ * ws.write_boolean(row, col, value, format = nil) -> self
334
+ *
335
+ * Writes a boolean +value+ into a +cell+ with +format+.
336
+ */
287
337
  VALUE
288
338
  worksheet_write_boolean_(int argc, VALUE *argv, VALUE self) {
289
339
  lxw_row_t row;
@@ -312,6 +362,12 @@ worksheet_write_boolean_(int argc, VALUE *argv, VALUE self) {
312
362
  return self;
313
363
  }
314
364
 
365
+ /* call-seq:
366
+ * ws.write_datetime(cell, format = nil) -> self
367
+ * ws.write_datetime(row, col, format = nil) -> self
368
+ *
369
+ * Make a +cell+ blank with +format+.
370
+ */
315
371
  VALUE
316
372
  worksheet_write_blank_(int argc, VALUE *argv, VALUE self) {
317
373
  lxw_row_t row;
@@ -334,6 +390,12 @@ worksheet_write_blank_(int argc, VALUE *argv, VALUE self) {
334
390
  return self;
335
391
  }
336
392
 
393
+ /* call-seq:
394
+ * ws.write_formula_num(cell, formula, value, format = nil) -> self
395
+ * ws.write_formula_num(row, col, formula, value, format = nil) -> self
396
+ *
397
+ * Writes a +formula+ with +value+ into a +cell+ with +format+.
398
+ */
337
399
  VALUE worksheet_write_formula_num_(int argc, VALUE *argv, VALUE self) {
338
400
  lxw_row_t row;
339
401
  lxw_col_t col;
@@ -349,13 +411,13 @@ VALUE worksheet_write_formula_num_(int argc, VALUE *argv, VALUE self) {
349
411
  ++larg;
350
412
  }
351
413
 
352
- if (larg + 1 < argc) {
353
- format_key = argv[larg];
414
+ if (larg < argc) {
415
+ value = argv[larg];
354
416
  ++larg;
355
417
  }
356
418
 
357
419
  if (larg < argc) {
358
- value = argv[larg];
420
+ format_key = argv[larg];
359
421
  ++larg;
360
422
  }
361
423
 
@@ -368,6 +430,10 @@ VALUE worksheet_write_formula_num_(int argc, VALUE *argv, VALUE self) {
368
430
  return self;
369
431
  }
370
432
 
433
+ /* call-seq: ws.set_row(row, height: nil, format: nil, hide: false) -> self
434
+ *
435
+ * Set properties of the row.
436
+ */
371
437
  VALUE
372
438
  worksheet_set_row_(VALUE self, VALUE row, VALUE opts) {
373
439
  double height = LXW_DEF_ROW_HEIGHT;
@@ -401,6 +467,10 @@ worksheet_set_row_(VALUE self, VALUE row, VALUE opts) {
401
467
  return self;
402
468
  }
403
469
 
470
+ /* call-seq: ws.set_column(col_from, col_to, width: nil, format: nil, hide: nil) -> self
471
+ *
472
+ * Set properties of the cols range.
473
+ */
404
474
  VALUE
405
475
  worksheet_set_column_(VALUE self, VALUE col_from, VALUE col_to, VALUE opts) {
406
476
  double width = LXW_DEF_COL_WIDTH;
@@ -436,27 +506,23 @@ worksheet_set_column_(VALUE self, VALUE col_from, VALUE col_to, VALUE opts) {
436
506
  return self;
437
507
  }
438
508
 
439
- #define SET_IMG_OPT(key, setter) { \
440
- val = rb_hash_aref(opts, ID2SYM(rb_intern(key))); \
441
- if (!NIL_P(val)) { \
442
- with_options = '\1'; \
443
- setter; \
444
- } \
445
- }
446
-
509
+ /* call-seq:
510
+ * ws.insert_image(cell, fname, opts = {}) -> self
511
+ * ws.insert_image(row, col, fname, opts = {}) -> self
512
+ *
513
+ * Inserts image from +fname+ into the worksheet (at +cell+).
514
+ *
515
+ * Available +opts+
516
+ * :offset, :x_offset, :y_offset:: Image offset (+:offset+ for both; Integer).
517
+ * :scale, :x_scale, :y_scale:: Image scale (+:scale+ for both; Numeric).
518
+ */
447
519
  VALUE
448
520
  worksheet_insert_image_(int argc, VALUE *argv, VALUE self) {
449
521
  lxw_row_t row;
450
522
  lxw_col_t col;
451
523
  VALUE fname = Qnil;
452
524
  VALUE opts = Qnil;
453
- VALUE val = Qnil;
454
- lxw_image_options options = {
455
- .x_offset = 0,
456
- .y_offset = 0,
457
- .x_scale = 1.0,
458
- .y_scale = 1.0
459
- };
525
+ lxw_image_options options;
460
526
  char with_options = '\0';
461
527
 
462
528
  rb_check_arity(argc, 2, 4);
@@ -476,12 +542,7 @@ worksheet_insert_image_(int argc, VALUE *argv, VALUE self) {
476
542
  Data_Get_Struct(self, struct worksheet, ptr);
477
543
 
478
544
  if (!NIL_P(opts)) {
479
- SET_IMG_OPT("offset", options.x_offset = options.y_offset = NUM2INT(val));
480
- SET_IMG_OPT("x_offset", options.x_offset = NUM2INT(val));
481
- SET_IMG_OPT("y_offset", options.y_offset = NUM2INT(val));
482
- SET_IMG_OPT("scale", options.x_scale = options.y_scale = NUM2DBL(val));
483
- SET_IMG_OPT("x_scale", options.x_scale = NUM2DBL(val));
484
- SET_IMG_OPT("y_scale", options.y_scale = NUM2DBL(val));
545
+ options = val_to_lxw_image_options(opts, &with_options);
485
546
  }
486
547
 
487
548
  if (with_options) {
@@ -493,15 +554,23 @@ worksheet_insert_image_(int argc, VALUE *argv, VALUE self) {
493
554
  return self;
494
555
  }
495
556
 
496
- #undef SET_IMG_OPT
497
-
557
+ /* call-seq:
558
+ * ws.insert_chart(cell, chart, opts = {}) -> self
559
+ * ws.insert_chart(row, col, chart, opts = {}) -> self
560
+ *
561
+ * Inserts chart from +fname+ into the worksheet (at +cell+).
562
+ *
563
+ * For available +opts+ see #insert_image.
564
+ */
498
565
  VALUE
499
566
  worksheet_insert_chart_(int argc, VALUE *argv, VALUE self) {
500
567
  lxw_row_t row;
501
568
  lxw_col_t col;
502
- VALUE chart;
569
+ VALUE chart, opts = Qnil;
570
+ lxw_image_options options;
571
+ char with_options = '\0';
503
572
 
504
- rb_check_arity(argc, 2, 3);
573
+ rb_check_arity(argc, 2, 4);
505
574
  int larg = extract_cell(argc, argv, &row, &col);
506
575
 
507
576
  if (larg < argc) {
@@ -511,27 +580,49 @@ worksheet_insert_chart_(int argc, VALUE *argv, VALUE self) {
511
580
  rb_raise(rb_eArgError, "No chart specified");
512
581
  }
513
582
 
583
+ if (larg < argc) {
584
+ opts = argv[larg];
585
+ ++larg;
586
+ }
587
+
588
+ if (!NIL_P(opts)) {
589
+ options = val_to_lxw_image_options(opts, &with_options);
590
+ }
591
+
514
592
  struct worksheet *ptr;
515
593
  struct chart *chart_ptr;
516
594
  Data_Get_Struct(self, struct worksheet, ptr);
517
595
  Data_Get_Struct(chart, struct chart, chart_ptr);
518
596
 
519
- worksheet_insert_chart(ptr->worksheet, row, col, chart_ptr->chart);
597
+ if (with_options) {
598
+ worksheet_insert_chart_opt(ptr->worksheet, row, col, chart_ptr->chart, &options);
599
+ } else {
600
+ worksheet_insert_chart(ptr->worksheet, row, col, chart_ptr->chart);
601
+ }
520
602
 
521
603
  return self;
522
604
  }
523
605
 
524
- #undef SET_IMG_OPT
525
-
606
+ /* call-seq:
607
+ * ws.merge_range(range, value = "", format = nil) -> self
608
+ * ws.merge_range(cell_from, cell_to, value = "", format = nil) -> self
609
+ * ws.merge_range(row_from, col_from, row_to, col_to, value = "", format = nil) -> self
610
+ *
611
+ * Merges +range+, setting string +value+ with +format+.
612
+ *
613
+ * ws.merge_range('A1:D5')
614
+ * ws.merge_range('A1', 'D5', 'Merged cells')
615
+ * ws.merge_range(0, 0, 4, 3)
616
+ */
526
617
  VALUE
527
618
  worksheet_merge_range_(int argc, VALUE *argv, VALUE self) {
528
- char *str;
619
+ char *str = "";
529
620
  lxw_format *format = NULL;
530
621
  lxw_col_t col1, col2;
531
622
  lxw_row_t row1, row2;
532
623
  VALUE workbook = rb_iv_get(self, "@workbook");
533
624
 
534
- rb_check_arity(argc, 2, 6);
625
+ rb_check_arity(argc, 1, 6);
535
626
  int larg = extract_range(argc, argv, &row1, &col1, &row2, &col2);
536
627
 
537
628
  if (larg < argc) {
@@ -551,6 +642,17 @@ worksheet_merge_range_(int argc, VALUE *argv, VALUE self) {
551
642
  return self;
552
643
  }
553
644
 
645
+ /* call-seq:
646
+ * ws.autofilter(range) -> self
647
+ * ws.autofilter(cell_from, cell_to) -> self
648
+ * ws.autofilter(row_from, col_from, row_to, col_to) -> self
649
+ *
650
+ * Applies autofilter to the +range+.
651
+ *
652
+ * ws.autofilter('A1:D5')
653
+ * ws.autofilter('A1', 'D5')
654
+ * ws.autofilter(0, 0, 4, 3)
655
+ */
554
656
  VALUE
555
657
  worksheet_autofilter_(int argc, VALUE *argv, VALUE self) {
556
658
  lxw_row_t row_from, row_to;
@@ -565,12 +667,22 @@ worksheet_autofilter_(int argc, VALUE *argv, VALUE self) {
565
667
  worksheet_autofilter(ptr->worksheet, row_from, col_from, row_to, col_to);
566
668
  return self;
567
669
  }
670
+
671
+ /* call-seq: ws.activate -> self
672
+ *
673
+ * Set the worksheet to be active on opening the workbook.
674
+ */
568
675
  VALUE worksheet_activate_(VALUE self) {
569
676
  struct worksheet *ptr;
570
677
  Data_Get_Struct(self, struct worksheet, ptr);
571
678
  worksheet_activate(ptr->worksheet);
572
679
  return self;
573
680
  }
681
+
682
+ /* call-seq: ws.select -> self
683
+ *
684
+ * Set the worksheet to be selected on openong the workbook.
685
+ */
574
686
  VALUE worksheet_select_(VALUE self) {
575
687
  struct worksheet *ptr;
576
688
  Data_Get_Struct(self, struct worksheet, ptr);
@@ -578,6 +690,10 @@ VALUE worksheet_select_(VALUE self) {
578
690
  return self;
579
691
  }
580
692
 
693
+ /* call-seq: ws.hide -> self
694
+ *
695
+ * Hide the worksheet.
696
+ */
581
697
  VALUE
582
698
  worksheet_hide_(VALUE self) {
583
699
  struct worksheet *ptr;
@@ -586,6 +702,11 @@ worksheet_hide_(VALUE self) {
586
702
  return self;
587
703
  }
588
704
 
705
+ /* call-seq: ws.set_fitst_sheet -> self
706
+ *
707
+ * Set the sheet to be the first visible in the sheets list (which is placed
708
+ * under the work area in Excel).
709
+ */
589
710
  VALUE
590
711
  worksheet_set_first_sheet_(VALUE self) {
591
712
  struct worksheet *ptr;
@@ -593,31 +714,47 @@ worksheet_set_first_sheet_(VALUE self) {
593
714
  worksheet_set_first_sheet(ptr->worksheet);
594
715
  return self;
595
716
  }
717
+
718
+ /* call-seq:
719
+ * ws.freeze_panes(cell) -> self
720
+ * ws.freeze_panes(row, col) -> self
721
+ *
722
+ * Divides the worksheet into horizontal or vertical panes and freezes them.
723
+ *
724
+ * The specified +cell+ is the top left in the right bottom pane.
725
+ *
726
+ * In order to freeze only rows/cols pass 0 as +row+ or +col+.
727
+ *
728
+ * Advanced usage (with 2nd cell and type) is not documented yet.
729
+ */
596
730
  VALUE
597
731
  worksheet_freeze_panes_(int argc, VALUE *argv, VALUE self) {
598
- rb_check_arity(argc, 2, 5);
599
- VALUE row = argv[0];
600
- VALUE col = argv[1];
732
+ lxw_row_t row, row2;
733
+ lxw_col_t col, col2;
734
+ uint8_t type = 0;
735
+ rb_check_arity(argc, 1, 5);
736
+ int larg = extract_cell(argc, argv, &row, &col);
601
737
  struct worksheet *ptr;
602
738
  Data_Get_Struct(self, struct worksheet, ptr);
603
- if (argc == 2) {
604
- worksheet_freeze_panes(ptr->worksheet, NUM2INT(row), value_to_col(col));
739
+ if (larg >= argc) {
740
+ worksheet_freeze_panes(ptr->worksheet, row, col);
605
741
  } else {
606
- VALUE row2 = row;
607
- VALUE col2 = col;
608
- uint8_t type = 0;
609
- if (argc > 2)
610
- row2 = argv[2];
611
- if (argc > 3)
612
- col2 = argv[3];
613
- if (argc > 4)
614
- type = NUM2INT(argv[4]);
615
- worksheet_freeze_panes_opt(ptr->worksheet, NUM2INT(row), value_to_col(col),
616
- NUM2INT(row2), value_to_col(col2), type);
742
+ larg += extract_cell(argc - larg, argv + larg, &row2, &col2);
743
+ if (larg < argc) {
744
+ type = NUM2INT(argv[larg]);
745
+ }
746
+ worksheet_freeze_panes_opt(ptr->worksheet, row, col, row2, col2, type);
617
747
  }
618
748
  return self;
619
749
  }
620
750
 
751
+ /* call-seq: ws.split_panes(vertical, horizontal) -> self
752
+ *
753
+ * Divides the worksheet int vertical and horizontal panes with respective
754
+ * positions from parameters (Numeric).
755
+ *
756
+ * If only one split is desired pass 0 for other.
757
+ */
621
758
  VALUE
622
759
  worksheet_split_panes_(VALUE self, VALUE vertical, VALUE horizontal) {
623
760
  struct worksheet *ptr;
@@ -626,6 +763,17 @@ worksheet_split_panes_(VALUE self, VALUE vertical, VALUE horizontal) {
626
763
  return self;
627
764
  }
628
765
 
766
+ /* call-seq:
767
+ * ws.set_selection(range) -> self
768
+ * ws.set_selection(cell_from, cell_to) -> self
769
+ * ws.set_selection(row_from, col_from, row_to, col_to) -> self
770
+ *
771
+ * Selects the specified +range+ on the worksheet.
772
+ *
773
+ * ws.set_selection('A1:G5')
774
+ * ws.set_selection('A1', 'G5')
775
+ * ws.set_selection(0, 0, 4, 6)
776
+ */
629
777
  VALUE
630
778
  worksheet_set_selection_(int argc, VALUE *argv, VALUE self) {
631
779
  lxw_row_t row_from, row_to;
@@ -641,6 +789,10 @@ worksheet_set_selection_(int argc, VALUE *argv, VALUE self) {
641
789
  return self;
642
790
  }
643
791
 
792
+ /* call-seq: ws.set_landscape -> self
793
+ *
794
+ * Sets print orientation of the worksheet to landscape.
795
+ */
644
796
  VALUE
645
797
  worksheet_set_landscape_(VALUE self) {
646
798
  struct worksheet *ptr;
@@ -649,6 +801,10 @@ worksheet_set_landscape_(VALUE self) {
649
801
  return self;
650
802
  }
651
803
 
804
+ /* call-seq: ws.set_portrait -> self
805
+ *
806
+ * Sets print orientation of the worksheet to portrait.
807
+ */
652
808
  VALUE
653
809
  worksheet_set_portrait_(VALUE self) {
654
810
  struct worksheet *ptr;
@@ -657,6 +813,10 @@ worksheet_set_portrait_(VALUE self) {
657
813
  return self;
658
814
  }
659
815
 
816
+ /* call-seq: ws.set_page_view -> self
817
+ *
818
+ * Sets worksheet displa mode to "Page View/Layout".
819
+ */
660
820
  VALUE
661
821
  worksheet_set_page_view_(VALUE self) {
662
822
  struct worksheet *ptr;
@@ -665,6 +825,10 @@ worksheet_set_page_view_(VALUE self) {
665
825
  return self;
666
826
  }
667
827
 
828
+ /* call-seq: ws.paper=(type) -> type
829
+ *
830
+ * Sets the paper +type+ for printing. See {libxlsxwriter doc}[https://libxlsxwriter.github.io/worksheet_8h.html#a9f8af12017797b10c5ee68e04149032f] for options.
831
+ */
668
832
  VALUE
669
833
  worksheet_set_paper_(VALUE self, VALUE paper_type) {
670
834
  struct worksheet *ptr;
@@ -673,6 +837,7 @@ worksheet_set_paper_(VALUE self, VALUE paper_type) {
673
837
  return self;
674
838
  }
675
839
 
840
+ /* Sets the worksheet margins (Numeric) for the printed page. */
676
841
  VALUE
677
842
  worksheet_set_margins_(VALUE self, VALUE left, VALUE right, VALUE top, VALUE bottom) {
678
843
  struct worksheet *ptr;
@@ -681,6 +846,13 @@ worksheet_set_margins_(VALUE self, VALUE left, VALUE right, VALUE top, VALUE bot
681
846
  return self;
682
847
  }
683
848
 
849
+ /* call-seq: ws.set_header(text, opts) -> self
850
+ *
851
+ * See {libxlsxwriter doc}[https://libxlsxwriter.github.io/worksheet_8h.html#a4070c24ed5107f33e94f30a1bf865ba9]
852
+ * for the +text+ control characters.
853
+ *
854
+ * Currently the only supported option is +:margin+ (Numeric).
855
+ */
684
856
  VALUE
685
857
  worksheet_set_header_(VALUE self, VALUE val, VALUE opts) {
686
858
  const char *str = StringValueCStr(val);
@@ -703,6 +875,10 @@ worksheet_set_header_(VALUE self, VALUE val, VALUE opts) {
703
875
  return self;
704
876
  }
705
877
 
878
+ /* call-seq: ws.set_footer(text, opts)
879
+ *
880
+ * See #set_header for params description.
881
+ */
706
882
  VALUE
707
883
  worksheet_set_footer_(VALUE self, VALUE val, VALUE opts) {
708
884
  const char *str = StringValueCStr(val);
@@ -725,6 +901,12 @@ worksheet_set_footer_(VALUE self, VALUE val, VALUE opts) {
725
901
  return self;
726
902
  }
727
903
 
904
+ /* call-seq: wb.h_pagebreaks=(breaks) -> breaks
905
+ *
906
+ * Adds horizontal page +breaks+ to the worksheet.
907
+ *
908
+ * wb.h_pagebreaks = [20, 40, 80]
909
+ */
728
910
  VALUE
729
911
  worksheet_set_h_pagebreaks_(VALUE self, VALUE val) {
730
912
  const size_t len = RARRAY_LEN(val);
@@ -739,6 +921,12 @@ worksheet_set_h_pagebreaks_(VALUE self, VALUE val) {
739
921
  return val;
740
922
  }
741
923
 
924
+ /* call-seq: wb.h_pagebreaks=(breaks) -> breaks
925
+ *
926
+ * Adds vertical page +breaks+ to the worksheet.
927
+ *
928
+ * wb.v_pagebreaks = [20, 40, 80]
929
+ */
742
930
  VALUE
743
931
  worksheet_set_v_pagebreaks_(VALUE self, VALUE val) {
744
932
  const size_t len = RARRAY_LEN(val);
@@ -753,6 +941,7 @@ worksheet_set_v_pagebreaks_(VALUE self, VALUE val) {
753
941
  return val;
754
942
  }
755
943
 
944
+ /* Changes the default print direction */
756
945
  VALUE
757
946
  worksheet_print_across_(VALUE self) {
758
947
  struct worksheet *ptr;
@@ -761,6 +950,10 @@ worksheet_print_across_(VALUE self) {
761
950
  return self;
762
951
  }
763
952
 
953
+ /* call-seq: ws.zoom=(zoom) -> zoom
954
+ *
955
+ * Sets the worksheet zoom factor in the range 10 <= +zoom+ <= 400.
956
+ */
764
957
  VALUE
765
958
  worksheet_set_zoom_(VALUE self, VALUE val) {
766
959
  struct worksheet *ptr;
@@ -769,6 +962,12 @@ worksheet_set_zoom_(VALUE self, VALUE val) {
769
962
  return self;
770
963
  }
771
964
 
965
+ /* call-seq: ws.gridlines=(option) -> option
966
+ *
967
+ * Display or hide screen and print gridlines using one of the values
968
+ * XlsxWriter::Worksheet::{GRIDLINES_HIDE_ALL, GRIDLINES_SHOW_SCREEN,
969
+ * GRIDLINES_SHOW_PRINT, GRIDLINES_SHOW_ALL}.
970
+ */
772
971
  VALUE
773
972
  worksheet_gridlines_(VALUE self, VALUE value) {
774
973
  struct worksheet *ptr;
@@ -779,6 +978,7 @@ worksheet_gridlines_(VALUE self, VALUE value) {
779
978
  return value;
780
979
  }
781
980
 
981
+ /* Center the worksheet data horizontally between the margins on the printed page */
782
982
  VALUE
783
983
  worksheet_center_horizontally_(VALUE self){
784
984
  struct worksheet *ptr;
@@ -787,6 +987,7 @@ worksheet_center_horizontally_(VALUE self){
787
987
  return self;
788
988
  }
789
989
 
990
+ /* Center the worksheet data vertically between the margins on the printed page */
790
991
  VALUE
791
992
  worksheet_center_vertically_(VALUE self) {
792
993
  struct worksheet *ptr;
@@ -795,6 +996,7 @@ worksheet_center_vertically_(VALUE self) {
795
996
  return self;
796
997
  }
797
998
 
999
+ /* Print rows and column header (wich is disabled by default). */
798
1000
  VALUE
799
1001
  worksheet_print_row_col_headers_(VALUE self) {
800
1002
  struct worksheet *ptr;
@@ -803,6 +1005,10 @@ worksheet_print_row_col_headers_(VALUE self) {
803
1005
  return self;
804
1006
  }
805
1007
 
1008
+ /* call-seq: ws.repeat_rows(row_from, row_to)
1009
+ *
1010
+ * Sets rows to be repeatedly printed out on all pages.
1011
+ */
806
1012
  VALUE
807
1013
  worksheet_repeat_rows_(VALUE self, VALUE row_from, VALUE row_to) {
808
1014
  struct worksheet *ptr;
@@ -811,6 +1017,10 @@ worksheet_repeat_rows_(VALUE self, VALUE row_from, VALUE row_to) {
811
1017
  return self;
812
1018
  }
813
1019
 
1020
+ /* call-seq: ws.repeat_columns(col_from, col_to)
1021
+ *
1022
+ * Sets columns to be repeatedly printed out on all pages.
1023
+ */
814
1024
  VALUE
815
1025
  worksheet_repeat_columns_(VALUE self, VALUE col_from, VALUE col_to) {
816
1026
  struct worksheet *ptr;
@@ -819,6 +1029,13 @@ worksheet_repeat_columns_(VALUE self, VALUE col_from, VALUE col_to) {
819
1029
  return self;
820
1030
  }
821
1031
 
1032
+ /* call-seq:
1033
+ * ws.print_area(range)
1034
+ * ws.print_area(cell_from, cell_to)
1035
+ * ws.print_area(row_from, col_from, row_to, col_to)
1036
+ *
1037
+ * Specifies area of the worksheet to be printed.
1038
+ */
822
1039
  VALUE
823
1040
  worksheet_print_area_(int argc, VALUE *argv, VALUE self) {
824
1041
  lxw_row_t row_from, row_to;
@@ -834,6 +1051,11 @@ worksheet_print_area_(int argc, VALUE *argv, VALUE self) {
834
1051
  return self;
835
1052
  }
836
1053
 
1054
+ /* call-seq: ws.fit_to_pages(width, height) -> self
1055
+ *
1056
+ * Fits the printed area to a specific number of pages both vertically and
1057
+ * horizontally.
1058
+ */
837
1059
  VALUE
838
1060
  worksheet_fit_to_pages_(VALUE self, VALUE width, VALUE height) {
839
1061
  struct worksheet *ptr;
@@ -842,6 +1064,10 @@ worksheet_fit_to_pages_(VALUE self, VALUE width, VALUE height) {
842
1064
  return self;
843
1065
  }
844
1066
 
1067
+ /* call-seq: ws.start_page=(page) -> page
1068
+ *
1069
+ * Set the number of the first printed page.
1070
+ */
845
1071
  VALUE
846
1072
  worksheet_set_start_page_(VALUE self, VALUE start_page) {
847
1073
  struct worksheet *ptr;
@@ -850,6 +1076,10 @@ worksheet_set_start_page_(VALUE self, VALUE start_page) {
850
1076
  return start_page;
851
1077
  }
852
1078
 
1079
+ /* call-seq: ws.print_scale=(scale) -> scale
1080
+ *
1081
+ * Sets the +scale+ factor of the printed page (10 <= +scale+ <= 400).
1082
+ */
853
1083
  VALUE
854
1084
  worksheet_set_print_scale_(VALUE self, VALUE scale) {
855
1085
  struct worksheet *ptr;
@@ -858,6 +1088,7 @@ worksheet_set_print_scale_(VALUE self, VALUE scale) {
858
1088
  return scale;
859
1089
  }
860
1090
 
1091
+ /* Sets text direction to rtl (e.g. for worksheets on Hebrew or Arabic). */
861
1092
  VALUE
862
1093
  worksheet_right_to_left_(VALUE self) {
863
1094
  struct worksheet *ptr;
@@ -866,6 +1097,7 @@ worksheet_right_to_left_(VALUE self) {
866
1097
  return self;
867
1098
  }
868
1099
 
1100
+ /* Hides all zero values. */
869
1101
  VALUE
870
1102
  worksheet_hide_zero_(VALUE self) {
871
1103
  struct worksheet *ptr;
@@ -874,6 +1106,12 @@ worksheet_hide_zero_(VALUE self) {
874
1106
  return self;
875
1107
  }
876
1108
 
1109
+ /* call-seq: ws.tab_color=(color) -> color
1110
+ *
1111
+ * Set the tab color (from RGB integer).
1112
+ *
1113
+ * ws.tab_color = 0xF0F0F0
1114
+ */
877
1115
  VALUE
878
1116
  worksheet_set_tab_color_(VALUE self, VALUE color) {
879
1117
  struct worksheet *ptr;
@@ -882,13 +1120,20 @@ worksheet_set_tab_color_(VALUE self, VALUE color) {
882
1120
  return color;
883
1121
  }
884
1122
 
1123
+ /* call-seq: ws.protect(password[, opts]) -> self
1124
+ *
1125
+ * Protects the worksheet elements from modification.
1126
+ * See {libxlsxwriter doc}[https://libxlsxwriter.github.io/worksheet_8h.html#a1b49e135d4debcdb25941f2f40f04cb0]
1127
+ * for options.
1128
+ */
885
1129
  VALUE
886
1130
  worksheet_protect_(int argc, VALUE *argv, VALUE self) {
887
1131
  rb_check_arity(argc, 0, 2);
888
1132
  uint8_t with_options = '\0';
889
1133
  VALUE val;
890
1134
  VALUE opts = Qnil;
891
- lxw_protection options;
1135
+ // All options are off by default
1136
+ lxw_protection options = {};
892
1137
  const char *password = NULL;
893
1138
  if (argc > 0 && !NIL_P(argv[0])) {
894
1139
  switch (TYPE(argv[0])) {
@@ -911,9 +1156,6 @@ worksheet_protect_(int argc, VALUE *argv, VALUE self) {
911
1156
  }
912
1157
  }
913
1158
 
914
- // All options are off by default
915
- memset(&options, 0, sizeof options);
916
-
917
1159
  if (!NIL_P(opts)) {
918
1160
  #define PR_OPT(field) { \
919
1161
  val = rb_hash_aref(opts, ID2SYM(rb_intern(#field))); \
@@ -949,6 +1191,10 @@ worksheet_protect_(int argc, VALUE *argv, VALUE self) {
949
1191
  return self;
950
1192
  }
951
1193
 
1194
+ /* call-seq: ws.set_default_row(height, hide_unuser_rows) -> self
1195
+ *
1196
+ * Sets the default row properties for the worksheet.
1197
+ */
952
1198
  VALUE
953
1199
  worksheet_set_default_row_(VALUE self, VALUE height, VALUE hide_unused_rows) {
954
1200
  struct worksheet *ptr;
@@ -958,14 +1204,21 @@ worksheet_set_default_row_(VALUE self, VALUE height, VALUE hide_unused_rows) {
958
1204
  return self;
959
1205
  }
960
1206
 
961
-
1207
+ /* call-seq: ws.vertical_dpi -> int
1208
+ *
1209
+ * Returns the vertical dpi.
1210
+ */
962
1211
  VALUE
963
1212
  worksheet_get_vertical_dpi_(VALUE self) {
964
1213
  struct worksheet *ptr;
965
1214
  Data_Get_Struct(self, struct worksheet, ptr);
966
- return ptr->worksheet->vertical_dpi;
1215
+ return INT2NUM(ptr->worksheet->vertical_dpi);
967
1216
  }
968
1217
 
1218
+ /* call-seq: ws.vertical_dpi=(dpi) -> dpi
1219
+ *
1220
+ * Sets the vertical dpi.
1221
+ */
969
1222
  VALUE
970
1223
  worksheet_set_vertical_dpi_(VALUE self, VALUE val) {
971
1224
  struct worksheet *ptr;
@@ -1062,3 +1315,101 @@ int extract_range(int argc, VALUE *argv, lxw_row_t *row_from, lxw_col_t *col_fro
1062
1315
  larg += extract_cell(argc - larg, argv + larg, row_to, col_to);
1063
1316
  return larg;
1064
1317
  }
1318
+
1319
+ #define SET_IMG_OPT(key, setter) { \
1320
+ val = rb_hash_aref(opts, ID2SYM(rb_intern(key))); \
1321
+ if (!NIL_P(val)) { \
1322
+ (*with_options) = '\1'; \
1323
+ setter; \
1324
+ } \
1325
+ }
1326
+ lxw_image_options
1327
+ val_to_lxw_image_options(VALUE opts, char *with_options) {
1328
+ VALUE val;
1329
+ lxw_image_options options = {
1330
+ .x_offset = 0,
1331
+ .y_offset = 0,
1332
+ .x_scale = 1.0,
1333
+ .y_scale = 1.0
1334
+ };
1335
+ SET_IMG_OPT("offset", options.x_offset = options.y_offset = NUM2INT(val));
1336
+ SET_IMG_OPT("x_offset", options.x_offset = NUM2INT(val));
1337
+ SET_IMG_OPT("y_offset", options.y_offset = NUM2INT(val));
1338
+ SET_IMG_OPT("scale", options.x_scale = options.y_scale = NUM2DBL(val));
1339
+ SET_IMG_OPT("x_scale", options.x_scale = NUM2DBL(val));
1340
+ SET_IMG_OPT("y_scale", options.y_scale = NUM2DBL(val));
1341
+ return options;
1342
+ }
1343
+ #undef SET_IMG_OPT
1344
+
1345
+
1346
+ void
1347
+ init_xlsxwriter_worksheet() {
1348
+ /* Xlsx worksheet */
1349
+ cWorksheet = rb_define_class_under(mXlsxWriter, "Worksheet", rb_cObject);
1350
+
1351
+ rb_define_alloc_func(cWorksheet, worksheet_alloc);
1352
+ rb_define_method(cWorksheet, "initialize", worksheet_init, -1);
1353
+ rb_define_method(cWorksheet, "free", worksheet_release, 0);
1354
+ rb_define_method(cWorksheet, "write_string", worksheet_write_string_, -1);
1355
+ rb_define_method(cWorksheet, "write_number", worksheet_write_number_, -1);
1356
+ rb_define_method(cWorksheet, "write_formula", worksheet_write_formula_, -1);
1357
+ rb_define_method(cWorksheet, "write_array_formula", worksheet_write_array_formula_, -1);
1358
+ rb_define_method(cWorksheet, "write_datetime", worksheet_write_datetime_, -1);
1359
+ rb_define_method(cWorksheet, "write_url", worksheet_write_url_, -1);
1360
+ rb_define_method(cWorksheet, "write_boolean", worksheet_write_boolean_, -1);
1361
+ rb_define_method(cWorksheet, "write_blank", worksheet_write_blank_, -1);
1362
+ rb_define_method(cWorksheet, "write_formula_num", worksheet_write_formula_num_, -1);
1363
+ rb_define_method(cWorksheet, "set_row", worksheet_set_row_, 2);
1364
+ rb_define_method(cWorksheet, "set_column", worksheet_set_column_, 3);
1365
+ rb_define_method(cWorksheet, "insert_image", worksheet_insert_image_, -1);
1366
+ rb_define_method(cWorksheet, "insert_chart", worksheet_insert_chart_, -1);
1367
+ rb_define_method(cWorksheet, "merge_range", worksheet_merge_range_, -1);
1368
+ rb_define_method(cWorksheet, "autofilter", worksheet_autofilter_, -1);
1369
+ rb_define_method(cWorksheet, "activate", worksheet_activate_, 0);
1370
+ rb_define_method(cWorksheet, "select", worksheet_select_, 0);
1371
+ rb_define_method(cWorksheet, "hide", worksheet_hide_, 0);
1372
+ rb_define_method(cWorksheet, "set_first_sheet", worksheet_set_first_sheet_, 0);
1373
+ rb_define_method(cWorksheet, "freeze_panes", worksheet_freeze_panes_, -1);
1374
+ rb_define_method(cWorksheet, "split_panes", worksheet_split_panes_, 2);
1375
+ rb_define_method(cWorksheet, "set_selection", worksheet_set_selection_, -1);
1376
+ rb_define_method(cWorksheet, "set_landscape", worksheet_set_landscape_, 0);
1377
+ rb_define_method(cWorksheet, "set_portrait", worksheet_set_portrait_, 0);
1378
+ rb_define_method(cWorksheet, "set_page_view", worksheet_set_page_view_, 0);
1379
+ rb_define_method(cWorksheet, "paper=", worksheet_set_paper_, 1);
1380
+ rb_define_method(cWorksheet, "set_margins", worksheet_set_margins_, 4);
1381
+ rb_define_method(cWorksheet, "set_header", worksheet_set_header_, 1);
1382
+ rb_define_method(cWorksheet, "set_footer", worksheet_set_footer_, 1);
1383
+ rb_define_method(cWorksheet, "h_pagebreaks=", worksheet_set_h_pagebreaks_, 1);
1384
+ rb_define_method(cWorksheet, "v_pagebreaks=", worksheet_set_v_pagebreaks_, 1);
1385
+ rb_define_method(cWorksheet, "print_across", worksheet_print_across_, 0);
1386
+ rb_define_method(cWorksheet, "zoom=", worksheet_set_zoom_, 1);
1387
+ rb_define_method(cWorksheet, "gridlines=", worksheet_gridlines_, 1);
1388
+ rb_define_method(cWorksheet, "center_horizontally", worksheet_center_horizontally_, 0);
1389
+ rb_define_method(cWorksheet, "center_vertically", worksheet_center_vertically_, 0);
1390
+ rb_define_method(cWorksheet, "print_row_col_headers", worksheet_print_row_col_headers_, 0);
1391
+ rb_define_method(cWorksheet, "repeat_rows", worksheet_repeat_rows_, 2);
1392
+ rb_define_method(cWorksheet, "repeat_columns", worksheet_repeat_columns_, 2);
1393
+ rb_define_method(cWorksheet, "print_area", worksheet_print_area_, -1);
1394
+ rb_define_method(cWorksheet, "fit_to_pages", worksheet_fit_to_pages_, 2);
1395
+ rb_define_method(cWorksheet, "start_page=", worksheet_set_start_page_, 1);
1396
+ rb_define_method(cWorksheet, "print_scale=", worksheet_set_print_scale_, 1);
1397
+ rb_define_method(cWorksheet, "right_to_left", worksheet_right_to_left_, 0);
1398
+ rb_define_method(cWorksheet, "hide_zero", worksheet_hide_zero_, 0);
1399
+ rb_define_method(cWorksheet, "tab_color=", worksheet_set_tab_color_, 1);
1400
+ rb_define_method(cWorksheet, "protect", worksheet_protect_, -1);
1401
+ rb_define_method(cWorksheet, "set_default_row", worksheet_set_default_row_, 2);
1402
+
1403
+ rb_define_method(cWorksheet, "vertical_dpi", worksheet_get_vertical_dpi_, 0);
1404
+ rb_define_method(cWorksheet, "vertical_dpi=", worksheet_set_vertical_dpi_, 1);
1405
+
1406
+ #define MAP_LXW_WH_CONST(name, val_name) rb_define_const(cWorksheet, #name, INT2NUM(LXW_##val_name))
1407
+ MAP_LXW_WH_CONST(DEF_COL_WIDTH, DEF_COL_WIDTH);
1408
+ MAP_LXW_WH_CONST(DEF_ROW_HEIGHT, DEF_ROW_HEIGHT);
1409
+
1410
+ MAP_LXW_WH_CONST(GRIDLINES_HIDE_ALL, HIDE_ALL_GRIDLINES);
1411
+ MAP_LXW_WH_CONST(GRIDLINES_SHOW_SCREEN, SHOW_SCREEN_GRIDLINES);
1412
+ MAP_LXW_WH_CONST(GRIDLINES_SHOW_PRINT, SHOW_PRINT_GRIDLINES);
1413
+ MAP_LXW_WH_CONST(GRIDLINES_SHOW_ALL, SHOW_ALL_GRIDLINES);
1414
+ #undef MAP_LXW_WH_CONST
1415
+ }