xlsxwriter 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +40 -0
  3. data/ext/xlsxwriter/chart.c +105 -0
  4. data/ext/xlsxwriter/chart.h +27 -0
  5. data/ext/xlsxwriter/extconf.rb +14 -0
  6. data/ext/xlsxwriter/format.c +67 -0
  7. data/ext/xlsxwriter/format.h +9 -0
  8. data/ext/xlsxwriter/libxlsxwriter/LICENSE.txt +89 -0
  9. data/ext/xlsxwriter/libxlsxwriter/Makefile +141 -0
  10. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter.h +23 -0
  11. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/app.h +79 -0
  12. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/chart.h +1093 -0
  13. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/common.h +336 -0
  14. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
  15. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/core.h +51 -0
  16. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
  17. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
  18. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
  19. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
  20. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
  21. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
  22. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
  23. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
  24. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
  25. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +215 -0
  26. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
  27. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
  28. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
  29. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
  30. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
  31. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/workbook.h +751 -0
  32. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
  33. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
  34. data/ext/xlsxwriter/libxlsxwriter/lib/.gitignore +0 -0
  35. data/ext/xlsxwriter/libxlsxwriter/src/Makefile +125 -0
  36. data/ext/xlsxwriter/libxlsxwriter/src/app.c +439 -0
  37. data/ext/xlsxwriter/libxlsxwriter/src/chart.c +3420 -0
  38. data/ext/xlsxwriter/libxlsxwriter/src/content_types.c +341 -0
  39. data/ext/xlsxwriter/libxlsxwriter/src/core.c +293 -0
  40. data/ext/xlsxwriter/libxlsxwriter/src/custom.c +224 -0
  41. data/ext/xlsxwriter/libxlsxwriter/src/drawing.c +746 -0
  42. data/ext/xlsxwriter/libxlsxwriter/src/format.c +728 -0
  43. data/ext/xlsxwriter/libxlsxwriter/src/hash_table.c +223 -0
  44. data/ext/xlsxwriter/libxlsxwriter/src/packager.c +877 -0
  45. data/ext/xlsxwriter/libxlsxwriter/src/relationships.c +242 -0
  46. data/ext/xlsxwriter/libxlsxwriter/src/shared_strings.c +264 -0
  47. data/ext/xlsxwriter/libxlsxwriter/src/styles.c +1086 -0
  48. data/ext/xlsxwriter/libxlsxwriter/src/theme.c +348 -0
  49. data/ext/xlsxwriter/libxlsxwriter/src/utility.c +512 -0
  50. data/ext/xlsxwriter/libxlsxwriter/src/workbook.c +1895 -0
  51. data/ext/xlsxwriter/libxlsxwriter/src/worksheet.c +4992 -0
  52. data/ext/xlsxwriter/libxlsxwriter/src/xmlwriter.c +355 -0
  53. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/Makefile +44 -0
  54. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/crypt.h +131 -0
  55. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
  56. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.h +209 -0
  57. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
  58. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
  59. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
  60. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/minizip.c +520 -0
  61. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.c +291 -0
  62. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.h +37 -0
  63. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
  64. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.h +437 -0
  65. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.c +2007 -0
  66. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.h +367 -0
  67. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
  68. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
  69. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
  70. data/ext/xlsxwriter/workbook.c +257 -0
  71. data/ext/xlsxwriter/workbook.h +42 -0
  72. data/ext/xlsxwriter/workbook_properties.c +103 -0
  73. data/ext/xlsxwriter/workbook_properties.h +10 -0
  74. data/ext/xlsxwriter/worksheet.c +1064 -0
  75. data/ext/xlsxwriter/worksheet.h +74 -0
  76. data/ext/xlsxwriter/xlsxwriter.c +239 -0
  77. data/lib/xlsxwriter.rb +6 -0
  78. data/lib/xlsxwriter/version.rb +3 -0
  79. data/lib/xlsxwriter/worksheet.rb +72 -0
  80. data/test/run-test.rb +11 -0
  81. data/test/support/xlsx_comparable.rb +109 -0
  82. data/test/test-array-formula.rb +33 -0
  83. data/test/test-autofilter.rb +70 -0
  84. data/test/test-chart-area.rb +25 -0
  85. data/test/test-data.rb +65 -0
  86. data/test/test-default-row.rb +25 -0
  87. data/test/test-defined-name.rb +46 -0
  88. data/test/test-escapes.rb +33 -0
  89. data/test/test-fit-to-pages.rb +21 -0
  90. data/test/test-formatting.rb +137 -0
  91. data/test/test-gridlines.rb +15 -0
  92. data/test/test-hyperlink.rb +67 -0
  93. data/test/test-image.rb +84 -0
  94. data/test/test-merge-range.rb +18 -0
  95. data/test/test-misc.rb +29 -0
  96. data/test/test-optimize.rb +32 -0
  97. data/test/test-page-breaks.rb +13 -0
  98. data/test/test-page-setup.rb +28 -0
  99. data/test/test-panes.rb +45 -0
  100. data/test/test-print-area.rb +19 -0
  101. data/test/test-print-options.rb +61 -0
  102. data/test/test-print-scale.rb +12 -0
  103. data/test/test-properties.rb +51 -0
  104. data/test/test-protect.rb +27 -0
  105. data/test/test-repeat.rb +23 -0
  106. data/test/test-row-col-format.rb +35 -0
  107. data/test/test-set-selection.rb +13 -0
  108. data/test/test-set-start-page.rb +13 -0
  109. data/test/test-simple.rb +62 -0
  110. data/test/test-types.rb +17 -0
  111. data/test/xlsx-func-testcase.rb +36 -0
  112. metadata +228 -0
@@ -0,0 +1,74 @@
1
+ #include <ruby.h>
2
+ #include "xlsxwriter.h"
3
+
4
+ #ifndef __WORKSHEET__
5
+ #define __WORKSHEET__
6
+
7
+ struct worksheet {
8
+ lxw_worksheet *worksheet;
9
+ };
10
+
11
+ VALUE worksheet_alloc(VALUE klass);
12
+ VALUE worksheet_init(int argc, VALUE *argv, VALUE self);
13
+ VALUE worksheet_release(VALUE self);
14
+ void worksheet_free(void *);
15
+
16
+ VALUE worksheet_write_string_(int argc, VALUE *argv, VALUE self);
17
+ VALUE worksheet_write_number_(int argc, VALUE *argv, VALUE self);
18
+ VALUE worksheet_write_formula_(int argc, VALUE *argv, VALUE self);
19
+ VALUE worksheet_write_array_formula_(int argc, VALUE *argv, VALUE self);
20
+ VALUE worksheet_write_datetime_(int argc, VALUE *argv, VALUE self);
21
+ VALUE worksheet_write_url_(int argc, VALUE *argv, VALUE self);
22
+ VALUE worksheet_write_boolean_(int argc, VALUE *argv, VALUE self);
23
+ VALUE worksheet_write_blank_(int argc, VALUE *argv, VALUE self);
24
+ VALUE worksheet_write_formula_num_(int argc, VALUE *argv, VALUE self);
25
+ VALUE worksheet_set_row_(VALUE self, VALUE row, VALUE opts);
26
+ VALUE worksheet_set_column_(VALUE self, VALUE col_from, VALUE col_to, VALUE opts);
27
+ VALUE worksheet_insert_image_(int argc, VALUE *argv, VALUE self);
28
+ VALUE worksheet_insert_chart_(int argc, VALUE *argv, VALUE self);
29
+ VALUE worksheet_merge_range_(int argc, VALUE *argv, VALUE self);
30
+ VALUE worksheet_autofilter_(int argc, VALUE *argv, VALUE self);
31
+ VALUE worksheet_activate_(VALUE self);
32
+ VALUE worksheet_select_(VALUE self);
33
+ VALUE worksheet_hide_(VALUE self);
34
+ VALUE worksheet_set_first_sheet_(VALUE self);
35
+ VALUE worksheet_freeze_panes_(int argc, VALUE *argv, VALUE self);
36
+ VALUE worksheet_split_panes_(VALUE self, VALUE vertical, VALUE horizontal);
37
+ VALUE worksheet_set_selection_(int argc, VALUE *argv, VALUE self);
38
+ VALUE worksheet_set_landscape_(VALUE self);
39
+ VALUE worksheet_set_portrait_(VALUE self);
40
+ VALUE worksheet_set_page_view_(VALUE self);
41
+ VALUE worksheet_set_paper_(VALUE self, VALUE paper_type);
42
+ VALUE worksheet_set_margins_(VALUE self, VALUE left, VALUE right, VALUE top, VALUE bottom);
43
+ VALUE worksheet_set_header_(VALUE self, VALUE val, VALUE opts);
44
+ VALUE worksheet_set_footer_(VALUE self, VALUE val, VALUE opts);
45
+ VALUE worksheet_set_h_pagebreaks_(VALUE self, VALUE val);
46
+ VALUE worksheet_set_v_pagebreaks_(VALUE self, VALUE val);
47
+ VALUE worksheet_print_across_(VALUE self);
48
+ VALUE worksheet_set_zoom_(VALUE self, VALUE val);
49
+ VALUE worksheet_gridlines_(VALUE self, VALUE value);
50
+ VALUE worksheet_center_horizontally_(VALUE self);
51
+ VALUE worksheet_center_vertically_(VALUE self);
52
+ VALUE worksheet_print_row_col_headers_(VALUE self);
53
+ VALUE worksheet_repeat_rows_(VALUE self, VALUE row_from, VALUE row_to);
54
+ VALUE worksheet_repeat_columns_(VALUE self, VALUE col_from, VALUE col_to);
55
+ VALUE worksheet_print_area_(int argc, VALUE *argv, VALUE self);
56
+ VALUE worksheet_fit_to_pages_(VALUE self, VALUE width, VALUE height);
57
+ VALUE worksheet_set_start_page_(VALUE self, VALUE start_page);
58
+ VALUE worksheet_set_print_scale_(VALUE self, VALUE scale);
59
+ VALUE worksheet_right_to_left_(VALUE self);
60
+ VALUE worksheet_hide_zero_(VALUE self);
61
+ VALUE worksheet_set_tab_color_(VALUE self, VALUE color);
62
+ VALUE worksheet_protect_(int argc, VALUE *argv, VALUE self);
63
+ VALUE worksheet_set_default_row_(VALUE self, VALUE height, VALUE hide_unused_rows);
64
+
65
+ VALUE worksheet_get_vertical_dpi_(VALUE self);
66
+ VALUE worksheet_set_vertical_dpi_(VALUE self, VALUE val);
67
+
68
+
69
+ lxw_col_t value_to_col(VALUE value);
70
+ int extract_cell(int argc, VALUE *argv, lxw_row_t *row, lxw_col_t *col);
71
+ int extract_range(int argc, VALUE *argv, lxw_row_t *row1, lxw_col_t *col1,
72
+ lxw_row_t *row2, lxw_col_t *col2);
73
+
74
+ #endif /// __WORKSHEET__
@@ -0,0 +1,239 @@
1
+ #include <ruby.h>
2
+ #include "xlsxwriter.h"
3
+ #include "chart.h"
4
+ #include "workbook.h"
5
+ #include "workbook_properties.h"
6
+ #include "worksheet.h"
7
+
8
+ VALUE mXlsxWriter;
9
+ VALUE cWorkbook;
10
+ VALUE cWorksheet;
11
+ VALUE mXlsxFormat;
12
+ VALUE cWorkbookProperties;
13
+ VALUE cChart;
14
+ VALUE cChartSeries;
15
+ VALUE cChartAxis;
16
+
17
+ void Init_xlsxwriter() {
18
+ mXlsxWriter = rb_define_module("XlsxWriter");
19
+ mXlsxFormat = rb_define_module_under(mXlsxWriter, "Format");
20
+ cWorkbook = rb_define_class_under(mXlsxWriter, "Workbook", rb_cObject);
21
+ cWorksheet = rb_define_class_under(mXlsxWriter, "Worksheet", rb_cObject);
22
+ cWorkbookProperties
23
+ = rb_define_class_under(cWorkbook, "Properties", rb_cObject);
24
+ cChart = rb_define_class_under(cWorkbook, "Chart", rb_cObject);
25
+ cChartSeries = rb_define_class_under(cChart, "Series", rb_cObject);
26
+ cChartAxis = rb_define_class_under(cChart, "Axis", rb_cObject);
27
+
28
+ rb_define_alloc_func(cWorkbook, workbook_alloc);
29
+ rb_define_singleton_method(cWorkbook, "new", workbook_new_, -1);
30
+ rb_define_alias(rb_singleton_class(cWorkbook), "open", "new");
31
+ rb_define_method(cWorkbook, "initialize", workbook_init, -1);
32
+ rb_define_method(cWorkbook, "close", workbook_release, 0);
33
+ rb_define_method(cWorkbook, "add_worksheet", workbook_add_worksheet_, -1);
34
+ rb_define_method(cWorkbook, "add_format", workbook_add_format_, 2);
35
+ rb_define_method(cWorkbook, "add_chart", workbook_add_chart_, 1);
36
+ rb_define_method(cWorkbook, "set_default_xf_indices", workbook_set_default_xf_indices_, 0);
37
+ rb_define_method(cWorkbook, "properties", workbook_properties_, 0);
38
+ rb_define_method(cWorkbook, "define_name", workbook_define_name_, 2);
39
+ rb_define_method(cWorkbook, "validate_worksheet_name", workbook_validate_worksheet_name_, 1);
40
+
41
+ rb_define_attr(cWorkbook, "font_sizes", 1, 0);
42
+
43
+
44
+ rb_define_alloc_func(cWorksheet, worksheet_alloc);
45
+ rb_define_method(cWorksheet, "initialize", worksheet_init, -1);
46
+ rb_define_method(cWorksheet, "free", worksheet_release, 0);
47
+ rb_define_method(cWorksheet, "write_string", worksheet_write_string_, -1);
48
+ rb_define_method(cWorksheet, "write_number", worksheet_write_number_, -1);
49
+ rb_define_method(cWorksheet, "write_formula", worksheet_write_formula_, -1);
50
+ rb_define_method(cWorksheet, "write_array_formula", worksheet_write_array_formula_, -1);
51
+ rb_define_method(cWorksheet, "write_datetime", worksheet_write_datetime_, -1);
52
+ rb_define_method(cWorksheet, "write_url", worksheet_write_url_, -1);
53
+ rb_define_method(cWorksheet, "write_boolean", worksheet_write_boolean_, -1);
54
+ rb_define_method(cWorksheet, "write_blank", worksheet_write_blank_, -1);
55
+ rb_define_method(cWorksheet, "write_formula_num", worksheet_write_formula_num_, -1);
56
+ rb_define_method(cWorksheet, "set_row", worksheet_set_row_, 2);
57
+ rb_define_method(cWorksheet, "set_column", worksheet_set_column_, 3);
58
+ rb_define_method(cWorksheet, "insert_image", worksheet_insert_image_, -1);
59
+ rb_define_method(cWorksheet, "insert_chart", worksheet_insert_chart_, -1);
60
+ rb_define_method(cWorksheet, "merge_range", worksheet_merge_range_, -1);
61
+ rb_define_method(cWorksheet, "autofilter", worksheet_autofilter_, -1);
62
+ rb_define_method(cWorksheet, "activate", worksheet_activate_, 0);
63
+ rb_define_method(cWorksheet, "select", worksheet_select_, 0);
64
+ rb_define_method(cWorksheet, "hide", worksheet_hide_, 0);
65
+ rb_define_method(cWorksheet, "set_first_sheet", worksheet_set_first_sheet_, 0);
66
+ rb_define_method(cWorksheet, "freeze_panes", worksheet_freeze_panes_, -1);
67
+ rb_define_method(cWorksheet, "split_panes", worksheet_split_panes_, 2);
68
+ rb_define_method(cWorksheet, "set_selection", worksheet_set_selection_, -1);
69
+ rb_define_method(cWorksheet, "set_landscape", worksheet_set_landscape_, 0);
70
+ rb_define_method(cWorksheet, "set_portrait", worksheet_set_portrait_, 0);
71
+ rb_define_method(cWorksheet, "set_page_view", worksheet_set_page_view_, 0);
72
+ rb_define_method(cWorksheet, "paper=", worksheet_set_paper_, 1);
73
+ rb_define_method(cWorksheet, "set_margins", worksheet_set_margins_, 4);
74
+ rb_define_method(cWorksheet, "set_header", worksheet_set_header_, 1);
75
+ rb_define_method(cWorksheet, "set_footer", worksheet_set_footer_, 1);
76
+ rb_define_method(cWorksheet, "h_pagebreaks=", worksheet_set_h_pagebreaks_, 1);
77
+ rb_define_method(cWorksheet, "v_pagebreaks=", worksheet_set_v_pagebreaks_, 1);
78
+ rb_define_method(cWorksheet, "print_across", worksheet_print_across_, 0);
79
+ rb_define_method(cWorksheet, "zoom=", worksheet_set_zoom_, 1);
80
+ rb_define_method(cWorksheet, "gridlines=", worksheet_gridlines_, 1);
81
+ rb_define_method(cWorksheet, "center_horizontally", worksheet_center_horizontally_, 0);
82
+ rb_define_method(cWorksheet, "center_vertically", worksheet_center_vertically_, 0);
83
+ rb_define_method(cWorksheet, "print_row_col_headers", worksheet_print_row_col_headers_, 0);
84
+ rb_define_method(cWorksheet, "repeat_rows", worksheet_repeat_rows_, 2);
85
+ rb_define_method(cWorksheet, "repeat_columns", worksheet_repeat_columns_, 2);
86
+ rb_define_method(cWorksheet, "print_area", worksheet_print_area_, -1);
87
+ rb_define_method(cWorksheet, "fit_to_pages", worksheet_fit_to_pages_, 2);
88
+ rb_define_method(cWorksheet, "start_page=", worksheet_set_start_page_, 1);
89
+ rb_define_method(cWorksheet, "print_scale=", worksheet_set_print_scale_, 1);
90
+ rb_define_method(cWorksheet, "right_to_left", worksheet_right_to_left_, 0);
91
+ rb_define_method(cWorksheet, "hide_zero", worksheet_hide_zero_, 0);
92
+ rb_define_method(cWorksheet, "tab_color=", worksheet_set_tab_color_, 1);
93
+ rb_define_method(cWorksheet, "protect", worksheet_protect_, -1);
94
+ rb_define_method(cWorksheet, "set_default_row", worksheet_set_default_row_, 2);
95
+
96
+ rb_define_method(cWorksheet, "vertical_dpi", worksheet_get_vertical_dpi_, 0);
97
+ rb_define_method(cWorksheet, "vertical_dpi=", worksheet_set_vertical_dpi_, 1);
98
+
99
+ rb_define_method(cWorkbookProperties, "initialize", workbook_properties_init_, 1);
100
+ rb_define_method(cWorkbookProperties, "[]=", workbook_properties_set_, 2);
101
+ #define DEF_PROP_HANDLER(prop) rb_define_method(cWorkbookProperties, #prop "=", workbook_properties_set_dir_, 1);
102
+ DEF_PROP_HANDLER(title);
103
+ DEF_PROP_HANDLER(subject);
104
+ DEF_PROP_HANDLER(author);
105
+ DEF_PROP_HANDLER(manager);
106
+ DEF_PROP_HANDLER(company);
107
+ DEF_PROP_HANDLER(category);
108
+ DEF_PROP_HANDLER(keywords);
109
+ DEF_PROP_HANDLER(comments);
110
+ DEF_PROP_HANDLER(status);
111
+ DEF_PROP_HANDLER(hyperlink_base);
112
+ #undef DEF_PROP_HANDLER
113
+
114
+
115
+ rb_define_alloc_func(cChart, chart_alloc);
116
+ rb_define_method(cChart, "initialize", chart_init, 2);
117
+ rb_define_method(cChart, "add_series", chart_add_series_, -1);
118
+
119
+ rb_define_method(cChart, "axis_id_1", chart_get_axis_id_1_, 0);
120
+ rb_define_method(cChart, "axis_id_1=", chart_set_axis_id_1_, 1);
121
+ rb_define_method(cChart, "axis_id_2", chart_get_axis_id_2_, 0);
122
+ rb_define_method(cChart, "axis_id_2=", chart_set_axis_id_2_, 1);
123
+
124
+ rb_define_alloc_func(cChartSeries, chart_series_alloc);
125
+ rb_define_method(cChartSeries, "initialize", chart_series_init, -1);
126
+
127
+
128
+ #define MAP_LXW_FMT_CONST(name) rb_define_const(mXlsxFormat, #name, INT2NUM(LXW_##name))
129
+ MAP_LXW_FMT_CONST(COLOR_BLACK);
130
+ MAP_LXW_FMT_CONST(COLOR_BLUE);
131
+ MAP_LXW_FMT_CONST(COLOR_BROWN);
132
+ MAP_LXW_FMT_CONST(COLOR_CYAN);
133
+ MAP_LXW_FMT_CONST(COLOR_GRAY);
134
+ MAP_LXW_FMT_CONST(COLOR_GREEN);
135
+ MAP_LXW_FMT_CONST(COLOR_LIME);
136
+ MAP_LXW_FMT_CONST(COLOR_MAGENTA);
137
+ MAP_LXW_FMT_CONST(COLOR_NAVY);
138
+ MAP_LXW_FMT_CONST(COLOR_ORANGE);
139
+ MAP_LXW_FMT_CONST(COLOR_PINK);
140
+ MAP_LXW_FMT_CONST(COLOR_PURPLE);
141
+ MAP_LXW_FMT_CONST(COLOR_RED);
142
+ MAP_LXW_FMT_CONST(COLOR_SILVER);
143
+ MAP_LXW_FMT_CONST(COLOR_WHITE);
144
+ MAP_LXW_FMT_CONST(COLOR_YELLOW);
145
+
146
+ MAP_LXW_FMT_CONST(UNDERLINE_SINGLE);
147
+ MAP_LXW_FMT_CONST(UNDERLINE_DOUBLE);
148
+ MAP_LXW_FMT_CONST(UNDERLINE_SINGLE_ACCOUNTING);
149
+ MAP_LXW_FMT_CONST(UNDERLINE_DOUBLE_ACCOUNTING);
150
+
151
+ MAP_LXW_FMT_CONST(FONT_SUPERSCRIPT);
152
+ MAP_LXW_FMT_CONST(FONT_SUBSCRIPT);
153
+
154
+ MAP_LXW_FMT_CONST(ALIGN_LEFT);
155
+ MAP_LXW_FMT_CONST(ALIGN_CENTER);
156
+ MAP_LXW_FMT_CONST(ALIGN_RIGHT);
157
+ MAP_LXW_FMT_CONST(ALIGN_FILL);
158
+ MAP_LXW_FMT_CONST(ALIGN_JUSTIFY);
159
+ MAP_LXW_FMT_CONST(ALIGN_CENTER_ACROSS);
160
+ MAP_LXW_FMT_CONST(ALIGN_DISTRIBUTED);
161
+
162
+ MAP_LXW_FMT_CONST(ALIGN_VERTICAL_TOP);
163
+ MAP_LXW_FMT_CONST(ALIGN_VERTICAL_BOTTOM);
164
+ MAP_LXW_FMT_CONST(ALIGN_VERTICAL_CENTER);
165
+ MAP_LXW_FMT_CONST(ALIGN_VERTICAL_JUSTIFY);
166
+ MAP_LXW_FMT_CONST(ALIGN_VERTICAL_DISTRIBUTED);
167
+
168
+ MAP_LXW_FMT_CONST(PATTERN_SOLID);
169
+ MAP_LXW_FMT_CONST(PATTERN_MEDIUM_GRAY);
170
+ MAP_LXW_FMT_CONST(PATTERN_DARK_GRAY);
171
+ MAP_LXW_FMT_CONST(PATTERN_LIGHT_GRAY);
172
+ MAP_LXW_FMT_CONST(PATTERN_DARK_HORIZONTAL);
173
+ MAP_LXW_FMT_CONST(PATTERN_DARK_VERTICAL);
174
+ MAP_LXW_FMT_CONST(PATTERN_DARK_DOWN);
175
+ MAP_LXW_FMT_CONST(PATTERN_DARK_UP);
176
+ MAP_LXW_FMT_CONST(PATTERN_DARK_GRID);
177
+ MAP_LXW_FMT_CONST(PATTERN_DARK_TRELLIS);
178
+ MAP_LXW_FMT_CONST(PATTERN_LIGHT_HORIZONTAL);
179
+ MAP_LXW_FMT_CONST(PATTERN_LIGHT_VERTICAL);
180
+ MAP_LXW_FMT_CONST(PATTERN_LIGHT_DOWN);
181
+ MAP_LXW_FMT_CONST(PATTERN_LIGHT_UP);
182
+ MAP_LXW_FMT_CONST(PATTERN_LIGHT_GRID);
183
+ MAP_LXW_FMT_CONST(PATTERN_LIGHT_TRELLIS);
184
+ MAP_LXW_FMT_CONST(PATTERN_GRAY_125);
185
+ MAP_LXW_FMT_CONST(PATTERN_GRAY_0625);
186
+
187
+ MAP_LXW_FMT_CONST(BORDER_THIN);
188
+ MAP_LXW_FMT_CONST(BORDER_MEDIUM);
189
+ MAP_LXW_FMT_CONST(BORDER_DASHED);
190
+ MAP_LXW_FMT_CONST(BORDER_DOTTED);
191
+ MAP_LXW_FMT_CONST(BORDER_THICK);
192
+ MAP_LXW_FMT_CONST(BORDER_DOUBLE);
193
+ MAP_LXW_FMT_CONST(BORDER_HAIR);
194
+ MAP_LXW_FMT_CONST(BORDER_MEDIUM_DASHED);
195
+ MAP_LXW_FMT_CONST(BORDER_DASH_DOT);
196
+ MAP_LXW_FMT_CONST(BORDER_MEDIUM_DASH_DOT);
197
+ MAP_LXW_FMT_CONST(BORDER_DASH_DOT_DOT);
198
+ MAP_LXW_FMT_CONST(BORDER_MEDIUM_DASH_DOT_DOT);
199
+ MAP_LXW_FMT_CONST(BORDER_SLANT_DASH_DOT);
200
+
201
+ MAP_LXW_FMT_CONST(DIAGONAL_BORDER_UP);
202
+ MAP_LXW_FMT_CONST(DIAGONAL_BORDER_DOWN);
203
+ MAP_LXW_FMT_CONST(DIAGONAL_BORDER_UP_DOWN);
204
+ #undef MAP_LXW_FMT_CONST
205
+
206
+ #define MAP_LXW_WH_CONST(name, val_name) rb_define_const(cWorksheet, #name, INT2NUM(LXW_##val_name))
207
+ MAP_LXW_WH_CONST(DEF_COL_WIDTH, DEF_COL_WIDTH);
208
+ MAP_LXW_WH_CONST(DEF_ROW_HEIGHT, DEF_ROW_HEIGHT);
209
+
210
+ MAP_LXW_WH_CONST(GRIDLINES_HIDE_ALL, HIDE_ALL_GRIDLINES);
211
+ MAP_LXW_WH_CONST(GRIDLINES_SHOW_SCREEN, SHOW_SCREEN_GRIDLINES);
212
+ MAP_LXW_WH_CONST(GRIDLINES_SHOW_PRINT, SHOW_PRINT_GRIDLINES);
213
+ MAP_LXW_WH_CONST(GRIDLINES_SHOW_ALL, SHOW_ALL_GRIDLINES);
214
+ #undef MAP_LXW_WH_CONST
215
+
216
+ #define MAP_CHART_CONST(name) rb_define_const(cChart, #name, INT2NUM(LXW_CHART_##name))
217
+ MAP_CHART_CONST(NONE);
218
+ MAP_CHART_CONST(AREA);
219
+ MAP_CHART_CONST(AREA_STACKED);
220
+ MAP_CHART_CONST(AREA_STACKED_PERCENT);
221
+ MAP_CHART_CONST(BAR);
222
+ MAP_CHART_CONST(BAR_STACKED);
223
+ MAP_CHART_CONST(BAR_STACKED_PERCENT);
224
+ MAP_CHART_CONST(COLUMN);
225
+ MAP_CHART_CONST(COLUMN_STACKED);
226
+ MAP_CHART_CONST(COLUMN_STACKED_PERCENT);
227
+ MAP_CHART_CONST(DOUGHNUT);
228
+ MAP_CHART_CONST(LINE);
229
+ MAP_CHART_CONST(PIE);
230
+ MAP_CHART_CONST(SCATTER);
231
+ MAP_CHART_CONST(SCATTER_STRAIGHT);
232
+ MAP_CHART_CONST(SCATTER_STRAIGHT_WITH_MARKERS);
233
+ MAP_CHART_CONST(SCATTER_SMOOTH);
234
+ MAP_CHART_CONST(SCATTER_SMOOTH_WITH_MARKERS);
235
+ MAP_CHART_CONST(RADAR);
236
+ MAP_CHART_CONST(RADAR_WITH_MARKERS);
237
+ MAP_CHART_CONST(RADAR_FILLED);
238
+ #undef MAP_CHART_CONST
239
+ }
@@ -0,0 +1,6 @@
1
+ module XlsxWriter
2
+ end
3
+
4
+ require 'xlsxwriter/version'
5
+ require 'xlsxwriter/xlsxwriter'
6
+ require 'xlsxwriter/worksheet'
@@ -0,0 +1,3 @@
1
+ module XlsxWriter
2
+ VERSION='0.0.2'.freeze
3
+ end
@@ -0,0 +1,72 @@
1
+ class XlsxWriter::Worksheet
2
+ attr_reader :current_row
3
+
4
+ THIN_CHARS = '^.acfijklrstxzFIJL()-'.freeze
5
+
6
+ def add_row(row, style: nil, height: nil, types: nil)
7
+ row_idx = @current_row ||= 0
8
+ @current_row += 1
9
+
10
+ row.each_with_index do |value, idx|
11
+ cell_style = style.is_a?(Array) ? style[idx] : style
12
+ cell_type = types.is_a?(Array) ? types[idx] : types
13
+
14
+ case cell_type && cell_type.to_sym
15
+ when :string
16
+ write_string(row_idx, idx, value.to_s, cell_style)
17
+ update_col_auto_width(idx, value.to_s, cell_style)
18
+ when :number
19
+ write_number(row_idx, idx, value.to_f, cell_style)
20
+ when :formula
21
+ write_formula(row_idx, idx, value, cell_style)
22
+ when :datetime, :date, :time
23
+ write_datetime(row_idx, idx, value.to_time, cell_style)
24
+ when :url
25
+ write_url(row_idx, idx, value, cell_style)
26
+ update_col_auto_width(idx, value.to_s, cell_style)
27
+ when :boolean
28
+ write_boolean(row_idx, idx, value, cell_style)
29
+ when :blank
30
+ write_blank(row_idx, idx, cell_style)
31
+ when nil
32
+ case value
33
+ when Numeric
34
+ write_number(row_idx, idx, value, cell_style)
35
+ when TrueClass, FalseClass
36
+ write_boolean(row_idx, idx, value, cell_style)
37
+ when '', nil
38
+ write_blank(row_idx, idx, cell_style)
39
+ when /\A=/
40
+ write_formula(row_idx, idx, value, cell_style)
41
+ else
42
+ if value.is_a?(Time) ||
43
+ (defined?(Date) && value.is_a?(Date)) ||
44
+ (defined?(DateTime) && value.is_a?(DateTime))
45
+ write_datetime(row_idx, idx, value.to_time, cell_style)
46
+ else # assume string
47
+ write_string(row_idx, idx, value.to_s, cell_style)
48
+ update_col_auto_width(idx, value.to_s, cell_style)
49
+ end
50
+ end
51
+ else
52
+ raise ArgumentError, "Unknown cell type #{cell_type}."
53
+ end
54
+
55
+ set_row(row_idx, height: height) if height
56
+
57
+ nil
58
+ end
59
+ end
60
+
61
+ def update_col_auto_width(idx, val, format)
62
+ font_scale = (@workbook.font_sizes[format] || 11) / 10.0
63
+ width = (val.count(THIN_CHARS) + 3) * font_scale
64
+ @col_auto_widths[idx] = [@col_auto_widths[idx], width].compact.max
65
+ end
66
+
67
+ def apply_auto_widths
68
+ @col_auto_widths.each_with_index do |width, idx|
69
+ set_column(idx, idx, width: width) if width
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ lib_dir = File.join(base_dir, "lib")
5
+ test_dir = File.join(base_dir, "test")
6
+
7
+ $LOAD_PATH.unshift(lib_dir)
8
+
9
+ require 'test/unit'
10
+
11
+ exit Test::Unit::AutoRunner.run(true, test_dir)
@@ -0,0 +1,109 @@
1
+ require 'test/unit'
2
+ require 'zip'
3
+
4
+ module XlsxComparable
5
+ def assert_xlsx_equal(got_path, exp_path, ignore_files=[], ignore_elements={})
6
+ Zip::File.open(exp_path) do |exp_zip|
7
+ Zip::File.open(got_path) do |got_zip|
8
+ exp_files = exp_zip.glob('**/*').select { |e| !ignore_files.include?(e.name) }
9
+ got_files = got_zip.glob('**/*').select { |e| !ignore_files.include?(e.name) }
10
+ assert_equal(got_files.map(&:name).sort, exp_files.map(&:name).sort)
11
+
12
+ exp_files.each do |exp_entry|
13
+ next unless exp_entry.file?
14
+ exp_xml_str = exp_zip.read(exp_entry.name)
15
+ got_xml_str = got_zip.read(exp_entry.name)
16
+
17
+ if %w(.png .jpeg .bmp .bin).include?(File.extname(exp_entry.name))
18
+ exp_xml_str.force_encoding('BINARY')
19
+ assert_equal(got_xml_str, exp_xml_str)
20
+ next
21
+ end
22
+
23
+ case exp_entry.name
24
+ when 'docProps/core.xml'
25
+ exp_xml_str.gsub!(/ ?John/, '')
26
+ exp_xml_str.gsub!(/\d{4}-\d\d-\d\dT\d\d\:\d\d:\d\dZ/, '')
27
+ got_xml_str.gsub!(/\d{4}-\d\d-\d\dT\d\d\:\d\d:\d\dZ/, '')
28
+ when 'xl/workbook.xml'
29
+ exp_xml_str.gsub!(/<workbookView[^>]*>/, '<workbookView/>')
30
+ exp_xml_str.gsub!(/<calcPr[^>]*>/, '<calcPr/>')
31
+ got_xml_str.gsub!(/<workbookView[^>]*>/, '<workbookView/>')
32
+ got_xml_str.gsub!(/<calcPr[^>]*>/, '<calcPr/>')
33
+ when /xl\/worksheets\/sheet\d+.xml/
34
+ exp_xml_str.gsub!(/horizontalDpi="200" /, '')
35
+ exp_xml_str.gsub!(/verticalDpi="200" /, '')
36
+ exp_xml_str.gsub!(/(<pageSetup[^>]*) r:id="rId1"/, '\1')
37
+ when /xl\/charts\/chart\d+.xml/
38
+ exp_xml_str.gsub!(/<c:pageMargins[^>]*>/, '<c:pageMargins/>')
39
+ got_xml_str.gsub!(/<c:pageMargins[^>]*>/, '<c:pageMargins/>')
40
+ end
41
+
42
+ if exp_entry.name =~ /.vml\z/
43
+ got_xml = _xml_to_list(got_xml_str)
44
+ exp_xml = _vml_to_list(exp_xml_str)
45
+ else
46
+ got_xml = _xml_to_list(got_xml_str)
47
+ exp_xml = _xml_to_list(exp_xml_str)
48
+ end
49
+
50
+ if ignore_elements.key?(exp_entry.name)
51
+ patterns = ignore_elements[exp_entry.name]
52
+ exp_xml.select! { |tag| patterns.none? { |pattern| tag.include? pattern } }
53
+ got_xml.select! { |tag| patterns.none? { |pattern| tag.include? pattern } }
54
+ end
55
+
56
+ if exp_entry.name == '[Content_Types].xml' || exp_entry.name =~ /.rels\z/
57
+ got_xml = _sort_rel_file_data(got_xml)
58
+ exp_xml = _sort_rel_file_data(exp_xml)
59
+ end
60
+
61
+ assert_equal got_xml, exp_xml
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def _xml_to_list(xml_str)
70
+ elements = xml_str.strip.split(/>\s*</).each do |el|
71
+ el.gsub!("\r", '')
72
+ el.insert 0, '<' unless el[0] == '<'
73
+ el << '>' unless el[-1] == '>'
74
+ end
75
+ end
76
+
77
+ def _vml_to_list(vml_str)
78
+ vml_str.gsub!("\r", '')
79
+
80
+ vml = vml_str.split("\n")
81
+ vml_str = ''.tap do |vml_str|
82
+ vml.each do |line|
83
+ line.strip!
84
+ next if line == ''
85
+ line.gsub!(?', ?")
86
+ line << ' ' if line =~ '"$'
87
+ line << "\n" if line =~ '>$'
88
+ line.gsub!('><', ">\n<")
89
+ if line == "<x:Anchor>\n"
90
+ line.strip!
91
+ end
92
+ wml_str << line
93
+ end
94
+ end
95
+ vml_str.rstrip.split("\n")
96
+ end
97
+
98
+ def _sort_rel_file_data(xml_elements)
99
+ first = xml_elements.shift
100
+ last = xml_elements.pop
101
+
102
+ xml_elements.sort!
103
+
104
+ xml_elements.unshift(first)
105
+ xml_elements.push(last)
106
+
107
+ xml_elements
108
+ end
109
+ end