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,252 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Scatter - A class for writing Excel Scatter 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
|
+
# The Scatter chart module also supports the following sub-types:
|
|
21
|
+
#
|
|
22
|
+
# markers_only (the default)
|
|
23
|
+
# straight_with_markers
|
|
24
|
+
# straight
|
|
25
|
+
# smooth_with_markers
|
|
26
|
+
# smooth
|
|
27
|
+
# These can be specified at creation time via the add_chart() Worksheet
|
|
28
|
+
# method:
|
|
29
|
+
#
|
|
30
|
+
# chart = workbook.add_chart(
|
|
31
|
+
# :type => 'scatter',
|
|
32
|
+
# :subtype => 'straight_with_markers'
|
|
33
|
+
# )
|
|
34
|
+
#
|
|
35
|
+
class Scatter < self
|
|
36
|
+
include Writexlsx::Utility
|
|
37
|
+
|
|
38
|
+
def initialize
|
|
39
|
+
super(self.class)
|
|
40
|
+
@subtype = 'marker_only'
|
|
41
|
+
@cross_between = 'midCat'
|
|
42
|
+
@horiz_val_axis = 0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# Override the virtual superclass method with a chart specific method.
|
|
47
|
+
#
|
|
48
|
+
def write_chart_type
|
|
49
|
+
# Write the c:areaChart element.
|
|
50
|
+
write_scatter_chart
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# Write the <c:pieChart> element.
|
|
55
|
+
#
|
|
56
|
+
def write_scatter_chart
|
|
57
|
+
style = 'lineMarker'
|
|
58
|
+
subtype = @subtype
|
|
59
|
+
|
|
60
|
+
# Set the user defined chart subtype
|
|
61
|
+
case subtype
|
|
62
|
+
when 'marker_only', 'straight_with_markers', 'straight'
|
|
63
|
+
style = 'lineMarker'
|
|
64
|
+
when 'smooth_with_markers', 'smooth'
|
|
65
|
+
style = 'smoothMarker'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Add default formatting to the series data.
|
|
69
|
+
modify_series_formatting
|
|
70
|
+
|
|
71
|
+
@writer.start_tag('c:scatterChart')
|
|
72
|
+
|
|
73
|
+
# Write the c:scatterStyle element.
|
|
74
|
+
write_scatter_style(style)
|
|
75
|
+
|
|
76
|
+
# Write the series elements.
|
|
77
|
+
write_series
|
|
78
|
+
|
|
79
|
+
@writer.end_tag('c:scatterChart')
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# Over-ridden to write c:xVal/c:yVal instead of c:cat/c:val elements.
|
|
84
|
+
#
|
|
85
|
+
# Write the <c:ser> element.
|
|
86
|
+
#
|
|
87
|
+
def write_ser(index, series)
|
|
88
|
+
@writer.start_tag('c:ser')
|
|
89
|
+
|
|
90
|
+
# Write the c:idx element.
|
|
91
|
+
write_idx(index)
|
|
92
|
+
|
|
93
|
+
# Write the c:order element.
|
|
94
|
+
write_order(index)
|
|
95
|
+
|
|
96
|
+
# Write the series name.
|
|
97
|
+
write_series_name(series)
|
|
98
|
+
|
|
99
|
+
# Write the c:spPr element.
|
|
100
|
+
write_sp_pr(series)
|
|
101
|
+
|
|
102
|
+
# Write the c:marker element.
|
|
103
|
+
write_marker(series[:_marker])
|
|
104
|
+
|
|
105
|
+
# Write the c:dLbls element.
|
|
106
|
+
write_d_lbls(series[:_labels])
|
|
107
|
+
|
|
108
|
+
# Write the c:trendline element.
|
|
109
|
+
write_trendline(series[:_trendline])
|
|
110
|
+
|
|
111
|
+
# Write the c:xVal element.
|
|
112
|
+
write_x_val(series)
|
|
113
|
+
|
|
114
|
+
# Write the c:yVal element.
|
|
115
|
+
write_y_val(series)
|
|
116
|
+
|
|
117
|
+
# Write the c:smooth element.
|
|
118
|
+
write_c_smooth
|
|
119
|
+
|
|
120
|
+
@writer.end_tag('c:ser')
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#
|
|
124
|
+
# Over-ridden to have 2 valAx elements for scatter charts instead of
|
|
125
|
+
# catAx/valAx.
|
|
126
|
+
#
|
|
127
|
+
# Write the <c:plotArea> element.
|
|
128
|
+
#
|
|
129
|
+
def write_plot_area
|
|
130
|
+
@writer.start_tag('c:plotArea')
|
|
131
|
+
|
|
132
|
+
# Write the c:layout element.
|
|
133
|
+
write_layout
|
|
134
|
+
|
|
135
|
+
# Write the subclass chart type element.
|
|
136
|
+
write_chart_type
|
|
137
|
+
|
|
138
|
+
# Write the c:catAx element.
|
|
139
|
+
write_cat_val_axis('b', 1)
|
|
140
|
+
|
|
141
|
+
# Write the c:catAx element.
|
|
142
|
+
@horiz_val_axis = 1
|
|
143
|
+
write_val_axis('l')
|
|
144
|
+
|
|
145
|
+
@writer.end_tag('c:plotArea')
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
#
|
|
149
|
+
# Write the <c:xVal> element.
|
|
150
|
+
#
|
|
151
|
+
def write_x_val(series)
|
|
152
|
+
formula = series[:_categories]
|
|
153
|
+
data_id = series[:_cat_data_id]
|
|
154
|
+
data = @formula_data[data_id]
|
|
155
|
+
|
|
156
|
+
@writer.start_tag('c:xVal')
|
|
157
|
+
|
|
158
|
+
# Check the type of cached data.
|
|
159
|
+
type = get_data_type(data)
|
|
160
|
+
|
|
161
|
+
# TODO. Can a scatter plot have non-numeric data.
|
|
162
|
+
|
|
163
|
+
if type == 'str'
|
|
164
|
+
# Write the c:numRef element.
|
|
165
|
+
write_str_ref(formula, data, type)
|
|
166
|
+
else
|
|
167
|
+
# Write the c:numRef element.
|
|
168
|
+
write_num_ref(formula, data, type)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
@writer.end_tag('c:xVal')
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
#
|
|
175
|
+
# Write the <c:yVal> element.
|
|
176
|
+
#
|
|
177
|
+
def write_y_val(series)
|
|
178
|
+
formula = series[:_values]
|
|
179
|
+
data_id = series[:_val_data_id]
|
|
180
|
+
data = @formula_data[data_id]
|
|
181
|
+
|
|
182
|
+
@writer.start_tag('c:yVal')
|
|
183
|
+
|
|
184
|
+
# Check the type of cached data.
|
|
185
|
+
type = get_data_type(data)
|
|
186
|
+
|
|
187
|
+
if type == 'str'
|
|
188
|
+
# Write the c:numRef element.
|
|
189
|
+
write_str_ref(formula, data, type)
|
|
190
|
+
else
|
|
191
|
+
# Write the c:numRef element.
|
|
192
|
+
write_num_ref(formula, data, type)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
@writer.end_tag('c:yVal')
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
#
|
|
199
|
+
# Write the <c:scatterStyle> element.
|
|
200
|
+
#
|
|
201
|
+
def write_scatter_style(val)
|
|
202
|
+
attributes = ['val', val]
|
|
203
|
+
|
|
204
|
+
@writer.empty_tag('c:scatterStyle', attributes)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
#
|
|
208
|
+
# Write the <c:smooth> element.
|
|
209
|
+
#
|
|
210
|
+
def write_c_smooth
|
|
211
|
+
subtype = @subtype
|
|
212
|
+
val = 1
|
|
213
|
+
|
|
214
|
+
return unless subtype =~ /smooth/
|
|
215
|
+
|
|
216
|
+
attributes = ['val', val]
|
|
217
|
+
|
|
218
|
+
@writer.empty_tag('c:smooth', attributes)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
#
|
|
222
|
+
# Add default formatting to the series data unless it has already been
|
|
223
|
+
# specified by the user.
|
|
224
|
+
#
|
|
225
|
+
def modify_series_formatting
|
|
226
|
+
subtype = @subtype
|
|
227
|
+
|
|
228
|
+
# The default scatter style "markers only" requires a line type
|
|
229
|
+
if subtype == 'marker_only'
|
|
230
|
+
# Go through each series and define default values.
|
|
231
|
+
@series.each do |series|
|
|
232
|
+
# Set a line type unless there is already a user defined type.
|
|
233
|
+
if series[:_line][:_defined] == 0
|
|
234
|
+
series[:_line] = { :width => 2.25, :none => 1, :_defined => 1 }
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Turn markers off for subtypes that don't have them
|
|
240
|
+
unless subtype =~ /marker/
|
|
241
|
+
# Go through each series and define default values.
|
|
242
|
+
@series.each do |series|
|
|
243
|
+
# Set a marker type unless there is already a user defined type.
|
|
244
|
+
if series[:_marker][:_defined] == 0
|
|
245
|
+
series[:_marker] = { :type => 'none', :_defined => 1 }
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Stock - A class for writing Excel Stock 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
|
+
#
|
|
21
|
+
# The default Stock chart is an High-Low-Close chart.
|
|
22
|
+
# A series must be added for each of these data sources.
|
|
23
|
+
#
|
|
24
|
+
class Stock < self
|
|
25
|
+
include Writexlsx::Utility
|
|
26
|
+
|
|
27
|
+
def initialize
|
|
28
|
+
super(self.class)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Override the virtual superclass method with a chart specific method.
|
|
33
|
+
#
|
|
34
|
+
def write_chart_type
|
|
35
|
+
# Write the c:areaChart element.
|
|
36
|
+
write_stock_chart
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
# Write the <c:stockChart> element.
|
|
41
|
+
#
|
|
42
|
+
def write_stock_chart
|
|
43
|
+
# Add default formatting to the series data.
|
|
44
|
+
modify_series_formatting
|
|
45
|
+
|
|
46
|
+
@writer.start_tag('c:stockChart')
|
|
47
|
+
|
|
48
|
+
# Write the series elements.
|
|
49
|
+
write_series
|
|
50
|
+
|
|
51
|
+
@writer.end_tag('c:stockChart')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#
|
|
55
|
+
# Over-ridden to add hi_low_lines(). TODO. Refactor up into the SUPER class.
|
|
56
|
+
#
|
|
57
|
+
# Write the series elements.
|
|
58
|
+
#
|
|
59
|
+
def write_series
|
|
60
|
+
# Write each series with subelements.
|
|
61
|
+
index = 0
|
|
62
|
+
@series.each do |series|
|
|
63
|
+
write_ser(index, series)
|
|
64
|
+
index += 1
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Write the c:hiLowLines element.
|
|
68
|
+
write_hi_low_lines
|
|
69
|
+
|
|
70
|
+
# Write the c:marker element.
|
|
71
|
+
write_marker_value
|
|
72
|
+
|
|
73
|
+
# Generate the axis ids.
|
|
74
|
+
add_axis_id
|
|
75
|
+
add_axis_id
|
|
76
|
+
|
|
77
|
+
# Write the c:axId element.
|
|
78
|
+
write_axis_id(@axis_ids[0])
|
|
79
|
+
write_axis_id(@axis_ids[1])
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# Write the <c:plotArea> element.
|
|
84
|
+
#
|
|
85
|
+
def write_plot_area
|
|
86
|
+
@writer.start_tag('c:plotArea')
|
|
87
|
+
|
|
88
|
+
# Write the c:layout element.
|
|
89
|
+
write_layout
|
|
90
|
+
|
|
91
|
+
# Write the subclass chart type element.
|
|
92
|
+
write_chart_type
|
|
93
|
+
|
|
94
|
+
# Write the c:dateAx element.
|
|
95
|
+
write_date_axis
|
|
96
|
+
|
|
97
|
+
# Write the c:catAx element.
|
|
98
|
+
write_val_axis
|
|
99
|
+
|
|
100
|
+
@writer.end_tag('c:plotArea')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#
|
|
104
|
+
# Add default formatting to the series data.
|
|
105
|
+
#
|
|
106
|
+
def modify_series_formatting
|
|
107
|
+
index = 0
|
|
108
|
+
array = []
|
|
109
|
+
@series.each do |series|
|
|
110
|
+
if index % 4 != 3
|
|
111
|
+
if series[:_line][:_defined].nil? || series[:_line][:_defined] == 0
|
|
112
|
+
series[:_line] = {
|
|
113
|
+
:width => 2.25,
|
|
114
|
+
:none => 1,
|
|
115
|
+
:_defined => 1
|
|
116
|
+
}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
if series[:_marker].nil? || series[:_marker] == 0
|
|
120
|
+
if index % 4 == 2
|
|
121
|
+
series[:_marker] = { :type => 'dot', :size => 3 }
|
|
122
|
+
else
|
|
123
|
+
series[:_marker] = { :type => 'none' }
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
index += 1
|
|
128
|
+
array << series
|
|
129
|
+
end
|
|
130
|
+
@series = array
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# Chartsheet - A class for writing the Excel XLSX Chartsheet files.
|
|
5
|
+
#
|
|
6
|
+
# Used in conjunction with WriteXLSX
|
|
7
|
+
#
|
|
8
|
+
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
|
9
|
+
# Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
require 'write_xlsx/worksheet'
|
|
13
|
+
|
|
14
|
+
module Writexlsx
|
|
15
|
+
class Chartsheet < Worksheet
|
|
16
|
+
include Writexlsx::Utility
|
|
17
|
+
|
|
18
|
+
def initialize(workbook, index, name)
|
|
19
|
+
super
|
|
20
|
+
@drawing = 1
|
|
21
|
+
@is_chartsheet = true
|
|
22
|
+
@chart = nil
|
|
23
|
+
@charts = [1]
|
|
24
|
+
@zoom_scale_normal = 0
|
|
25
|
+
@oriantation = 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# Assemble and write the XML file.
|
|
30
|
+
#
|
|
31
|
+
def assemble_xml_file # :nodoc:
|
|
32
|
+
return unless @writer
|
|
33
|
+
write_xml_declaration
|
|
34
|
+
|
|
35
|
+
# Write the root chartsheet element.
|
|
36
|
+
write_chartsheet
|
|
37
|
+
|
|
38
|
+
# Write the worksheet properties.
|
|
39
|
+
write_sheet_pr
|
|
40
|
+
|
|
41
|
+
# Write the sheet view properties.
|
|
42
|
+
write_sheet_views
|
|
43
|
+
|
|
44
|
+
# Write the sheetProtection element.
|
|
45
|
+
write_sheet_protection
|
|
46
|
+
|
|
47
|
+
# Write the printOptions element.
|
|
48
|
+
write_print_options
|
|
49
|
+
|
|
50
|
+
# Write the worksheet page_margins.
|
|
51
|
+
write_page_margins
|
|
52
|
+
|
|
53
|
+
# Write the worksheet page setup.
|
|
54
|
+
write_page_setup
|
|
55
|
+
|
|
56
|
+
# Write the headerFooter element.
|
|
57
|
+
write_header_footer
|
|
58
|
+
|
|
59
|
+
# Write the drawing element.
|
|
60
|
+
write_drawings
|
|
61
|
+
|
|
62
|
+
# Close the worksheet tag.
|
|
63
|
+
@writer.end_tag('chartsheet')
|
|
64
|
+
|
|
65
|
+
# Close the XML writer object and filehandle.
|
|
66
|
+
@writer.crlf
|
|
67
|
+
@writer.getOutput->close
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def protect(password = '', options = {})
|
|
71
|
+
@chart.protection = 1
|
|
72
|
+
|
|
73
|
+
options[:sheet] = 0
|
|
74
|
+
options[:content] = 1
|
|
75
|
+
options[:scenarios] = 1
|
|
76
|
+
|
|
77
|
+
super(password, options)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
###############################################################################
|
|
82
|
+
#
|
|
83
|
+
# Encapsulated Chart methods.
|
|
84
|
+
#
|
|
85
|
+
###############################################################################
|
|
86
|
+
|
|
87
|
+
def add_series(*args)
|
|
88
|
+
@chart.add_series(*args)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def set_x_axis(*args)
|
|
92
|
+
@chart.set_x_axis(*args)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def set_y_axis(*args)
|
|
96
|
+
@chart.set_y_axis(*args)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def set_title(*args)
|
|
100
|
+
@chart.set_title(*args)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def set_legend(*args)
|
|
104
|
+
@chart.set_legend(*args)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def set_plotarea(*args)
|
|
108
|
+
@chart.set_plotarea(*args)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def set_chartarea(*args)
|
|
112
|
+
@chart.set_chartarea(*args)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def set_style(*args)
|
|
116
|
+
@chart.set_style(*args)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
#
|
|
122
|
+
# Set up chart/drawings.
|
|
123
|
+
#
|
|
124
|
+
def prepare_chart(index, chart_id, drawing_id) # :nodoc:
|
|
125
|
+
drawing = Drawing.new
|
|
126
|
+
@drawing = $drawing
|
|
127
|
+
@drawing.orientation = @orientation
|
|
128
|
+
|
|
129
|
+
@external_drawing_links << [ '/drawing', '../drawings/drawing' << drawing_id << '.xml' ]
|
|
130
|
+
|
|
131
|
+
@drawing_links << [ '/chart', '../charts/chart' << chart_id << '.xml' ]
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
#
|
|
135
|
+
# Write the <chartsheet> element. This is the root element of Chartsheet.
|
|
136
|
+
#
|
|
137
|
+
def write_chartsheet # :nodoc:
|
|
138
|
+
schema = 'http://schemas.openxmlformats.org/'
|
|
139
|
+
xmlns = schema + 'spreadsheetml/2006/main'
|
|
140
|
+
xmlns_r = schema + 'officeDocument/2006/relationships'
|
|
141
|
+
xmlns_mc = schema + 'markup-compatibility/2006'
|
|
142
|
+
xmlns_mv = 'urn:schemas-microsoft-com:mac:vml'
|
|
143
|
+
mc_ignorable = 'mv'
|
|
144
|
+
mc_preserve_attributes = 'mv:*'
|
|
145
|
+
|
|
146
|
+
attributes = [
|
|
147
|
+
'xmlns', xmlns,
|
|
148
|
+
'xmlns:r', xmlns_r
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
@writer.start_tag('chartsheet', attributes)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
#
|
|
155
|
+
# Write the <sheetPr> element for Sheet level properties.
|
|
156
|
+
#
|
|
157
|
+
def _write_sheet_pr # :nodoc:
|
|
158
|
+
|
|
159
|
+
attributes = []
|
|
160
|
+
|
|
161
|
+
attributes << {'filterMode' => 1} if @filter_on
|
|
162
|
+
|
|
163
|
+
if @fit_page || @tab_color
|
|
164
|
+
@writer.start_tag('sheetPr', attributes)
|
|
165
|
+
write_tab_color
|
|
166
|
+
write_page_set_up_pr
|
|
167
|
+
@writer.end_tag('sheetPr')
|
|
168
|
+
else
|
|
169
|
+
@writer.empty_tag('sheetPr', attributes)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|