write_xlsx 1.00.0 → 1.01.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changes +15 -0
- data/examples/a_simple.rb +1 -1
- data/examples/add_vba_project.rb +1 -1
- data/examples/array_formula.rb +1 -1
- data/examples/chart_area.rb +5 -2
- data/examples/chart_bar.rb +5 -2
- data/examples/chart_clustered.rb +1 -1
- data/examples/chart_column.rb +5 -2
- data/examples/chart_combined.rb +1 -1
- data/examples/chart_data_table.rb +9 -3
- data/examples/chart_data_tools.rb +25 -7
- data/examples/chart_doughnut.rb +17 -5
- data/examples/chart_gauge.rb +73 -0
- data/examples/chart_line.rb +5 -2
- data/examples/chart_pareto.rb +1 -1
- data/examples/chart_pie.rb +9 -3
- data/examples/chart_radar.rb +13 -4
- data/examples/chart_scatter.rb +5 -2
- data/examples/chart_secondary_axis.rb +5 -2
- data/examples/chart_stock.rb +1 -1
- data/examples/chart_styles.rb +1 -1
- data/examples/colors.rb +1 -1
- data/examples/data_validate.rb +1 -1
- data/examples/date_time.rb +1 -1
- data/examples/demo.rb +4 -1
- data/examples/formats.rb +1 -1
- data/examples/headers.rb +1 -1
- data/examples/hide_row_col.rb +1 -1
- data/examples/hide_sheet.rb +1 -1
- data/examples/hyperlink1.rb +1 -1
- data/examples/indent.rb +1 -1
- data/examples/macros.rb +1 -1
- data/examples/merge1.rb +1 -1
- data/examples/merge2.rb +1 -1
- data/examples/merge3.rb +1 -1
- data/examples/merge4.rb +1 -1
- data/examples/merge5.rb +1 -1
- data/examples/merge6.rb +1 -1
- data/examples/outline.rb +1 -1
- data/examples/outline_collapsed.rb +1 -1
- data/examples/panes.rb +1 -1
- data/examples/properties.rb +1 -1
- data/examples/regions.rb +1 -1
- data/examples/rich_strings.rb +1 -1
- data/examples/right_to_left.rb +1 -1
- data/examples/shape1.rb +1 -1
- data/examples/shape2.rb +1 -1
- data/examples/shape3.rb +1 -1
- data/examples/shape4.rb +1 -1
- data/examples/shape5.rb +1 -1
- data/examples/shape6.rb +1 -1
- data/examples/shape7.rb +1 -1
- data/examples/shape8.rb +1 -1
- data/examples/shape_all.rb +1 -1
- data/examples/sparklines1.rb +1 -1
- data/examples/sparklines2.rb +1 -1
- data/examples/stats.rb +1 -1
- data/examples/stats_ext.rb +1 -1
- data/examples/stocks.rb +1 -1
- data/examples/tab_colors.rb +1 -1
- data/examples/tables.rb +1 -1
- data/lib/write_xlsx/chart.rb +18 -13
- data/lib/write_xlsx/chart/area.rb +1 -1
- data/lib/write_xlsx/chart/bar.rb +1 -1
- data/lib/write_xlsx/chart/column.rb +1 -1
- data/lib/write_xlsx/chart/doughnut.rb +1 -1
- data/lib/write_xlsx/chart/line.rb +1 -1
- data/lib/write_xlsx/chart/pie.rb +21 -8
- data/lib/write_xlsx/chart/radar.rb +1 -1
- data/lib/write_xlsx/chart/scatter.rb +1 -1
- data/lib/write_xlsx/chart/stock.rb +1 -1
- data/lib/write_xlsx/chartsheet.rb +5 -5
- data/lib/write_xlsx/drawing.rb +28 -8
- data/lib/write_xlsx/package/comments.rb +7 -7
- data/lib/write_xlsx/shape.rb +4 -3
- data/lib/write_xlsx/sheets.rb +11 -1
- data/lib/write_xlsx/sparkline.rb +1 -1
- data/lib/write_xlsx/utility.rb +18 -6
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +5 -5
- data/lib/write_xlsx/worksheet.rb +113 -125
- data/test/drawing/test_drawing_chart_01.rb +6 -2
- data/test/drawing/test_drawing_image_01.rb +12 -3
- data/test/drawing/test_drawing_shape_01.rb +8 -5
- data/test/drawing/test_drawing_shape_02.rb +12 -5
- data/test/drawing/test_drawing_shape_03.rb +8 -5
- data/test/drawing/test_drawing_shape_04.rb +8 -24
- data/test/drawing/test_drawing_shape_05.rb +8 -5
- data/test/drawing/test_drawing_shape_06.rb +11 -6
- data/test/drawing/test_drawing_shape_07.rb +11 -6
- data/test/drawing/test_write_a_graphic_frame_locks.rb +1 -1
- data/test/drawing/test_write_c_chart.rb +1 -1
- data/test/drawing/test_write_c_nv_graphic_frame_pr.rb +1 -1
- data/test/drawing/test_write_c_nv_pr.rb +1 -1
- data/test/drawing/test_write_col.rb +1 -1
- data/test/drawing/test_write_col_off.rb +1 -1
- data/test/drawing/test_write_ext.rb +1 -1
- data/test/drawing/test_write_pos.rb +1 -1
- data/test/drawing/test_write_row.rb +1 -1
- data/test/drawing/test_write_row_off.rb +1 -1
- data/test/drawing/test_write_xfrm_extension.rb +1 -1
- data/test/drawing/test_write_xfrm_offset.rb +1 -1
- data/test/perl_output/chart_gauge.xlsx +0 -0
- data/test/regression/test_chart_axis26.rb +10 -8
- data/test/regression/test_chart_axis27.rb +1 -1
- data/test/regression/test_chart_axis28.rb +1 -1
- data/test/regression/test_chart_axis29.rb +1 -1
- data/test/regression/test_chart_axis33.rb +1 -1
- data/test/regression/test_chart_axis44.rb +54 -0
- data/test/regression/test_chart_axis45.rb +54 -0
- data/test/regression/test_chart_axis46.rb +54 -0
- data/test/regression/test_chart_combined10.rb +43 -0
- data/test/regression/test_chart_combined11.rb +63 -0
- data/test/regression/test_chart_data_labels25.rb +1 -1
- data/test/regression/test_chart_doughnut07.rb +37 -0
- data/test/regression/test_chart_font09.rb +1 -1
- data/test/regression/test_chart_size03.rb +4 -1
- data/test/regression/test_comment14.rb +29 -0
- data/test/regression/test_image08.rb +5 -4
- data/test/regression/test_image15.rb +4 -2
- data/test/regression/test_image28.rb +1 -1
- data/test/regression/test_object_position01.rb +26 -0
- data/test/regression/test_object_position02.rb +26 -0
- data/test/regression/test_object_position03.rb +26 -0
- data/test/regression/test_object_position04.rb +44 -0
- data/test/regression/test_object_position06.rb +28 -0
- data/test/regression/test_object_position07.rb +28 -0
- data/test/regression/test_object_position08.rb +47 -0
- data/test/regression/test_object_position09.rb +50 -0
- data/test/regression/test_object_position10.rb +28 -0
- data/test/regression/test_shape_connect01.rb +4 -2
- data/test/regression/xlsx_files/chart_axis26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis33.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis44.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis45.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis46.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined10.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined11.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels25.xlsx +0 -0
- data/test/regression/xlsx_files/chart_doughnut07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_font09.xlsx +0 -0
- data/test/regression/xlsx_files/comment14.xlsx +0 -0
- data/test/regression/xlsx_files/object_position01.xlsx +0 -0
- data/test/regression/xlsx_files/object_position02.xlsx +0 -0
- data/test/regression/xlsx_files/object_position03.xlsx +0 -0
- data/test/regression/xlsx_files/object_position04.xlsx +0 -0
- data/test/regression/xlsx_files/object_position06.xlsx +0 -0
- data/test/regression/xlsx_files/object_position07.xlsx +0 -0
- data/test/regression/xlsx_files/object_position08.xlsx +0 -0
- data/test/regression/xlsx_files/object_position09.xlsx +0 -0
- data/test/regression/xlsx_files/object_position10.xlsx +0 -0
- data/test/test_example_match.rb +836 -771
- data/test/workbook/test_check_sheetname.rb +61 -0
- metadata +75 -6
data/examples/sparklines1.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
# of more complex sparkline formatting.
|
11
11
|
#
|
12
12
|
# reverse ('(c)'), November 2011, John McNamara, jmcnamara@cpan.org
|
13
|
-
# convert to ruby by Hideo NAKAMURA,
|
13
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
14
14
|
#
|
15
15
|
|
16
16
|
require 'write_xlsx'
|
data/examples/sparklines2.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
# options that can be applied to sparklines.
|
11
11
|
#
|
12
12
|
# reverse ('(c)'), November 2011, John McNamara, jmcnamara@cpan.org
|
13
|
-
# convert to ruby by Hideo NAKAMURA,
|
13
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
14
14
|
#
|
15
15
|
|
16
16
|
require 'write_xlsx'
|
data/examples/stats.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# A Simple example of how to use functions with the WriteXLSX gem.
|
7
7
|
#
|
8
8
|
# reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
|
9
|
-
# convert to ruby by Hideo NAKAMURA,
|
9
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
10
10
|
#
|
11
11
|
|
12
12
|
require 'write_xlsx'
|
data/examples/stats_ext.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
# other worksheets within the same workbook.
|
10
10
|
#
|
11
11
|
# reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
|
12
|
-
# convert to ruby by Hideo NAKAMURA,
|
12
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
13
13
|
#
|
14
14
|
|
15
15
|
require 'write_xlsx'
|
data/examples/stocks.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
# with colours to indicate if a share price has gone up or down.
|
10
10
|
#
|
11
11
|
# reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
|
12
|
-
# convert to ruby by Hideo NAKAMURA,
|
12
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
13
13
|
#
|
14
14
|
|
15
15
|
require 'write_xlsx'
|
data/examples/tab_colors.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Example of how to set Excel worksheet tab colours.
|
6
6
|
#
|
7
7
|
# reverse(c), May 2006, John McNamara, jmcnamara@cpan.org
|
8
|
-
# convert to ruby by Hideo NAKAMURA,
|
8
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
9
9
|
#
|
10
10
|
|
11
11
|
require 'write_xlsx'
|
data/examples/tables.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
# structure that can be references in a formula or formatted collectively.
|
10
10
|
#
|
11
11
|
# reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
|
12
|
-
# convert to ruby by Hideo NAKAMURA,
|
12
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
13
13
|
#
|
14
14
|
|
15
15
|
require 'write_xlsx'
|
data/lib/write_xlsx/chart.rb
CHANGED
@@ -1178,8 +1178,8 @@ def write_cat_axis(params) # :nodoc:
|
|
1178
1178
|
return unless axis_ids
|
1179
1179
|
return if axis_ids.empty?
|
1180
1180
|
|
1181
|
-
position
|
1182
|
-
|
1181
|
+
position = @cat_axis_position
|
1182
|
+
is_y_axis = @horiz_cat_axis
|
1183
1183
|
|
1184
1184
|
# Overwrite the default axis position with a user supplied value.
|
1185
1185
|
position = x_axis.position || position
|
@@ -1202,9 +1202,9 @@ def write_cat_axis(params) # :nodoc:
|
|
1202
1202
|
|
1203
1203
|
# Write the axis title elements.
|
1204
1204
|
if x_axis.formula
|
1205
|
-
write_title_formula(x_axis,
|
1205
|
+
write_title_formula(x_axis, is_y_axis, @x_axis, x_axis.layout)
|
1206
1206
|
elsif x_axis.name
|
1207
|
-
write_title_rich(x_axis,
|
1207
|
+
write_title_rich(x_axis, is_y_axis, x_axis.layout)
|
1208
1208
|
end
|
1209
1209
|
|
1210
1210
|
# Write the c:numFmt element.
|
@@ -1808,10 +1808,10 @@ def write_auto_title_deleted
|
|
1808
1808
|
#
|
1809
1809
|
# Write the <c:title> element for a rich string.
|
1810
1810
|
#
|
1811
|
-
def write_title_rich(title,
|
1811
|
+
def write_title_rich(title, is_y_axis = nil, layout = nil, overlay = nil) # :nodoc:
|
1812
1812
|
@writer.tag_elements('c:title') do
|
1813
1813
|
# Write the c:tx element.
|
1814
|
-
write_tx_rich(title,
|
1814
|
+
write_tx_rich(title, is_y_axis)
|
1815
1815
|
# Write the c:layout element.
|
1816
1816
|
write_layout(layout, 'text')
|
1817
1817
|
# Write the c:overlay element.
|
@@ -1822,7 +1822,7 @@ def write_title_rich(title, horiz = nil, layout = nil, overlay = nil) # :nodoc:
|
|
1822
1822
|
#
|
1823
1823
|
# Write the <c:title> element for a rich string.
|
1824
1824
|
#
|
1825
|
-
def write_title_formula(title,
|
1825
|
+
def write_title_formula(title, is_y_axis = nil, axis = nil, layout = nil, overlay = nil) # :nodoc:
|
1826
1826
|
@writer.tag_elements('c:title') do
|
1827
1827
|
# Write the c:tx element.
|
1828
1828
|
write_tx_formula(title.formula, axis ? axis.data_id : title.data_id)
|
@@ -1831,15 +1831,15 @@ def write_title_formula(title, horiz = nil, axis = nil, layout = nil, overlay =
|
|
1831
1831
|
# Write the c:overlay element.
|
1832
1832
|
write_overlay if overlay
|
1833
1833
|
# Write the c:txPr element.
|
1834
|
-
write_tx_pr(
|
1834
|
+
write_tx_pr(is_y_axis, axis ? axis.name_font : title.name_font)
|
1835
1835
|
end
|
1836
1836
|
end
|
1837
1837
|
|
1838
1838
|
#
|
1839
1839
|
# Write the <c:tx> element.
|
1840
1840
|
#
|
1841
|
-
def write_tx_rich(title,
|
1842
|
-
@writer.tag_elements('c:tx') { write_rich(title,
|
1841
|
+
def write_tx_rich(title, is_y_axis) # :nodoc:
|
1842
|
+
@writer.tag_elements('c:tx') { write_rich(title, is_y_axis) }
|
1843
1843
|
end
|
1844
1844
|
|
1845
1845
|
#
|
@@ -1861,14 +1861,14 @@ def write_tx_formula(title, data_id) # :nodoc:
|
|
1861
1861
|
#
|
1862
1862
|
# Write the <c:rich> element.
|
1863
1863
|
#
|
1864
|
-
def write_rich(title,
|
1864
|
+
def write_rich(title, is_y_axis) # :nodoc:
|
1865
1865
|
rotation = nil
|
1866
1866
|
if title.name_font && title.name_font[:_rotation]
|
1867
1867
|
rotation = title.name_font[:_rotation]
|
1868
1868
|
end
|
1869
1869
|
@writer.tag_elements('c:rich') do
|
1870
1870
|
# Write the a:bodyPr element.
|
1871
|
-
write_a_body_pr(rotation,
|
1871
|
+
write_a_body_pr(rotation, is_y_axis)
|
1872
1872
|
# Write the a:lstStyle element.
|
1873
1873
|
write_a_lst_style
|
1874
1874
|
# Write the a:p element.
|
@@ -2241,7 +2241,12 @@ def write_num_base(tag, data)
|
|
2241
2241
|
write_format_code('General')
|
2242
2242
|
|
2243
2243
|
# Write the c:ptCount element.
|
2244
|
-
|
2244
|
+
if data
|
2245
|
+
count = data.size
|
2246
|
+
else
|
2247
|
+
count = 0
|
2248
|
+
end
|
2249
|
+
write_pt_count(count)
|
2245
2250
|
|
2246
2251
|
data.each_with_index do |token, i|
|
2247
2252
|
# Write non-numeric data as 0.
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
data/lib/write_xlsx/chart/bar.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Excel::Writer::XLSX::Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2014, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
data/lib/write_xlsx/chart/pie.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
@@ -42,13 +42,6 @@ def initialize(subtype)
|
|
42
42
|
}
|
43
43
|
end
|
44
44
|
|
45
|
-
#
|
46
|
-
# Override parent method to add a warning.
|
47
|
-
#
|
48
|
-
def combine(chart)
|
49
|
-
raise "Combined chart not currently supported for Pie charts"
|
50
|
-
end
|
51
|
-
|
52
45
|
#
|
53
46
|
# Set the Pie/Doughnut chart rotation: the angle of the first slice.
|
54
47
|
#
|
@@ -91,11 +84,31 @@ def write_pie_chart
|
|
91
84
|
# Write the <c:plotArea> element.
|
92
85
|
#
|
93
86
|
def write_plot_area
|
87
|
+
second_chart = @combined
|
88
|
+
|
94
89
|
@writer.tag_elements('c:plotArea') do
|
95
90
|
# Write the c:layout element.
|
96
91
|
write_layout(@plotarea.layout, 'plot')
|
97
92
|
# Write the subclass chart type element.
|
98
93
|
write_chart_type
|
94
|
+
# Configure a combined chart if present.
|
95
|
+
if second_chart
|
96
|
+
# Secondary axis has unique id otherwise use same as primary.
|
97
|
+
if second_chart.is_secondary?
|
98
|
+
second_chart.id = 1000 + @id
|
99
|
+
else
|
100
|
+
second_chart.id = @id
|
101
|
+
end
|
102
|
+
|
103
|
+
# Share the same filehandle for writing
|
104
|
+
second_chart.writer = @writer
|
105
|
+
|
106
|
+
# Share series index with primary chart.
|
107
|
+
second_chart.series_index = @series_index
|
108
|
+
|
109
|
+
# Write the subclass chart type elements for combined chart.
|
110
|
+
second_chart.write_chart_type
|
111
|
+
end
|
99
112
|
# Write the c:spPr eleent for the plotarea formatting.
|
100
113
|
write_sp_pr(@plotarea)
|
101
114
|
end
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2012, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# See formatting note in Chart.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Convert to ruby by Hideo NAKAMURA,
|
11
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
|
14
14
|
require 'write_xlsx/package/xml_writer_simple'
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# Used in conjunction with WriteXLSX
|
7
7
|
#
|
8
8
|
# Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
|
9
|
-
# Convert to ruby by Hideo NAKAMURA,
|
9
|
+
# Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
10
10
|
#
|
11
11
|
|
12
12
|
require 'write_xlsx/worksheet'
|
@@ -19,7 +19,7 @@ class Chartsheet < Worksheet
|
|
19
19
|
|
20
20
|
def initialize(workbook, index, name)
|
21
21
|
super
|
22
|
-
@
|
22
|
+
@drawings = Drawings.new
|
23
23
|
@is_chartsheet = true
|
24
24
|
@chart = nil
|
25
25
|
@charts = [1]
|
@@ -176,9 +176,9 @@ def set_high_low_lines(*args)
|
|
176
176
|
def prepare_chart(index, chart_id, drawing_id) # :nodoc:
|
177
177
|
@chart.id = chart_id - 1
|
178
178
|
|
179
|
-
|
180
|
-
@
|
181
|
-
@
|
179
|
+
drawings = Drawings.new
|
180
|
+
@drawings = drawings
|
181
|
+
@drawings.orientation = @page_setup.orientation
|
182
182
|
|
183
183
|
@external_drawing_links << [ '/drawing', "../drawings/drawing#{drawing_id}.xml" ]
|
184
184
|
|
data/lib/write_xlsx/drawing.rb
CHANGED
@@ -4,6 +4,15 @@
|
|
4
4
|
|
5
5
|
module Writexlsx
|
6
6
|
class Drawing
|
7
|
+
attr_accessor :type, :dimensions, :width, :height, :name, :shape, :anchor
|
8
|
+
|
9
|
+
def initialize(type, dimensions, width, height, name, shape, anchor)
|
10
|
+
@type, @dimensions, @width, @height, @name, @shape, @anchor =
|
11
|
+
type, dimensions, width, height, name, shape, anchor
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Drawings
|
7
16
|
include Writexlsx::Utility
|
8
17
|
|
9
18
|
attr_writer :embedded, :orientation
|
@@ -32,10 +41,10 @@ def assemble_xml_file
|
|
32
41
|
write_drawing_workspace do
|
33
42
|
if @embedded
|
34
43
|
index = 0
|
35
|
-
@drawings.each do |
|
44
|
+
@drawings.each do |drawing|
|
36
45
|
# Write the xdr:twoCellAnchor element.
|
37
46
|
index += 1
|
38
|
-
write_two_cell_anchor(index,
|
47
|
+
write_two_cell_anchor(index, drawing)
|
39
48
|
end
|
40
49
|
else
|
41
50
|
# Write the xdr:absoluteAnchor element.
|
@@ -48,8 +57,8 @@ def assemble_xml_file
|
|
48
57
|
#
|
49
58
|
# Add a chart, image or shape sub object to the drawing.
|
50
59
|
#
|
51
|
-
def add_drawing_object(
|
52
|
-
@drawings <<
|
60
|
+
def add_drawing_object(drawing)
|
61
|
+
@drawings << drawing
|
53
62
|
end
|
54
63
|
|
55
64
|
private
|
@@ -71,14 +80,25 @@ def write_drawing_workspace
|
|
71
80
|
# Write the <xdr:twoCellAnchor> element.
|
72
81
|
#
|
73
82
|
def write_two_cell_anchor(*args)
|
74
|
-
index,
|
75
|
-
|
76
|
-
|
83
|
+
index, drawing = args
|
84
|
+
|
85
|
+
type = drawing.type
|
86
|
+
width = drawing.width
|
87
|
+
height = drawing.height
|
88
|
+
description = drawing.name
|
89
|
+
shape = drawing.shape
|
90
|
+
anchor = drawing.anchor
|
91
|
+
col_from, row_from, col_from_offset, row_from_offset,
|
92
|
+
col_to, row_to, col_to_offset, row_to_offset, col_absolute, row_absolute = drawing.dimensions
|
77
93
|
|
78
94
|
attributes = []
|
79
95
|
|
80
96
|
# Add attribute for images.
|
81
|
-
|
97
|
+
if anchor == 2
|
98
|
+
attributes << [:editAs, 'oneCell']
|
99
|
+
elsif anchor == 3
|
100
|
+
attributes << [:editAs, 'absolute']
|
101
|
+
end
|
82
102
|
|
83
103
|
# Add attribute for shapes.
|
84
104
|
attributes << [:editAs, shape.edit_as] if shape && shape.edit_as
|
@@ -257,13 +257,9 @@ def [](row)
|
|
257
257
|
@comments[row]
|
258
258
|
end
|
259
259
|
|
260
|
-
def add(
|
261
|
-
|
262
|
-
|
263
|
-
else
|
264
|
-
@comments[comment.row] = {}
|
265
|
-
@comments[comment.row][comment.col] = comment
|
266
|
-
end
|
260
|
+
def add(workbook, worksheet, row, col, string, options)
|
261
|
+
@comments[row] ||= {}
|
262
|
+
@comments[row][col] = [workbook, worksheet, row, col, string, options]
|
267
263
|
end
|
268
264
|
|
269
265
|
def empty?
|
@@ -293,6 +289,10 @@ def sorted_comments
|
|
293
289
|
# We sort the comments by row and column but that isn't strictly required.
|
294
290
|
@comments.keys.sort.each do |row|
|
295
291
|
@comments[row].keys.sort.each do |col|
|
292
|
+
user_options = @comments[row][col]
|
293
|
+
comment = Comment.new(*user_options)
|
294
|
+
@comments[row][col] = comment
|
295
|
+
|
296
296
|
# Set comment visibility if required and not already user defined.
|
297
297
|
@comments[row][col].visible ||= 1 if comments_visible?
|
298
298
|
|
data/lib/write_xlsx/shape.rb
CHANGED
@@ -8,14 +8,14 @@ module Writexlsx
|
|
8
8
|
# Used in conjunction with WriteXLSX.
|
9
9
|
#
|
10
10
|
# Copyright 2000-2012, John McNamara, jmcnamara@cpan.org
|
11
|
-
# Converted to ruby by Hideo NAKAMURA,
|
11
|
+
# Converted to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
12
12
|
#
|
13
13
|
class Shape
|
14
14
|
include Writexlsx::Utility
|
15
15
|
|
16
16
|
attr_reader :edit_as, :type, :drawing
|
17
17
|
attr_reader :tx_box, :fill, :line, :format
|
18
|
-
attr_reader :align, :valign
|
18
|
+
attr_reader :align, :valign, :anchor
|
19
19
|
attr_accessor :name, :connect, :type, :id, :start, :end, :rotation
|
20
20
|
attr_accessor :flip_h, :flip_v, :adjustments, :palette, :text, :stencil
|
21
21
|
attr_accessor :row_start, :row_end, :column_start, :column_end
|
@@ -183,11 +183,12 @@ def calc_position_emus(worksheet)
|
|
183
183
|
@y_abs = (y_abslt * 9_525).to_i
|
184
184
|
end
|
185
185
|
|
186
|
-
def set_position(row_start, column_start, x_offset, y_offset, x_scale, y_scale)
|
186
|
+
def set_position(row_start, column_start, x_offset, y_offset, x_scale, y_scale, anchor)
|
187
187
|
@row_start = row_start
|
188
188
|
@column_start = column_start
|
189
189
|
@x_offset = x_offset || 0
|
190
190
|
@y_offset = y_offset || 0
|
191
|
+
@anchor = anchor || 1
|
191
192
|
|
192
193
|
# Override shape scale if supplied as an argument. Otherwise, use the
|
193
194
|
# existing shape scale factors.
|