write_xlsx 0.90.0 → 0.97.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/Changes +37 -0
  3. data/README.md +1 -1
  4. data/examples/a_simple.rb +1 -6
  5. data/examples/conditional_format.rb +73 -46
  6. data/examples/demo.rb +1 -7
  7. data/examples/hyperlink1.rb +4 -11
  8. data/lib/write_xlsx/chart.rb +81 -205
  9. data/lib/write_xlsx/chart/axis.rb +2 -2
  10. data/lib/write_xlsx/chart/caption.rb +3 -1
  11. data/lib/write_xlsx/chart/pie.rb +2 -0
  12. data/lib/write_xlsx/chart/series.rb +11 -7
  13. data/lib/write_xlsx/format.rb +15 -11
  14. data/lib/write_xlsx/package/conditional_format.rb +351 -38
  15. data/lib/write_xlsx/package/content_types.rb +10 -0
  16. data/lib/write_xlsx/package/custom.rb +125 -0
  17. data/lib/write_xlsx/package/packager.rb +26 -0
  18. data/lib/write_xlsx/package/styles.rb +53 -21
  19. data/lib/write_xlsx/package/table.rb +11 -4
  20. data/lib/write_xlsx/utility.rb +234 -34
  21. data/lib/write_xlsx/version.rb +1 -1
  22. data/lib/write_xlsx/workbook.rb +88 -1
  23. data/lib/write_xlsx/worksheet.rb +247 -23
  24. data/test/helper.rb +6 -1
  25. data/test/regression/_test_hyperlink31.rb +26 -0
  26. data/test/regression/images/zero_dpi.jpg +0 -0
  27. data/test/regression/test_chart_bar08.rb +3 -0
  28. data/test/regression/test_chart_bar11.rb +3 -0
  29. data/test/regression/test_chart_bar14.rb +3 -0
  30. data/test/regression/test_chart_chartarea05.rb +16 -17
  31. data/test/regression/test_chart_chartarea06.rb +49 -0
  32. data/test/regression/test_chart_data_labels25.rb +61 -0
  33. data/test/regression/test_chart_format26.rb +48 -0
  34. data/test/regression/test_chart_format27.rb +58 -0
  35. data/test/regression/test_chart_format28.rb +52 -0
  36. data/test/regression/test_chart_format29.rb +59 -0
  37. data/test/regression/test_chart_format30.rb +53 -0
  38. data/test/regression/test_chart_format31.rb +60 -0
  39. data/test/regression/test_chart_table03.rb +56 -0
  40. data/test/regression/test_cond_format14.rb +42 -0
  41. data/test/regression/test_cond_format15.rb +53 -0
  42. data/test/regression/test_cond_format16.rb +53 -0
  43. data/test/regression/test_cond_format17.rb +37 -0
  44. data/test/regression/test_cond_format18.rb +136 -0
  45. data/test/regression/test_date_1904_01.rb +1 -1
  46. data/test/regression/test_escapes04.rb +3 -0
  47. data/test/regression/test_escapes05.rb +3 -0
  48. data/test/regression/test_escapes07.rb +3 -0
  49. data/test/regression/test_escapes08.rb +3 -0
  50. data/test/regression/test_hyperlink01.rb +3 -0
  51. data/test/regression/test_hyperlink02.rb +3 -0
  52. data/test/regression/test_hyperlink03.rb +4 -0
  53. data/test/regression/test_hyperlink04.rb +3 -0
  54. data/test/regression/test_hyperlink05.rb +3 -0
  55. data/test/regression/test_hyperlink06.rb +3 -0
  56. data/test/regression/test_hyperlink07.rb +3 -0
  57. data/test/regression/test_hyperlink08.rb +3 -0
  58. data/test/regression/test_hyperlink09.rb +3 -0
  59. data/test/regression/test_hyperlink10.rb +3 -0
  60. data/test/regression/test_hyperlink11.rb +3 -0
  61. data/test/regression/test_hyperlink12.rb +3 -0
  62. data/test/regression/test_hyperlink13.rb +3 -0
  63. data/test/regression/test_hyperlink14.rb +3 -0
  64. data/test/regression/test_hyperlink15.rb +3 -0
  65. data/test/regression/test_hyperlink16.rb +3 -0
  66. data/test/regression/test_hyperlink17.rb +3 -0
  67. data/test/regression/test_hyperlink18.rb +3 -0
  68. data/test/regression/test_hyperlink20.rb +3 -0
  69. data/test/regression/test_hyperlink21.rb +3 -0
  70. data/test/regression/test_hyperlink22.rb +3 -0
  71. data/test/regression/test_hyperlink23.rb +3 -0
  72. data/test/regression/test_hyperlink24.rb +3 -0
  73. data/test/regression/test_hyperlink25.rb +3 -0
  74. data/test/regression/test_hyperlink26.rb +3 -0
  75. data/test/regression/test_hyperlink27.rb +3 -0
  76. data/test/regression/test_hyperlink28.rb +50 -0
  77. data/test/regression/test_hyperlink29.rb +27 -0
  78. data/test/regression/test_hyperlink30.rb +36 -0
  79. data/test/regression/test_image35.rb +26 -0
  80. data/test/regression/test_properties01.rb +1 -4
  81. data/test/regression/test_properties02.rb +1 -4
  82. data/test/regression/test_properties03.rb +26 -0
  83. data/test/regression/test_properties04.rb +61 -0
  84. data/test/regression/test_properties05.rb +30 -0
  85. data/test/regression/test_table03.rb +3 -0
  86. data/test/regression/test_table04.rb +3 -0
  87. data/test/regression/test_table05.rb +3 -0
  88. data/test/regression/test_table06.rb +3 -0
  89. data/test/regression/test_table20.rb +34 -0
  90. data/test/regression/test_table21.rb +36 -0
  91. data/test/regression/test_table22.rb +32 -0
  92. data/test/regression/xlsx_files/chart_chartarea05.xlsx +0 -0
  93. data/test/regression/xlsx_files/chart_chartarea06.xlsx +0 -0
  94. data/test/regression/xlsx_files/chart_data_labels25.xlsx +0 -0
  95. data/test/regression/xlsx_files/chart_format26.xlsx +0 -0
  96. data/test/regression/xlsx_files/chart_format27.xlsx +0 -0
  97. data/test/regression/xlsx_files/chart_format28.xlsx +0 -0
  98. data/test/regression/xlsx_files/chart_format29.xlsx +0 -0
  99. data/test/regression/xlsx_files/chart_format30.xlsx +0 -0
  100. data/test/regression/xlsx_files/chart_format31.xlsx +0 -0
  101. data/test/regression/xlsx_files/chart_table03.xlsx +0 -0
  102. data/test/regression/xlsx_files/cond_format14.xlsx +0 -0
  103. data/test/regression/xlsx_files/cond_format15.xlsx +0 -0
  104. data/test/regression/xlsx_files/cond_format16.xlsx +0 -0
  105. data/test/regression/xlsx_files/cond_format17.xlsx +0 -0
  106. data/test/regression/xlsx_files/cond_format18.xlsx +0 -0
  107. data/test/regression/xlsx_files/date_1904_01.xlsx +0 -0
  108. data/test/regression/xlsx_files/hyperlink28.xlsx +0 -0
  109. data/test/regression/xlsx_files/hyperlink29.xlsx +0 -0
  110. data/test/regression/xlsx_files/hyperlink30.xlsx +0 -0
  111. data/test/regression/xlsx_files/hyperlink31.xlsx +0 -0
  112. data/test/regression/xlsx_files/image35.xlsx +0 -0
  113. data/test/regression/xlsx_files/properties03.xlsx +0 -0
  114. data/test/regression/xlsx_files/properties04.xlsx +0 -0
  115. data/test/regression/xlsx_files/properties05.xlsx +0 -0
  116. data/test/regression/xlsx_files/table21.xlsx +0 -0
  117. data/test/regression/xlsx_files/table22.xlsx +0 -0
  118. data/test/workbook/test_write_workbook_view.rb +81 -0
  119. data/test/worksheet/test_cond_format_22.rb +266 -0
  120. data/test/worksheet/test_cond_format_23.rb +242 -0
  121. data/test/worksheet/test_cond_format_24.rb +303 -0
  122. data/test/worksheet/test_data_bar_01.rb +53 -0
  123. data/test/worksheet/test_data_bar_02.rb +79 -0
  124. data/test/worksheet/test_data_bar_03.rb +147 -0
  125. data/test/worksheet/test_data_bar_04.rb +145 -0
  126. data/test/worksheet/test_data_bar_05.rb +147 -0
  127. data/test/worksheet/test_data_bar_06.rb +145 -0
  128. data/test/worksheet/test_data_bar_07.rb +146 -0
  129. data/test/worksheet/test_data_bar_08.rb +54 -0
  130. data/test/worksheet/test_data_bar_09.rb +80 -0
  131. data/test/worksheet/test_data_bar_10.rb +165 -0
  132. data/test/worksheet/test_data_bar_11.rb +167 -0
  133. data/test/worksheet/test_data_bar_12.rb +104 -0
  134. data/test/worksheet/test_write_data_validation_02.rb +27 -0
  135. metadata +135 -2
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartFormat30 < 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_format30
14
+ @xlsx = 'chart_format30.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+ chart = workbook.add_chart(:type => 'line', :embedded => 1)
18
+
19
+ # For testing, copy the randomly generated axis ids in the target xlsx file.
20
+ chart.instance_variable_set(:@axis_ids, [108652416, 108655744])
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(
31
+ :categories => '=Sheet1!$A$1:$A$5',
32
+ :values => '=Sheet1!$B$1:$B$5',
33
+ :trendline => {
34
+ :type => 'linear',
35
+ :intercept => 0.8,
36
+ :display_equation => 1,
37
+ :display_r_squared => 1
38
+ }
39
+ )
40
+
41
+ chart.add_series(
42
+ :categories => '=Sheet1!$A$1:$A$5',
43
+ :values => '=Sheet1!$C$1:$C$5'
44
+ )
45
+
46
+ chart.set_legend(:delete_series => [0, 2])
47
+
48
+ worksheet.insert_chart('E9', chart)
49
+
50
+ workbook.close
51
+ compare_for_regression
52
+ end
53
+ end
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartFormat31 < 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_format31
14
+ @xlsx = 'chart_format31.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+ chart = workbook.add_chart(:type => 'line', :embedded => 1)
18
+
19
+ # For testing, copy the randomly generated axis ids in the target xlsx file.
20
+ chart.instance_variable_set(:@axis_ids, [115443200, 115459200])
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(
31
+ :categories => '=Sheet1!$A$1:$A$5',
32
+ :values => '=Sheet1!$B$1:$B$5',
33
+ :trendline => {
34
+ :type => 'polynomial',
35
+ :name => 'My trend name',
36
+ :order => 2,
37
+ :forward => 0.5,
38
+ :backward => 0.5,
39
+ :intercept => 1.5,
40
+ :display_equation => 1,
41
+ :display_r_squared => 1,
42
+ :line => {
43
+ :color => 'red',
44
+ :width => 1,
45
+ :dash_type => 'long_dash'
46
+ }
47
+ }
48
+ )
49
+
50
+ chart.add_series(
51
+ :categories => '=Sheet1!$A$1:$A$5',
52
+ :values => '=Sheet1!$C$1:$C$5'
53
+ )
54
+
55
+ worksheet.insert_chart('E9', chart)
56
+
57
+ workbook.close
58
+ compare_for_regression
59
+ end
60
+ end
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestChartTable03 < 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_table03
14
+ @xlsx = 'chart_table03.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 xls file.
20
+ chart.instance_variable_set(:@axis_ids, [108636032, 108643840])
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
+ # Test the default table.
35
+ chart.set_table(
36
+ :vertical => false,
37
+ :horizontal => false,
38
+ :outline => false,
39
+ :show_keys => true,
40
+ :font => {
41
+ :bold => 1,
42
+ :italic => 1,
43
+ :color => 'red',
44
+ :baseline => -1
45
+ }
46
+ )
47
+
48
+ worksheet.insert_chart('E9', chart)
49
+
50
+ workbook.close
51
+ compare_for_regression(
52
+ nil,
53
+ {'xl/charts/chart1.xml' => ['a:pPr']}
54
+ )
55
+ end
56
+ end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionCondFormat14 < 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_cond_format14
14
+ @xlsx = 'cond_format14.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ format = workbook.add_format(:bg_color => 'red')
19
+
20
+ worksheet.write('A1', 10)
21
+ worksheet.write('A2', 20)
22
+ worksheet.write('A3', 30)
23
+ worksheet.write('A4', 40)
24
+
25
+ worksheet.conditional_formatting(
26
+ 'A1',
27
+ {
28
+ :type => 'cell',
29
+ :format => format,
30
+ :criteria => 'greater than',
31
+ :value => 5,
32
+ :stop_if_true => 1
33
+ }
34
+ )
35
+
36
+ workbook.close
37
+ compare_for_regression(
38
+ nil,
39
+ { 'xl/workbook.xml' => ['<workbookView'] }
40
+ )
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionCondFormat15 < 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_cond_format15
14
+ @xlsx = 'cond_format15.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ # We manually set the indices to get the same order as the target file.
19
+ format1 = workbook.add_format(:bg_color => 'red')
20
+ format2 = workbook.add_format(:bg_color => '#92D050')
21
+
22
+ worksheet.write('A1', 10)
23
+ worksheet.write('A2', 20)
24
+ worksheet.write('A3', 30)
25
+ worksheet.write('A4', 40)
26
+
27
+ options1 = {
28
+ :type => 'cell',
29
+ :format => format1,
30
+ :criteria => 'less than',
31
+ :value => 5,
32
+ :stop_if_true => 1
33
+ }
34
+
35
+ worksheet.conditional_formatting('A1', options1)
36
+
37
+ options2 = {
38
+ :type => 'cell',
39
+ :format => format2,
40
+ :criteria => 'greater than',
41
+ :value => 20,
42
+ :stop_if_true => 1
43
+ }
44
+
45
+ worksheet.conditional_formatting('A1', options2)
46
+
47
+ workbook.close
48
+ compare_for_regression(
49
+ nil,
50
+ { 'xl/workbook.xml' => ['<workbookView'] }
51
+ )
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionCondFormat16 < 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_cond_format16
14
+ @xlsx = 'cond_format16.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ # We manually set the indices to get the same order as the target file.
19
+ format1 = workbook.add_format(:bg_color => 'red')
20
+ format2 = workbook.add_format(:bg_color => '#92D050')
21
+
22
+ worksheet.write('A1', 10)
23
+ worksheet.write('A2', 20)
24
+ worksheet.write('A3', 30)
25
+ worksheet.write('A4', 40)
26
+
27
+ options1 = {
28
+ :type => 'cell',
29
+ :format => format1,
30
+ :criteria => 'less than',
31
+ :value => 5,
32
+ :stop_if_true => false
33
+ }
34
+
35
+ worksheet.conditional_formatting('A1', options1)
36
+
37
+ options2 = {
38
+ :type => 'cell',
39
+ :format => format2,
40
+ :criteria => 'greater than',
41
+ :value => 20,
42
+ :stop_if_true => true
43
+ }
44
+
45
+ worksheet.conditional_formatting('A1', options2)
46
+
47
+ workbook.close
48
+ compare_for_regression(
49
+ nil,
50
+ { 'xl/workbook.xml' => ['<workbookView'] }
51
+ )
52
+ end
53
+ end
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionCondFormat17 < 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_cond_format17
14
+ @xlsx = 'cond_format17.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.write('A1', 10)
19
+ worksheet.write('A2', 20)
20
+ worksheet.write('A3', 30)
21
+ worksheet.write('A4', 40)
22
+
23
+ worksheet.conditional_formatting(
24
+ 'A1:A4',
25
+ {
26
+ :type => 'icon_set',
27
+ :icon_style => '3_arrows'
28
+ }
29
+ )
30
+
31
+ workbook.close
32
+ compare_for_regression(
33
+ nil,
34
+ { 'xl/workbook.xml' => ['<workbookView'] }
35
+ )
36
+ end
37
+ end
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionCondFormat18 < 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_cond_format18
14
+ @xlsx = 'cond_format18.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.write('A1', 1)
19
+ worksheet.write('A2', 2)
20
+ worksheet.write('A3', 3)
21
+ worksheet.write('A4', 4)
22
+ worksheet.write('A5', 5)
23
+ worksheet.write('A6', 6)
24
+ worksheet.write('A7', 7)
25
+ worksheet.write('A8', 8)
26
+ worksheet.write('A9', 9)
27
+
28
+ worksheet.write('A12', 75)
29
+
30
+
31
+ worksheet.conditional_formatting(
32
+ 'A1',
33
+ {
34
+ :type => 'icon_set',
35
+ :icon_style => '3_arrows',
36
+ :reverse_icons => 1
37
+ }
38
+ )
39
+
40
+ worksheet.conditional_formatting(
41
+ 'A2',
42
+ {
43
+ :type => 'icon_set',
44
+ :icon_style => '3_flags',
45
+ :icons_only => 1
46
+ }
47
+ )
48
+
49
+ worksheet.conditional_formatting(
50
+ 'A3',
51
+ {
52
+ :type => 'icon_set',
53
+ :icon_style => '3_traffic_lights_rimmed',
54
+ :icons_only => 1,
55
+ :reverse_icons => 1
56
+ }
57
+ )
58
+
59
+ worksheet.conditional_formatting(
60
+ 'A4',
61
+ {
62
+ :type => 'icon_set',
63
+ :icon_style => '3_symbols_circled',
64
+ :icons => [
65
+ {:value => 80},
66
+ {:value => 20}
67
+ ]
68
+ }
69
+ )
70
+
71
+ worksheet.conditional_formatting(
72
+ 'A5',
73
+ {
74
+ :type => 'icon_set',
75
+ :icon_style => '4_arrows',
76
+ :icons => [
77
+ {:criteria => '>'},
78
+ {:criteria => '>'},
79
+ {:criteria => '>'}
80
+ ]
81
+ }
82
+ )
83
+
84
+ worksheet.conditional_formatting(
85
+ 'A6',
86
+ {
87
+ :type => 'icon_set',
88
+ :icon_style => '4_red_to_black',
89
+ :icons => [
90
+ {:criteria => '>=', :type => 'number', :value => 90},
91
+ {:criteria => '<', :type => 'percentile', :value => 50},
92
+ {:criteria => '<=', :type => 'percent', :value => 25}
93
+ ]
94
+ }
95
+ )
96
+
97
+ worksheet.conditional_formatting(
98
+ 'A7',
99
+ {
100
+ :type => 'icon_set',
101
+ :icon_style => '4_traffic_lights',
102
+ :icons => [ {:value => '=$A$12'} ]
103
+ }
104
+ )
105
+
106
+ worksheet.conditional_formatting(
107
+ 'A8',
108
+ {
109
+ :type => 'icon_set',
110
+ :icon_style => '5_arrows_gray',
111
+ :icons => [ {:type => 'formula', :value => '=$A$12'} ]
112
+ }
113
+ )
114
+
115
+ worksheet.conditional_formatting(
116
+ 'A9',
117
+ {
118
+ :type => 'icon_set',
119
+ :icon_style => '5_quarters',
120
+ :icons => [
121
+ {:value => 70},
122
+ {:value => 50},
123
+ {:value => 30},
124
+ {:value => 10}
125
+ ],
126
+ :reverse_icons => 1
127
+ }
128
+ )
129
+
130
+ workbook.close
131
+ compare_for_regression(
132
+ nil,
133
+ { 'xl/workbook.xml' => ['<workbookView'] }
134
+ )
135
+ end
136
+ end