write_xlsx 0.0.2
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.
- data/.document +5 -0
- data/.gitattributes +1 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +82 -0
- data/Rakefile +78 -0
- data/VERSION +1 -0
- data/examples/a_simple.rb +45 -0
- data/examples/array_formula.rb +33 -0
- data/examples/autofilter.rb +235 -0
- data/examples/chart_area.rb +59 -0
- data/examples/chart_bar.rb +59 -0
- data/examples/chart_column.rb +58 -0
- data/examples/chart_line.rb +59 -0
- data/examples/chart_pie.rb +49 -0
- data/examples/chart_scatter.rb +59 -0
- data/examples/chart_stock.rb +65 -0
- data/examples/colors.rb +130 -0
- data/examples/comments1.rb +12 -0
- data/examples/comments2.rb +335 -0
- data/examples/conditional_format.rb +67 -0
- data/examples/data_validate.rb +279 -0
- data/examples/defined_name.rb +28 -0
- data/examples/demo.rb +104 -0
- data/examples/diag_border.rb +26 -0
- data/examples/headers.rb +119 -0
- data/examples/hide_sheet.rb +30 -0
- data/examples/hyperlink1.rb +58 -0
- data/examples/indent.rb +28 -0
- data/examples/merge1.rb +38 -0
- data/examples/merge2.rb +48 -0
- data/examples/merge3.rb +43 -0
- data/examples/merge4.rb +82 -0
- data/examples/merge5.rb +70 -0
- data/examples/merge6.rb +48 -0
- data/examples/outline.rb +252 -0
- data/examples/properties.rb +33 -0
- data/examples/protection.rb +34 -0
- data/examples/rich_strings.rb +42 -0
- data/examples/right_to_left.rb +24 -0
- data/examples/tab_colors.rb +26 -0
- data/lib/write_xlsx.rb +77 -0
- data/lib/write_xlsx/chart.rb +3027 -0
- data/lib/write_xlsx/chart/area.rb +52 -0
- data/lib/write_xlsx/chart/bar.rb +126 -0
- data/lib/write_xlsx/chart/column.rb +132 -0
- data/lib/write_xlsx/chart/line.rb +51 -0
- data/lib/write_xlsx/chart/pie.rb +210 -0
- data/lib/write_xlsx/chart/scatter.rb +252 -0
- data/lib/write_xlsx/chart/stock.rb +134 -0
- data/lib/write_xlsx/chartsheet.rb +173 -0
- data/lib/write_xlsx/colors.rb +65 -0
- data/lib/write_xlsx/compatibility.rb +71 -0
- data/lib/write_xlsx/drawing.rb +547 -0
- data/lib/write_xlsx/format.rb +683 -0
- data/lib/write_xlsx/package/app.rb +218 -0
- data/lib/write_xlsx/package/comments.rb +221 -0
- data/lib/write_xlsx/package/content_types.rb +189 -0
- data/lib/write_xlsx/package/core.rb +196 -0
- data/lib/write_xlsx/package/packager.rb +510 -0
- data/lib/write_xlsx/package/relationships.rb +98 -0
- data/lib/write_xlsx/package/shared_strings.rb +96 -0
- data/lib/write_xlsx/package/styles.rb +705 -0
- data/lib/write_xlsx/package/theme.rb +45 -0
- data/lib/write_xlsx/package/vml.rb +386 -0
- data/lib/write_xlsx/package/xml_writer_simple.rb +90 -0
- data/lib/write_xlsx/utility.rb +113 -0
- data/lib/write_xlsx/workbook.rb +1488 -0
- data/lib/write_xlsx/worksheet.rb +6578 -0
- data/lib/write_xlsx/zip_file_utils.rb +98 -0
- data/test/chart/test_add_series.rb +113 -0
- data/test/chart/test_process_names.rb +27 -0
- data/test/chart/test_write_auto.rb +15 -0
- data/test/chart/test_write_ax_id.rb +15 -0
- data/test/chart/test_write_ax_pos.rb +15 -0
- data/test/chart/test_write_chart_space.rb +15 -0
- data/test/chart/test_write_cross_ax.rb +15 -0
- data/test/chart/test_write_crosses.rb +15 -0
- data/test/chart/test_write_format_code.rb +15 -0
- data/test/chart/test_write_idx.rb +15 -0
- data/test/chart/test_write_label_align.rb +15 -0
- data/test/chart/test_write_label_offset.rb +15 -0
- data/test/chart/test_write_lang.rb +15 -0
- data/test/chart/test_write_layout.rb +15 -0
- data/test/chart/test_write_legend.rb +16 -0
- data/test/chart/test_write_legend_pos.rb +15 -0
- data/test/chart/test_write_major_gridlines.rb +15 -0
- data/test/chart/test_write_marker.rb +17 -0
- data/test/chart/test_write_marker_size.rb +15 -0
- data/test/chart/test_write_marker_value.rb +16 -0
- data/test/chart/test_write_num_cache.rb +16 -0
- data/test/chart/test_write_num_fmt.rb +16 -0
- data/test/chart/test_write_number_format.rb +15 -0
- data/test/chart/test_write_order.rb +15 -0
- data/test/chart/test_write_orientation.rb +15 -0
- data/test/chart/test_write_page_margins.rb +15 -0
- data/test/chart/test_write_page_setup.rb +15 -0
- data/test/chart/test_write_plot_vis_only.rb +15 -0
- data/test/chart/test_write_pt.rb +16 -0
- data/test/chart/test_write_pt_count.rb +16 -0
- data/test/chart/test_write_series_formula.rb +16 -0
- data/test/chart/test_write_style.rb +41 -0
- data/test/chart/test_write_symbol.rb +16 -0
- data/test/chart/test_write_tick_lbl_pos.rb +16 -0
- data/test/chart/test_write_v.rb +16 -0
- data/test/drawing/test_drawing_chart_01.rb +50 -0
- data/test/drawing/test_drawing_image_01.rb +59 -0
- data/test/helper.rb +90 -0
- data/test/package/app/test_app01.rb +44 -0
- data/test/package/app/test_app02.rb +46 -0
- data/test/package/app/test_app03.rb +53 -0
- data/test/package/comments/test_comments01.rb +36 -0
- data/test/package/comments/test_write_text_t.rb +44 -0
- data/test/package/content_types/test_content_types.rb +35 -0
- data/test/package/content_types/test_write_default.rb +13 -0
- data/test/package/content_types/test_write_override.rb +13 -0
- data/test/package/core/test_core01.rb +28 -0
- data/test/package/core/test_core02.rb +42 -0
- data/test/package/relationships/test_relationships.rb +28 -0
- data/test/package/relationships/test_sheet_rels.rb +22 -0
- data/test/package/shared_strings/test_shared_strings01.rb +30 -0
- data/test/package/shared_strings/test_shared_strings02.rb +30 -0
- data/test/package/shared_strings/test_write_si.rb +13 -0
- data/test/package/shared_strings/test_write_sst.rb +15 -0
- data/test/package/styles/test_styles_01.rb +69 -0
- data/test/package/styles/test_styles_02.rb +104 -0
- data/test/package/styles/test_styles_03.rb +90 -0
- data/test/package/styles/test_styles_04.rb +216 -0
- data/test/package/styles/test_styles_05.rb +150 -0
- data/test/package/styles/test_styles_06.rb +104 -0
- data/test/package/styles/test_styles_07.rb +104 -0
- data/test/package/styles/test_styles_08.rb +109 -0
- data/test/package/styles/test_styles_09.rb +95 -0
- data/test/package/vml/test_vml_01.rb +42 -0
- data/test/package/vml/test_write_anchor.rb +14 -0
- data/test/package/vml/test_write_auto_fill.rb +14 -0
- data/test/package/vml/test_write_column.rb +14 -0
- data/test/package/vml/test_write_div.rb +14 -0
- data/test/package/vml/test_write_fill.rb +14 -0
- data/test/package/vml/test_write_idmap.rb +14 -0
- data/test/package/vml/test_write_move_with_cells.rb +14 -0
- data/test/package/vml/test_write_path.rb +22 -0
- data/test/package/vml/test_write_row.rb +14 -0
- data/test/package/vml/test_write_shadow.rb +14 -0
- data/test/package/vml/test_write_shapelayout.rb +14 -0
- data/test/package/vml/test_write_shapetype.rb +14 -0
- data/test/package/vml/test_write_size_with_cells.rb +14 -0
- data/test/package/vml/test_write_stroke.rb +14 -0
- data/test/package/vml/test_write_textbox.rb +14 -0
- data/test/perl_output/a_simple.xlsx +0 -0
- data/test/perl_output/array_formula.xlsx +0 -0
- data/test/perl_output/autofilter.xlsx +0 -0
- data/test/perl_output/chart_area.xlsx +0 -0
- data/test/perl_output/chart_bar.xlsx +0 -0
- data/test/perl_output/chart_column.xlsx +0 -0
- data/test/perl_output/chart_line.xlsx +0 -0
- data/test/perl_output/chart_pie.xlsx +0 -0
- data/test/perl_output/chart_scatter.xlsx +0 -0
- data/test/perl_output/chart_stock.xlsx +0 -0
- data/test/perl_output/comments1.xlsx +0 -0
- data/test/perl_output/comments2.xlsx +0 -0
- data/test/perl_output/conditional_format.xlsx +0 -0
- data/test/perl_output/data_validate.xlsx +0 -0
- data/test/perl_output/defined_name.xlsx +0 -0
- data/test/perl_output/demo.xlsx +0 -0
- data/test/perl_output/diag_border.xlsx +0 -0
- data/test/perl_output/fit_to_pages.xlsx +0 -0
- data/test/perl_output/headers.xlsx +0 -0
- data/test/perl_output/hide_sheet.xlsx +0 -0
- data/test/perl_output/hyperlink.xlsx +0 -0
- data/test/perl_output/indent.xlsx +0 -0
- data/test/perl_output/merge1.xlsx +0 -0
- data/test/perl_output/merge2.xlsx +0 -0
- data/test/perl_output/merge3.xlsx +0 -0
- data/test/perl_output/merge4.xlsx +0 -0
- data/test/perl_output/merge5.xlsx +0 -0
- data/test/perl_output/merge6.xlsx +0 -0
- data/test/perl_output/outline.xlsx +0 -0
- data/test/perl_output/print_scale.xlsx +0 -0
- data/test/perl_output/properties.xlsx +0 -0
- data/test/perl_output/protection.xlsx +0 -0
- data/test/perl_output/rich_strings.xlsx +0 -0
- data/test/perl_output/right_to_left.xlsx +0 -0
- data/test/perl_output/tab_colors.xlsx +0 -0
- data/test/test_delete_files.rb +37 -0
- data/test/test_example_match.rb +2281 -0
- data/test/test_xml_writer_simple.rb +63 -0
- data/test/workbook/test_get_chart_range.rb +59 -0
- data/test/workbook/test_sort_defined_names.rb +77 -0
- data/test/workbook/test_workbook_01.rb +29 -0
- data/test/workbook/test_workbook_02.rb +31 -0
- data/test/workbook/test_workbook_03.rb +31 -0
- data/test/workbook/test_workbook_new.rb +18 -0
- data/test/workbook/test_write_defined_name.rb +17 -0
- data/test/workbook/test_write_defined_names.rb +41 -0
- data/test/worksheet/test_calculate_spans.rb +58 -0
- data/test/worksheet/test_convert_date_time_01.rb +439 -0
- data/test/worksheet/test_convert_date_time_02.rb +478 -0
- data/test/worksheet/test_convert_date_time_03.rb +435 -0
- data/test/worksheet/test_extract_filter_tokens.rb +109 -0
- data/test/worksheet/test_parse_filter_expression.rb +143 -0
- data/test/worksheet/test_position_object.rb +50 -0
- data/test/worksheet/test_repeat_formula.rb +55 -0
- data/test/worksheet/test_worksheet_01.rb +32 -0
- data/test/worksheet/test_worksheet_02.rb +38 -0
- data/test/worksheet/test_worksheet_03.rb +44 -0
- data/test/worksheet/test_worksheet_04.rb +45 -0
- data/test/worksheet/test_write_array_formula_01.rb +99 -0
- data/test/worksheet/test_write_autofilter.rb +260 -0
- data/test/worksheet/test_write_brk.rb +18 -0
- data/test/worksheet/test_write_cell.rb +49 -0
- data/test/worksheet/test_write_cell_value.rb +33 -0
- data/test/worksheet/test_write_col_breaks.rb +27 -0
- data/test/worksheet/test_write_col_info.rb +95 -0
- data/test/worksheet/test_write_conditional_formatting.rb +72 -0
- data/test/worksheet/test_write_custom_filter.rb +18 -0
- data/test/worksheet/test_write_custom_filters.rb +25 -0
- data/test/worksheet/test_write_data_validation_01.rb +113 -0
- data/test/worksheet/test_write_data_validation_02.rb +528 -0
- data/test/worksheet/test_write_dimension.rb +94 -0
- data/test/worksheet/test_write_ext.rb +18 -0
- data/test/worksheet/test_write_ext_lst.rb +18 -0
- data/test/worksheet/test_write_filter.rb +18 -0
- data/test/worksheet/test_write_filter_column.rb +18 -0
- data/test/worksheet/test_write_filters.rb +32 -0
- data/test/worksheet/test_write_header_footer.rb +53 -0
- data/test/worksheet/test_write_hyperlink.rb +39 -0
- data/test/worksheet/test_write_hyperlinks.rb +27 -0
- data/test/worksheet/test_write_legacy_drawing.rb +19 -0
- data/test/worksheet/test_write_merge_cell.rb +18 -0
- data/test/worksheet/test_write_merge_cells.rb +192 -0
- data/test/worksheet/test_write_methods.rb +353 -0
- data/test/worksheet/test_write_mx_plv.rb +19 -0
- data/test/worksheet/test_write_page_margins.rb +98 -0
- data/test/worksheet/test_write_page_set_up_pr.rb +19 -0
- data/test/worksheet/test_write_page_setup.rb +54 -0
- data/test/worksheet/test_write_pane.rb +123 -0
- data/test/worksheet/test_write_phonetic_pr.rb +19 -0
- data/test/worksheet/test_write_print_options.rb +77 -0
- data/test/worksheet/test_write_row_breaks.rb +27 -0
- data/test/worksheet/test_write_row_element.rb +69 -0
- data/test/worksheet/test_write_selection.rb +18 -0
- data/test/worksheet/test_write_sheet_calc_pr.rb +18 -0
- data/test/worksheet/test_write_sheet_data.rb +18 -0
- data/test/worksheet/test_write_sheet_format_pr.rb +18 -0
- data/test/worksheet/test_write_sheet_pr.rb +36 -0
- data/test/worksheet/test_write_sheet_protection.rb +174 -0
- data/test/worksheet/test_write_sheet_view.rb +62 -0
- data/test/worksheet/test_write_sheet_view1.rb +64 -0
- data/test/worksheet/test_write_sheet_view2.rb +56 -0
- data/test/worksheet/test_write_sheet_view3.rb +83 -0
- data/test/worksheet/test_write_sheet_view4.rb +83 -0
- data/test/worksheet/test_write_sheet_view5.rb +74 -0
- data/test/worksheet/test_write_sheet_view6.rb +51 -0
- data/test/worksheet/test_write_sheet_view7.rb +71 -0
- data/test/worksheet/test_write_sheet_view8.rb +51 -0
- data/test/worksheet/test_write_sheet_view9.rb +51 -0
- data/test/worksheet/test_write_tab_color.rb +23 -0
- data/test/worksheet/test_write_worksheet.rb +19 -0
- data/write_xlsx.gemspec +308 -0
- metadata +363 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Area - A class for writing Excel Area charts.
|
|
5
|
+
#
|
|
6
|
+
# Used in conjunction with Chart.
|
|
7
|
+
#
|
|
8
|
+
# See formatting note in Chart.
|
|
9
|
+
#
|
|
10
|
+
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
require 'write_xlsx/package/xml_writer_simple'
|
|
15
|
+
require 'write_xlsx/chart'
|
|
16
|
+
require 'write_xlsx/utility'
|
|
17
|
+
|
|
18
|
+
module Writexlsx
|
|
19
|
+
class Chart
|
|
20
|
+
class Area < self
|
|
21
|
+
include Writexlsx::Utility
|
|
22
|
+
|
|
23
|
+
def initialize
|
|
24
|
+
super(self.class)
|
|
25
|
+
@cross_between = 'midCat'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# Override the virtual superclass method with a chart specific method.
|
|
30
|
+
#
|
|
31
|
+
def write_chart_type
|
|
32
|
+
# Write the c:areaChart element.
|
|
33
|
+
write_area_chart
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Write the <c:areaChart> element.
|
|
38
|
+
#
|
|
39
|
+
def write_area_chart
|
|
40
|
+
@writer.start_tag('c:areaChart')
|
|
41
|
+
|
|
42
|
+
# Write the c:grouping element.
|
|
43
|
+
write_grouping('standard')
|
|
44
|
+
|
|
45
|
+
# Write the series elements.
|
|
46
|
+
write_series
|
|
47
|
+
|
|
48
|
+
@writer.end_tag('c:areaChart')
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Bar - A class for writing Excel Bar charts.
|
|
5
|
+
#
|
|
6
|
+
# Used in conjunction with Chart.
|
|
7
|
+
#
|
|
8
|
+
# See formatting note in Chart.
|
|
9
|
+
#
|
|
10
|
+
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
require 'write_xlsx/package/xml_writer_simple'
|
|
15
|
+
require 'write_xlsx/utility'
|
|
16
|
+
|
|
17
|
+
module Writexlsx
|
|
18
|
+
class Chart
|
|
19
|
+
class Bar < self
|
|
20
|
+
include Writexlsx::Utility
|
|
21
|
+
|
|
22
|
+
def initialize
|
|
23
|
+
super(self.class)
|
|
24
|
+
@subtype = 'clustered'
|
|
25
|
+
@cat_axis_position = 'l'
|
|
26
|
+
@val_axis_position = 'b'
|
|
27
|
+
@horiz_val_axis = 0
|
|
28
|
+
@horiz_cat_axis = 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Override the virtual superclass method with a chart specific method.
|
|
33
|
+
#
|
|
34
|
+
def write_chart_type
|
|
35
|
+
# Reverse X and Y axes for Bar charts.
|
|
36
|
+
@x_axis, @y_axis = @y_axis, @x_axis
|
|
37
|
+
|
|
38
|
+
# Write the c:barChart element.
|
|
39
|
+
write_bar_chart
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Write the <c:barChart> element.
|
|
44
|
+
#
|
|
45
|
+
def write_bar_chart
|
|
46
|
+
subtype = @subtype
|
|
47
|
+
|
|
48
|
+
subtype = 'percentStacked' if subtype == 'percent_stacked'
|
|
49
|
+
|
|
50
|
+
@writer.start_tag('c:barChart')
|
|
51
|
+
|
|
52
|
+
# Write the c:barDir element.
|
|
53
|
+
write_bar_dir
|
|
54
|
+
|
|
55
|
+
# Write the c:grouping element.
|
|
56
|
+
write_grouping(subtype)
|
|
57
|
+
|
|
58
|
+
# Write the series elements.
|
|
59
|
+
write_series
|
|
60
|
+
|
|
61
|
+
@writer.end_tag('c:barChart')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
#
|
|
66
|
+
# Write the <c:barDir> element.
|
|
67
|
+
#
|
|
68
|
+
def write_bar_dir
|
|
69
|
+
val = 'bar'
|
|
70
|
+
|
|
71
|
+
attributes = ['val', val]
|
|
72
|
+
|
|
73
|
+
@writer.empty_tag('c:barDir', attributes)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Over-ridden to add c:overlap.
|
|
78
|
+
#
|
|
79
|
+
# Write the series elements.
|
|
80
|
+
#
|
|
81
|
+
def write_series
|
|
82
|
+
# Write each series with subelements.
|
|
83
|
+
index = 0
|
|
84
|
+
@series.each do |series|
|
|
85
|
+
write_ser(index, series)
|
|
86
|
+
index += 1
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# Write the c:marker element.
|
|
91
|
+
write_marker_value
|
|
92
|
+
|
|
93
|
+
# Write the c:overlap element.
|
|
94
|
+
write_overlap if @subtype =~ /stacked/
|
|
95
|
+
|
|
96
|
+
# Generate the axis ids.
|
|
97
|
+
add_axis_id
|
|
98
|
+
add_axis_id
|
|
99
|
+
|
|
100
|
+
# Write the c:axId element.
|
|
101
|
+
write_axis_id(@axis_ids[0])
|
|
102
|
+
write_axis_id(@axis_ids[1])
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
#
|
|
107
|
+
# Over-ridden to add % format. TODO. This will be refactored back up to the
|
|
108
|
+
# SUPER class later.
|
|
109
|
+
#
|
|
110
|
+
# Write the <c:numFmt> element.
|
|
111
|
+
#
|
|
112
|
+
def write_number_format(format_code = 'General')
|
|
113
|
+
source_linked = 1
|
|
114
|
+
|
|
115
|
+
format_code = '0%' if @subtype == 'percent_stacked'
|
|
116
|
+
|
|
117
|
+
attributes = [
|
|
118
|
+
'formatCode', format_code,
|
|
119
|
+
'sourceLinked', source_linked
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
@writer.empty_tag('c:numFmt', attributes)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Column - A class for writing Excel Column charts.
|
|
5
|
+
#
|
|
6
|
+
# Used in conjunction with Chart.
|
|
7
|
+
#
|
|
8
|
+
# See formatting note in Chart.
|
|
9
|
+
#
|
|
10
|
+
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
require 'write_xlsx/package/xml_writer_simple'
|
|
15
|
+
require 'write_xlsx/utility'
|
|
16
|
+
|
|
17
|
+
module Writexlsx
|
|
18
|
+
class Chart
|
|
19
|
+
# The Column chart module also supports the following sub-types:
|
|
20
|
+
#
|
|
21
|
+
# stacked
|
|
22
|
+
# percent_stacked
|
|
23
|
+
# These can be specified at creation time via the add_chart() Worksheet
|
|
24
|
+
# method:
|
|
25
|
+
#
|
|
26
|
+
# chart = workbook.add_chart( :type => 'column', :subtype => 'stacked' )
|
|
27
|
+
#
|
|
28
|
+
class Column < self
|
|
29
|
+
include Writexlsx::Utility
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
super(self.class)
|
|
33
|
+
@subtype = 'clustered'
|
|
34
|
+
@horiz_val_axis = 0
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# Override the virtual superclass method with a chart specific method.
|
|
39
|
+
#
|
|
40
|
+
def write_chart_type
|
|
41
|
+
# Write the c:barChart element.
|
|
42
|
+
write_bar_chart
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
##############################################################################
|
|
47
|
+
#
|
|
48
|
+
# _write_bar_chart
|
|
49
|
+
#
|
|
50
|
+
# Write the <c:barChart> element.
|
|
51
|
+
#
|
|
52
|
+
def write_bar_chart
|
|
53
|
+
subtype = @subtype
|
|
54
|
+
|
|
55
|
+
subtype = 'percentStacked' if subtype == 'percent_stacked'
|
|
56
|
+
|
|
57
|
+
@writer.start_tag('c:barChart')
|
|
58
|
+
|
|
59
|
+
# Write the c:barDir element.
|
|
60
|
+
write_bar_dir
|
|
61
|
+
|
|
62
|
+
# Write the c:grouping element.
|
|
63
|
+
write_grouping(subtype)
|
|
64
|
+
|
|
65
|
+
# Write the series elements.
|
|
66
|
+
write_series
|
|
67
|
+
|
|
68
|
+
@writer.end_tag('c:barChart')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#
|
|
72
|
+
# Write the <c:barDir> element.
|
|
73
|
+
#
|
|
74
|
+
def write_bar_dir
|
|
75
|
+
val = 'col'
|
|
76
|
+
|
|
77
|
+
attributes = ['val', val]
|
|
78
|
+
|
|
79
|
+
@writer.empty_tag('c:barDir', attributes)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
#
|
|
84
|
+
# Over-ridden to add c:overlap.
|
|
85
|
+
#
|
|
86
|
+
# Write the series elements.
|
|
87
|
+
#
|
|
88
|
+
def write_series
|
|
89
|
+
# Write each series with subelements.
|
|
90
|
+
index = 0
|
|
91
|
+
@series.each do |series|
|
|
92
|
+
write_ser(index, series)
|
|
93
|
+
index += 1
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Write the c:marker element.
|
|
97
|
+
write_marker_value
|
|
98
|
+
|
|
99
|
+
# Write the c:overlap element.
|
|
100
|
+
write_overlap if @subtype =~ /stacked/
|
|
101
|
+
|
|
102
|
+
# Generate the axis ids.
|
|
103
|
+
add_axis_id
|
|
104
|
+
add_axis_id
|
|
105
|
+
|
|
106
|
+
# Write the c:axId element.
|
|
107
|
+
write_axis_id(@axis_ids[0])
|
|
108
|
+
write_axis_id(@axis_ids[1])
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
#
|
|
112
|
+
# Over-ridden to add % format. TODO. This will be refactored back up to the
|
|
113
|
+
# SUPER class later.
|
|
114
|
+
#
|
|
115
|
+
# Write the <c:numFmt> element.
|
|
116
|
+
#
|
|
117
|
+
def write_number_format(format_code = nil)
|
|
118
|
+
format_code ||= 'General'
|
|
119
|
+
source_linked = 1
|
|
120
|
+
|
|
121
|
+
format_code = '0%' if @subtype == 'percent_stacked'
|
|
122
|
+
|
|
123
|
+
attributes = [
|
|
124
|
+
'formatCode', format_code,
|
|
125
|
+
'sourceLinked', source_linked
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
@writer.empty_tag('c:numFmt', attributes)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Line - A class for writing Excel Line charts.
|
|
5
|
+
#
|
|
6
|
+
# Used in conjunction with Chart.
|
|
7
|
+
#
|
|
8
|
+
# See formatting note in Chart.
|
|
9
|
+
#
|
|
10
|
+
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
require 'write_xlsx/package/xml_writer_simple'
|
|
15
|
+
require 'write_xlsx/utility'
|
|
16
|
+
|
|
17
|
+
module Writexlsx
|
|
18
|
+
class Chart
|
|
19
|
+
class Line < self
|
|
20
|
+
include Writexlsx::Utility
|
|
21
|
+
|
|
22
|
+
def initialize
|
|
23
|
+
super(self.class)
|
|
24
|
+
@default_marker = {:type => 'none'}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# Override the virtual superclass method with a chart specific method.
|
|
29
|
+
#
|
|
30
|
+
def write_chart_type
|
|
31
|
+
# Write the c:barChart element.
|
|
32
|
+
write_line_chart
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
#
|
|
36
|
+
# Write the <c:lineChart> element.
|
|
37
|
+
#
|
|
38
|
+
def write_line_chart
|
|
39
|
+
@writer.start_tag('c:lineChart')
|
|
40
|
+
|
|
41
|
+
# Write the c:grouping element.
|
|
42
|
+
write_grouping('standard')
|
|
43
|
+
|
|
44
|
+
# Write the series elements.
|
|
45
|
+
write_series
|
|
46
|
+
|
|
47
|
+
@writer.end_tag('c:lineChart')
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Pie - A class for writing Excel Pie charts.
|
|
5
|
+
#
|
|
6
|
+
# Used in conjunction with Chart.
|
|
7
|
+
#
|
|
8
|
+
# See formatting note in Chart.
|
|
9
|
+
#
|
|
10
|
+
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
require 'write_xlsx/package/xml_writer_simple'
|
|
15
|
+
require 'write_xlsx/chart'
|
|
16
|
+
require 'write_xlsx/utility'
|
|
17
|
+
|
|
18
|
+
module Writexlsx
|
|
19
|
+
class Chart
|
|
20
|
+
# A Pie chart doesn't have an X or Y axis so the following common chart
|
|
21
|
+
# methods are ignored.
|
|
22
|
+
#
|
|
23
|
+
# chart.set_x_axis
|
|
24
|
+
# chart.set_y_axis
|
|
25
|
+
#
|
|
26
|
+
class Pie < self
|
|
27
|
+
include Writexlsx::Utility
|
|
28
|
+
|
|
29
|
+
def initialize
|
|
30
|
+
super(self.class)
|
|
31
|
+
@vary_data_color = 1
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# Override the virtual superclass method with a chart specific method.
|
|
36
|
+
#
|
|
37
|
+
def write_chart_type
|
|
38
|
+
# Write the c:areaChart element.
|
|
39
|
+
write_pie_chart
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Write the <c:pieChart> element.
|
|
44
|
+
#
|
|
45
|
+
def write_pie_chart
|
|
46
|
+
@writer.start_tag('c:pieChart')
|
|
47
|
+
|
|
48
|
+
# Write the c:varyColors element.
|
|
49
|
+
write_vary_colors
|
|
50
|
+
|
|
51
|
+
# Write the series elements.
|
|
52
|
+
write_series
|
|
53
|
+
|
|
54
|
+
# Write the c:firstSliceAng element.
|
|
55
|
+
write_first_slice_ang
|
|
56
|
+
|
|
57
|
+
@writer.end_tag('c:pieChart')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
# Over-ridden method to remove the cat_axis() and val_axis() code since
|
|
62
|
+
# Pie charts don't require those axes.
|
|
63
|
+
#
|
|
64
|
+
# Write the <c:plotArea> element.
|
|
65
|
+
#
|
|
66
|
+
def write_plot_area
|
|
67
|
+
@writer.start_tag('c:plotArea')
|
|
68
|
+
|
|
69
|
+
# Write the c:layout element.
|
|
70
|
+
write_layout
|
|
71
|
+
|
|
72
|
+
# Write the subclass chart type element.
|
|
73
|
+
write_chart_type
|
|
74
|
+
|
|
75
|
+
@writer.end_tag('c:plotArea')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
#
|
|
79
|
+
# Over-ridden method to remove axis_id code since Pie charts don't require
|
|
80
|
+
# val and cat axes.
|
|
81
|
+
#
|
|
82
|
+
# Write the series elements.
|
|
83
|
+
#
|
|
84
|
+
def write_series
|
|
85
|
+
# Write each series with subelements.
|
|
86
|
+
index = 0
|
|
87
|
+
@series.each do |series|
|
|
88
|
+
write_ser(index, series)
|
|
89
|
+
index += 1
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# Over-ridden method to add <c:txPr> to legend.
|
|
95
|
+
#
|
|
96
|
+
# Write the <c:legend> element.
|
|
97
|
+
#
|
|
98
|
+
def write_legend
|
|
99
|
+
position = @legend_position
|
|
100
|
+
overlay = 0
|
|
101
|
+
|
|
102
|
+
if position =~ /^overlay_/
|
|
103
|
+
positon.sub!(/^overlay_/, '')
|
|
104
|
+
overlay = 1
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
allowed = {
|
|
108
|
+
'right' => 'r',
|
|
109
|
+
'left' => 'l',
|
|
110
|
+
'top' => 't',
|
|
111
|
+
'bottom' => 'b'
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return if position == 'none'
|
|
115
|
+
return unless allowed.has_key?(position)
|
|
116
|
+
|
|
117
|
+
position = allowed[position]
|
|
118
|
+
|
|
119
|
+
@writer.start_tag('c:legend')
|
|
120
|
+
|
|
121
|
+
# Write the c:legendPos element.
|
|
122
|
+
write_legend_pos(position)
|
|
123
|
+
|
|
124
|
+
# Write the c:layout element.
|
|
125
|
+
write_layout
|
|
126
|
+
|
|
127
|
+
# Write the c:overlay element.
|
|
128
|
+
write_overlay if overlay != 0
|
|
129
|
+
|
|
130
|
+
# Write the c:txPr element. Over-ridden.
|
|
131
|
+
write_tx_pr_legend
|
|
132
|
+
|
|
133
|
+
@writer.end_tag('c:legend')
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
#
|
|
137
|
+
# Write the <c:txPr> element for legends.
|
|
138
|
+
#
|
|
139
|
+
def write_tx_pr_legend
|
|
140
|
+
horiz = 0
|
|
141
|
+
|
|
142
|
+
@writer.start_tag('c:txPr')
|
|
143
|
+
|
|
144
|
+
# Write the a:bodyPr element.
|
|
145
|
+
write_a_body_pr(horiz)
|
|
146
|
+
|
|
147
|
+
# Write the a:lstStyle element.
|
|
148
|
+
write_a_lst_style
|
|
149
|
+
|
|
150
|
+
# Write the a:p element.
|
|
151
|
+
write_a_p_legend
|
|
152
|
+
|
|
153
|
+
@writer.end_tag('c:txPr')
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
#
|
|
157
|
+
# Write the <a:p> element for legends.
|
|
158
|
+
#
|
|
159
|
+
def write_a_p_legend
|
|
160
|
+
@writer.start_tag('a:p')
|
|
161
|
+
|
|
162
|
+
# Write the a:pPr element.
|
|
163
|
+
write_a_p_pr_legend
|
|
164
|
+
|
|
165
|
+
# Write the a:endParaRPr element.
|
|
166
|
+
write_a_end_para_rpr
|
|
167
|
+
|
|
168
|
+
@writer.end_tag('a:p')
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
#
|
|
172
|
+
# Write the <a:pPr> element for legends.
|
|
173
|
+
#
|
|
174
|
+
def write_a_p_pr_legend
|
|
175
|
+
rtl = 0
|
|
176
|
+
|
|
177
|
+
attributes = ['rtl', rtl]
|
|
178
|
+
|
|
179
|
+
@writer.start_tag('a:pPr', attributes)
|
|
180
|
+
|
|
181
|
+
# Write the a:defRPr element.
|
|
182
|
+
write_a_def_rpr
|
|
183
|
+
|
|
184
|
+
@writer.end_tag('a:pPr')
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
#
|
|
188
|
+
# Write the <c:varyColors> element.
|
|
189
|
+
#
|
|
190
|
+
def write_vary_colors
|
|
191
|
+
val = 1
|
|
192
|
+
|
|
193
|
+
attributes = ['val', val]
|
|
194
|
+
|
|
195
|
+
@writer.empty_tag('c:varyColors', attributes)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
#
|
|
199
|
+
# Write the <c:firstSliceAng> element.
|
|
200
|
+
#
|
|
201
|
+
def write_first_slice_ang
|
|
202
|
+
val = 0
|
|
203
|
+
|
|
204
|
+
attributes = ['val', val]
|
|
205
|
+
|
|
206
|
+
@writer.empty_tag('c:firstSliceAng', attributes)
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|