write_xlsx 0.97.0 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes +27 -0
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/lib/write_xlsx/chart.rb +25 -22
- data/lib/write_xlsx/chart/axis.rb +2 -2
- data/lib/write_xlsx/chart/legend.rb +14 -0
- data/lib/write_xlsx/chart/pie.rb +9 -7
- data/lib/write_xlsx/chartsheet.rb +30 -2
- data/lib/write_xlsx/format.rb +4 -4
- data/lib/write_xlsx/package/comments.rb +50 -47
- data/lib/write_xlsx/package/conditional_format.rb +9 -1
- data/lib/write_xlsx/package/table.rb +5 -0
- data/lib/write_xlsx/utility.rb +59 -1
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +30 -5
- data/lib/write_xlsx/worksheet.rb +31 -13
- data/lib/write_xlsx/worksheet/data_validation.rb +10 -14
- data/test/chart/test_write_legend_pos.rb +9 -1
- data/test/chartsheet/test_write_sheet_protection.rb +91 -0
- data/test/package/comments/test_comments_01.rb +54 -0
- data/test/package/comments/test_comments_02.rb +54 -0
- data/test/perl_output/formats.xlsx +0 -0
- data/test/regression/images/happy.jpg +0 -0
- data/test/regression/test_array_formula03.rb +36 -0
- data/test/regression/test_autofilter08.rb +110 -0
- data/test/regression/test_autofilter09.rb +110 -0
- data/test/regression/test_autofilter10.rb +110 -0
- data/test/regression/test_chart_axis42.rb +44 -0
- data/test/regression/test_chart_axis43.rb +44 -0
- data/test/regression/test_chart_legend03.rb +41 -0
- data/test/regression/test_chart_legend04.rb +41 -0
- data/test/regression/test_chart_legend05.rb +41 -0
- data/test/regression/test_chart_legend06.rb +41 -0
- data/test/regression/test_chart_legend07.rb +38 -0
- data/test/regression/test_comment13.rb +36 -0
- data/test/regression/test_cond_format19.rb +64 -0
- data/test/regression/test_cond_format20.rb +43 -0
- data/test/regression/test_format15.rb +26 -0
- data/test/regression/test_image36.rb +26 -0
- data/test/regression/test_table23.rb +56 -0
- data/test/regression/xlsx_files/array_formula03.xlsx +0 -0
- data/test/regression/xlsx_files/autofilter08.xlsx +0 -0
- data/test/regression/xlsx_files/autofilter09.xlsx +0 -0
- data/test/regression/xlsx_files/autofilter10.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis42.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis43.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend03.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend04.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend06.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend07.xlsx +0 -0
- data/test/regression/xlsx_files/comment13.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format19.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format20.xlsx +0 -0
- data/test/regression/xlsx_files/format15.xlsx +0 -0
- data/test/regression/xlsx_files/image36.xlsx +0 -0
- data/test/regression/xlsx_files/table23.xlsx +0 -0
- data/test/workbook/test_write_workbook_view.rb +36 -0
- data/test/worksheet/test_write_data_validation_02.rb +17 -0
- data/test/worksheet/test_write_sheet_view.rb +19 -1
- metadata +79 -4
- data/test/package/comments/test_write_text_t.rb +0 -44
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestComments02 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@workbook = WriteXLSX.new(StringIO.new)
|
7
|
+
@worksheet = @workbook.add_worksheet('')
|
8
|
+
end
|
9
|
+
|
10
|
+
###############################################################################
|
11
|
+
#
|
12
|
+
# Test the _assemble_xml_file() method.
|
13
|
+
#
|
14
|
+
def test_assemble_xml_file
|
15
|
+
@worksheet.write_comment(
|
16
|
+
1, 1, 'Some text',
|
17
|
+
:author => 'John', :visible => nil, :color => 81,
|
18
|
+
:font => 'Calibri', :font_size => 20, :font_family => 2
|
19
|
+
)
|
20
|
+
|
21
|
+
comments = @worksheet.comments
|
22
|
+
comments.assemble_xml_file
|
23
|
+
result = got_to_array(comments.instance_variable_get(:@writer).string)
|
24
|
+
|
25
|
+
expected = expected_to_array(expected_xml)
|
26
|
+
assert_equal(expected, result)
|
27
|
+
end
|
28
|
+
|
29
|
+
def expected_xml
|
30
|
+
<<EOS
|
31
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
32
|
+
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
33
|
+
<authors>
|
34
|
+
<author>John</author>
|
35
|
+
</authors>
|
36
|
+
<commentList>
|
37
|
+
<comment ref="B2" authorId="0">
|
38
|
+
<text>
|
39
|
+
<r>
|
40
|
+
<rPr>
|
41
|
+
<sz val="20"/>
|
42
|
+
<color indexed="81"/>
|
43
|
+
<rFont val="Calibri"/>
|
44
|
+
<family val="2"/>
|
45
|
+
</rPr>
|
46
|
+
<t>Some text</t>
|
47
|
+
</r>
|
48
|
+
</text>
|
49
|
+
</comment>
|
50
|
+
</commentList>
|
51
|
+
</comments>
|
52
|
+
EOS
|
53
|
+
end
|
54
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionArrayFormula03 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_array_formula03
|
14
|
+
@xlsx = 'array_formula03.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
data = [0, 0, 0]
|
19
|
+
|
20
|
+
worksheet.write_col('B1', data)
|
21
|
+
worksheet.write_col('C1', data)
|
22
|
+
|
23
|
+
worksheet.write_formula(
|
24
|
+
'A1',
|
25
|
+
'{=SUM(B1:C1*B2:C2)}',
|
26
|
+
nil,
|
27
|
+
0
|
28
|
+
)
|
29
|
+
|
30
|
+
workbook.close
|
31
|
+
compare_for_regression(
|
32
|
+
[ 'xl/calcChain.xml', '[Content_Types].xml', 'xl/_rels/workbook.xml.rels' ],
|
33
|
+
{'xl/workbook.xml' => ['<workbookView']}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionAutofilter08 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_autofilter08
|
14
|
+
@xlsx = 'autofilter08.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
# Extract the data embedded at the end of this file.
|
19
|
+
data = []
|
20
|
+
data_lines.split(/\n/).each { |line| data << line.split }
|
21
|
+
|
22
|
+
worksheet.write('A1', headings)
|
23
|
+
|
24
|
+
# Create a blank cell in out test data.
|
25
|
+
data[5][0] = ''
|
26
|
+
|
27
|
+
worksheet.autofilter('A1:D51')
|
28
|
+
worksheet.filter_column('A', 'x == Blanks or x == North')
|
29
|
+
|
30
|
+
# Hide the rows that don't match the filter criteria.
|
31
|
+
row = 1
|
32
|
+
|
33
|
+
data.each do |row_data|
|
34
|
+
region = row_data[0]
|
35
|
+
if region == '' || region == 'North'
|
36
|
+
# Row is visible.
|
37
|
+
else
|
38
|
+
# Hide row.
|
39
|
+
worksheet.set_row(row, nil, nil, 1)
|
40
|
+
end
|
41
|
+
worksheet.write(row, 0, row_data)
|
42
|
+
row += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
workbook.close
|
46
|
+
compare_for_regression(
|
47
|
+
nil,
|
48
|
+
{'xl/workbook.xml' => ['<workbookView']}
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def headings
|
53
|
+
%w[Region Item Volume Month]
|
54
|
+
end
|
55
|
+
|
56
|
+
def data_lines
|
57
|
+
<<EOS
|
58
|
+
East Apple 9000 July
|
59
|
+
East Apple 5000 July
|
60
|
+
South Orange 9000 September
|
61
|
+
North Apple 2000 November
|
62
|
+
West Apple 9000 November
|
63
|
+
South Pear 7000 October
|
64
|
+
North Pear 9000 August
|
65
|
+
West Orange 1000 December
|
66
|
+
West Grape 1000 November
|
67
|
+
South Pear 10000 April
|
68
|
+
West Grape 6000 January
|
69
|
+
South Orange 3000 May
|
70
|
+
North Apple 3000 December
|
71
|
+
South Apple 7000 February
|
72
|
+
West Grape 1000 December
|
73
|
+
East Grape 8000 February
|
74
|
+
South Grape 10000 June
|
75
|
+
West Pear 7000 December
|
76
|
+
South Apple 2000 October
|
77
|
+
East Grape 7000 December
|
78
|
+
North Grape 6000 April
|
79
|
+
East Pear 8000 February
|
80
|
+
North Apple 7000 August
|
81
|
+
North Orange 7000 July
|
82
|
+
North Apple 6000 June
|
83
|
+
South Grape 8000 September
|
84
|
+
West Apple 3000 October
|
85
|
+
South Orange 10000 November
|
86
|
+
West Grape 4000 July
|
87
|
+
North Orange 5000 August
|
88
|
+
East Orange 1000 November
|
89
|
+
East Orange 4000 October
|
90
|
+
North Grape 5000 August
|
91
|
+
East Apple 1000 December
|
92
|
+
South Apple 10000 March
|
93
|
+
East Grape 7000 October
|
94
|
+
West Grape 1000 September
|
95
|
+
East Grape 10000 October
|
96
|
+
South Orange 8000 March
|
97
|
+
North Apple 4000 July
|
98
|
+
South Orange 5000 July
|
99
|
+
West Apple 4000 June
|
100
|
+
East Apple 5000 April
|
101
|
+
North Pear 3000 August
|
102
|
+
East Grape 9000 November
|
103
|
+
North Orange 8000 October
|
104
|
+
East Apple 10000 June
|
105
|
+
South Pear 1000 December
|
106
|
+
North Grape 10000 July
|
107
|
+
East Grape 6000 February
|
108
|
+
EOS
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionAutofilter09 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_autofilter09
|
14
|
+
@xlsx = 'autofilter09.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
# Extract the data embedded at the end of this file.
|
19
|
+
data = []
|
20
|
+
data_lines.split(/\n/).each { |line| data << line.split }
|
21
|
+
|
22
|
+
worksheet.write('A1', headings)
|
23
|
+
|
24
|
+
# Create a blank cell in out test data.
|
25
|
+
data[5][0] = ''
|
26
|
+
|
27
|
+
worksheet.autofilter('A1:D51')
|
28
|
+
worksheet.filter_column_list('A', %w(East North South))
|
29
|
+
|
30
|
+
# Hide the rows that don't match the filter criteria.
|
31
|
+
row = 1
|
32
|
+
|
33
|
+
data.each do |row_data|
|
34
|
+
region = row_data[0]
|
35
|
+
if %w(East North South).include?(region)
|
36
|
+
# Row is visible.
|
37
|
+
else
|
38
|
+
# Hide row.
|
39
|
+
worksheet.set_row(row, nil, nil, 1)
|
40
|
+
end
|
41
|
+
worksheet.write(row, 0, row_data)
|
42
|
+
row += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
workbook.close
|
46
|
+
compare_for_regression(
|
47
|
+
nil,
|
48
|
+
{'xl/workbook.xml' => ['<workbookView']}
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def headings
|
53
|
+
%w[Region Item Volume Month]
|
54
|
+
end
|
55
|
+
|
56
|
+
def data_lines
|
57
|
+
<<EOS
|
58
|
+
East Apple 9000 July
|
59
|
+
East Apple 5000 July
|
60
|
+
South Orange 9000 September
|
61
|
+
North Apple 2000 November
|
62
|
+
West Apple 9000 November
|
63
|
+
South Pear 7000 October
|
64
|
+
North Pear 9000 August
|
65
|
+
West Orange 1000 December
|
66
|
+
West Grape 1000 November
|
67
|
+
South Pear 10000 April
|
68
|
+
West Grape 6000 January
|
69
|
+
South Orange 3000 May
|
70
|
+
North Apple 3000 December
|
71
|
+
South Apple 7000 February
|
72
|
+
West Grape 1000 December
|
73
|
+
East Grape 8000 February
|
74
|
+
South Grape 10000 June
|
75
|
+
West Pear 7000 December
|
76
|
+
South Apple 2000 October
|
77
|
+
East Grape 7000 December
|
78
|
+
North Grape 6000 April
|
79
|
+
East Pear 8000 February
|
80
|
+
North Apple 7000 August
|
81
|
+
North Orange 7000 July
|
82
|
+
North Apple 6000 June
|
83
|
+
South Grape 8000 September
|
84
|
+
West Apple 3000 October
|
85
|
+
South Orange 10000 November
|
86
|
+
West Grape 4000 July
|
87
|
+
North Orange 5000 August
|
88
|
+
East Orange 1000 November
|
89
|
+
East Orange 4000 October
|
90
|
+
North Grape 5000 August
|
91
|
+
East Apple 1000 December
|
92
|
+
South Apple 10000 March
|
93
|
+
East Grape 7000 October
|
94
|
+
West Grape 1000 September
|
95
|
+
East Grape 10000 October
|
96
|
+
South Orange 8000 March
|
97
|
+
North Apple 4000 July
|
98
|
+
South Orange 5000 July
|
99
|
+
West Apple 4000 June
|
100
|
+
East Apple 5000 April
|
101
|
+
North Pear 3000 August
|
102
|
+
East Grape 9000 November
|
103
|
+
North Orange 8000 October
|
104
|
+
East Apple 10000 June
|
105
|
+
South Pear 1000 December
|
106
|
+
North Grape 10000 July
|
107
|
+
East Grape 6000 February
|
108
|
+
EOS
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionAutofilter10 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_autofilter10
|
14
|
+
@xlsx = 'autofilter10.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
# Extract the data embedded at the end of this file.
|
19
|
+
data = []
|
20
|
+
data_lines.split(/\n/).each { |line| data << line.split }
|
21
|
+
|
22
|
+
worksheet.write('A1', headings)
|
23
|
+
|
24
|
+
# Create a blank cell in out test data.
|
25
|
+
data[5][0] = ''
|
26
|
+
|
27
|
+
worksheet.autofilter('A1:D51')
|
28
|
+
worksheet.filter_column_list('A', %w(North South East Blanks))
|
29
|
+
|
30
|
+
# Hide the rows that don't match the filter criteria.
|
31
|
+
row = 1
|
32
|
+
|
33
|
+
data.each do |row_data|
|
34
|
+
region = row_data[0]
|
35
|
+
if %w(North South East).include?(region) || region == ''
|
36
|
+
# Row is visible.
|
37
|
+
else
|
38
|
+
# Hide row.
|
39
|
+
worksheet.set_row(row, nil, nil, 1)
|
40
|
+
end
|
41
|
+
worksheet.write(row, 0, row_data)
|
42
|
+
row += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
workbook.close
|
46
|
+
compare_for_regression(
|
47
|
+
nil,
|
48
|
+
{'xl/workbook.xml' => ['<workbookView']}
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def headings
|
53
|
+
%w[Region Item Volume Month]
|
54
|
+
end
|
55
|
+
|
56
|
+
def data_lines
|
57
|
+
<<EOS
|
58
|
+
East Apple 9000 July
|
59
|
+
East Apple 5000 July
|
60
|
+
South Orange 9000 September
|
61
|
+
North Apple 2000 November
|
62
|
+
West Apple 9000 November
|
63
|
+
South Pear 7000 October
|
64
|
+
North Pear 9000 August
|
65
|
+
West Orange 1000 December
|
66
|
+
West Grape 1000 November
|
67
|
+
South Pear 10000 April
|
68
|
+
West Grape 6000 January
|
69
|
+
South Orange 3000 May
|
70
|
+
North Apple 3000 December
|
71
|
+
South Apple 7000 February
|
72
|
+
West Grape 1000 December
|
73
|
+
East Grape 8000 February
|
74
|
+
South Grape 10000 June
|
75
|
+
West Pear 7000 December
|
76
|
+
South Apple 2000 October
|
77
|
+
East Grape 7000 December
|
78
|
+
North Grape 6000 April
|
79
|
+
East Pear 8000 February
|
80
|
+
North Apple 7000 August
|
81
|
+
North Orange 7000 July
|
82
|
+
North Apple 6000 June
|
83
|
+
South Grape 8000 September
|
84
|
+
West Apple 3000 October
|
85
|
+
South Orange 10000 November
|
86
|
+
West Grape 4000 July
|
87
|
+
North Orange 5000 August
|
88
|
+
East Orange 1000 November
|
89
|
+
East Orange 4000 October
|
90
|
+
North Grape 5000 August
|
91
|
+
East Apple 1000 December
|
92
|
+
South Apple 10000 March
|
93
|
+
East Grape 7000 October
|
94
|
+
West Grape 1000 September
|
95
|
+
East Grape 10000 October
|
96
|
+
South Orange 8000 March
|
97
|
+
North Apple 4000 July
|
98
|
+
South Orange 5000 July
|
99
|
+
West Apple 4000 June
|
100
|
+
East Apple 5000 April
|
101
|
+
North Pear 3000 August
|
102
|
+
East Grape 9000 November
|
103
|
+
North Orange 8000 October
|
104
|
+
East Apple 10000 June
|
105
|
+
South Pear 1000 December
|
106
|
+
North Grape 10000 July
|
107
|
+
East Grape 6000 February
|
108
|
+
EOS
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartAxis42 < Minitest::Test
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@tempfile.close(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_chart_axis42
|
14
|
+
@xlsx = 'chart_axis42.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@io)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'column', :embedded => 1)
|
18
|
+
|
19
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
20
|
+
chart.instance_variable_set(:@axis_ids, [61296640, 61298560])
|
21
|
+
|
22
|
+
data = [
|
23
|
+
[ 1, 2, 3, 4, 5 ],
|
24
|
+
[ 2, 4, 6, 8, 10 ],
|
25
|
+
[ 3, 6, 9, 12, 15 ]
|
26
|
+
]
|
27
|
+
|
28
|
+
worksheet.write('A1', data)
|
29
|
+
|
30
|
+
chart.add_series(:values => '=Sheet1!$A$1:$A$5')
|
31
|
+
chart.add_series(:values => '=Sheet1!$B$1:$B$5')
|
32
|
+
chart.add_series(:values => '=Sheet1!$C$1:$C$5')
|
33
|
+
|
34
|
+
chart.set_x_axis(:label_align => 'right')
|
35
|
+
|
36
|
+
worksheet.insert_chart('E9', chart)
|
37
|
+
|
38
|
+
workbook.close
|
39
|
+
compare_for_regression(
|
40
|
+
nil,
|
41
|
+
{ 'xl/charts/chart1.xml' => ['<c:pageMargins'] }
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|