xlsxwriter 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +4 -16
- data/ext/xlsxwriter/chart.c +499 -4
- data/ext/xlsxwriter/chart.h +11 -9
- data/ext/xlsxwriter/format.c +89 -1
- data/ext/xlsxwriter/format.h +4 -0
- data/ext/xlsxwriter/workbook.c +145 -6
- data/ext/xlsxwriter/workbook.h +2 -22
- data/ext/xlsxwriter/workbook_properties.c +61 -14
- data/ext/xlsxwriter/workbook_properties.h +4 -3
- data/ext/xlsxwriter/worksheet.c +406 -55
- data/ext/xlsxwriter/worksheet.h +5 -58
- data/ext/xlsxwriter/xlsxwriter.c +26 -227
- data/lib/xlsxwriter/version.rb +2 -1
- data/lib/xlsxwriter/worksheet.rb +18 -6
- data/test/test-chart-axis.rb +102 -0
- data/test/test-chart-bar.rb +34 -0
- data/test/test-chart-column.rb +30 -0
- data/test/test-chart-doughnut.rb +31 -0
- data/test/test-chart-pie.rb +44 -0
- data/test/test-chart-scatter.rb +29 -0
- data/test/test-chart-size.rb +45 -0
- data/test/test-chart-title.rb +44 -0
- data/test/test-panes.rb +18 -18
- metadata +18 -2
data/ext/xlsxwriter/worksheet.h
CHANGED
@@ -8,67 +8,14 @@ struct worksheet {
|
|
8
8
|
lxw_worksheet *worksheet;
|
9
9
|
};
|
10
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
11
|
lxw_col_t value_to_col(VALUE value);
|
70
12
|
int extract_cell(int argc, VALUE *argv, lxw_row_t *row, lxw_col_t *col);
|
71
13
|
int extract_range(int argc, VALUE *argv, lxw_row_t *row1, lxw_col_t *col1,
|
72
14
|
lxw_row_t *row2, lxw_col_t *col2);
|
15
|
+
lxw_image_options val_to_lxw_image_options(VALUE opts, char *with_options);
|
16
|
+
|
17
|
+
void init_xlsxwriter_worksheet();
|
18
|
+
|
19
|
+
extern VALUE cWorksheet;
|
73
20
|
|
74
21
|
#endif /// __WORKSHEET__
|
data/ext/xlsxwriter/xlsxwriter.c
CHANGED
@@ -1,239 +1,38 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include "xlsxwriter.h"
|
3
3
|
#include "chart.h"
|
4
|
+
#include "format.h"
|
4
5
|
#include "workbook.h"
|
5
6
|
#include "workbook_properties.h"
|
6
7
|
#include "worksheet.h"
|
7
8
|
|
8
9
|
VALUE mXlsxWriter;
|
9
|
-
VALUE cWorkbook;
|
10
|
-
VALUE cWorksheet;
|
11
|
-
VALUE mXlsxFormat;
|
12
|
-
VALUE cWorkbookProperties;
|
13
|
-
VALUE cChart;
|
14
|
-
VALUE cChartSeries;
|
15
|
-
VALUE cChartAxis;
|
16
10
|
|
11
|
+
/* Document-module: XlsxWriter
|
12
|
+
*
|
13
|
+
* XlsxWriter is a ruby interface to libxlsxwriter.
|
14
|
+
*
|
15
|
+
* It provides a couple of useful shorthands (like being able to pass cells and
|
16
|
+
* ranges as both numbers, cell strings and range strings.
|
17
|
+
*
|
18
|
+
* It also has column authowidth functionality partially taken from Axlsx gem
|
19
|
+
* enable by default.
|
20
|
+
*
|
21
|
+
* Simple example of using the XlsxWriter to generate an xlsx file containing
|
22
|
+
* 'Hello' string in the first rows of column 'A':
|
23
|
+
*
|
24
|
+
* XlsxWriter::Workbook.open('/tmp/text.xlsx') do |wb|
|
25
|
+
* ws.add_worksheet do |ws|
|
26
|
+
* 10.times { |i| ws.add_row ['Hello!'] }
|
27
|
+
* end
|
28
|
+
* end
|
29
|
+
*/
|
17
30
|
void Init_xlsxwriter() {
|
18
|
-
mXlsxWriter
|
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);
|
31
|
+
mXlsxWriter = rb_define_module("XlsxWriter");
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
|
+
init_xlsxwriter_workbook();
|
34
|
+
init_xlsxwriter_workbook_properties();
|
35
|
+
init_xlsxwriter_format();
|
36
|
+
init_xlsxwriter_worksheet();
|
37
|
+
init_xlsxwriter_chart();
|
239
38
|
}
|
data/lib/xlsxwriter/version.rb
CHANGED
data/lib/xlsxwriter/worksheet.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
class XlsxWriter::Worksheet
|
2
|
+
# Last row number written with #add_row
|
2
3
|
attr_reader :current_row
|
3
4
|
|
5
|
+
# Thiner characters list used for column width logic mimicing axlsx behaviour
|
4
6
|
THIN_CHARS = '^.acfijklrstxzFIJL()-'.freeze
|
5
7
|
|
8
|
+
# Write a +row+. If no +types+ passed XlsxWriter tries to deduce them automatically.
|
9
|
+
#
|
10
|
+
# Both +types+ and +style+ may be an array as well as a symbol.
|
11
|
+
# In the latter case they are applied to all cells in the +row+.
|
12
|
+
#
|
13
|
+
# +height+ is a Numeric that specifies the row height.
|
6
14
|
def add_row(row, style: nil, height: nil, types: nil)
|
7
15
|
row_idx = @current_row ||= 0
|
8
16
|
@current_row += 1
|
@@ -58,15 +66,19 @@ class XlsxWriter::Worksheet
|
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
61
|
-
|
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
|
-
|
69
|
+
# Apply cols automatic widths calculated by #add_row.
|
67
70
|
def apply_auto_widths
|
68
71
|
@col_auto_widths.each_with_index do |width, idx|
|
69
72
|
set_column(idx, idx, width: width) if width
|
70
73
|
end
|
71
74
|
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Updates the col auto width value to fit the string.
|
79
|
+
def update_col_auto_width(idx, val, format)
|
80
|
+
font_scale = (@workbook.font_sizes[format] || 11) / 10.0
|
81
|
+
width = (val.count(THIN_CHARS) + 3) * font_scale
|
82
|
+
@col_auto_widths[idx] = [@col_auto_widths[idx], width].compact.max
|
83
|
+
end
|
72
84
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative './xlsx-func-testcase'
|
2
|
+
|
3
|
+
class TestChartAxis < XlsxWriterTestCase
|
4
|
+
DATA = [
|
5
|
+
[1, 2, 3],
|
6
|
+
[2, 4, 6],
|
7
|
+
[3, 6, 9],
|
8
|
+
[4, 8, 12],
|
9
|
+
[5, 10, 15]
|
10
|
+
]
|
11
|
+
|
12
|
+
test 'chart_axis01' do |wb|
|
13
|
+
wb.add_worksheet do |ws|
|
14
|
+
DATA.each { |row| ws.add_row row }
|
15
|
+
|
16
|
+
wb.add_chart(XlsxWriter::Workbook::Chart::BAR) do |chart|
|
17
|
+
chart.axis_id_1 = 58_955_648
|
18
|
+
chart.axis_id_2 = 68_446_848
|
19
|
+
|
20
|
+
chart.add_series '=Sheet1!$A$1:$A$5'
|
21
|
+
chart.add_series '=Sheet1!$B$1:$B$5'
|
22
|
+
chart.add_series '=Sheet1!$C$1:$C$5'
|
23
|
+
|
24
|
+
chart.x_axis.name = 'XXX'
|
25
|
+
chart.y_axis.name = 'YYY'
|
26
|
+
|
27
|
+
ws.insert_chart 'E9', chart
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'chart_axis06' do |wb|
|
33
|
+
wb.add_worksheet do |ws|
|
34
|
+
[ [2, 60], [4, 30], [6, 10] ].each { |row| ws.add_row row }
|
35
|
+
wb.add_chart(XlsxWriter::Workbook::Chart::PIE) do |chart|
|
36
|
+
chart.add_series '=Sheet1!$A$1:$A$3', '=Sheet1!$B$1:$B$3'
|
37
|
+
chart.title = 'Title'
|
38
|
+
chart.x_axis.name = 'XXX'
|
39
|
+
chart.y_axis.name = 'YYY'
|
40
|
+
ws.insert_chart('E9', chart)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'chart_axis26' do |wb|
|
46
|
+
wb.add_worksheet do |ws|
|
47
|
+
DATA.each { |row| ws.add_row row }
|
48
|
+
|
49
|
+
wb.add_chart(XlsxWriter::Workbook::Chart::LINE) do |chart|
|
50
|
+
chart.axis_id_1 = 73_048_448
|
51
|
+
chart.axis_id_2 = 73_049_984
|
52
|
+
|
53
|
+
chart.add_series '=Sheet1!$A$1:$A$5'
|
54
|
+
chart.add_series '=Sheet1!$B$1:$B$5'
|
55
|
+
chart.add_series '=Sheet1!$C$1:$C$5'
|
56
|
+
|
57
|
+
chart.x_axis.set_num_font rotation: 45, baseline: -1
|
58
|
+
|
59
|
+
ws.insert_chart('E9', chart)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'chart_axis35' do |wb|
|
65
|
+
wb.add_worksheet do |ws|
|
66
|
+
DATA.each { |row| ws.add_row row }
|
67
|
+
|
68
|
+
wb.add_chart(XlsxWriter::Workbook::Chart::COLUMN) do |chart|
|
69
|
+
chart.axis_id_1 = 63_008_128
|
70
|
+
chart.axis_id_2 = 62_522_496
|
71
|
+
|
72
|
+
chart.add_series '=Sheet1!$A$1:$A$5'
|
73
|
+
chart.add_series '=Sheet1!$B$1:$B$5'
|
74
|
+
chart.add_series '=Sheet1!$C$1:$C$5'
|
75
|
+
|
76
|
+
chart.y_axis.set_line none: true
|
77
|
+
|
78
|
+
ws.insert_chart('E9', chart)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'chart_axis38' do |wb|
|
84
|
+
wb.add_worksheet do |ws|
|
85
|
+
DATA.each { |row| ws.add_row row }
|
86
|
+
|
87
|
+
wb.add_chart(XlsxWriter::Workbook::Chart::COLUMN) do |chart|
|
88
|
+
chart.axis_id_1 = 45_642_496
|
89
|
+
chart.axis_id_2 = 45_644_416
|
90
|
+
|
91
|
+
chart.add_series '=Sheet1!$A$1:$A$5'
|
92
|
+
chart.add_series '=Sheet1!$B$1:$B$5'
|
93
|
+
chart.add_series '=Sheet1!$C$1:$C$5'
|
94
|
+
|
95
|
+
chart.y_axis.set_line color: XlsxWriter::Format::COLOR_YELLOW
|
96
|
+
chart.y_axis.set_fill color: XlsxWriter::Format::COLOR_RED
|
97
|
+
|
98
|
+
ws.insert_chart 'E9', chart
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|