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
@@ -22,7 +22,12 @@ class Writexlsx::Workbook
22
22
  # Set the default index for each format. This is mainly used for testing.
23
23
  #
24
24
  def set_default_xf_indices #:nodoc:
25
- @formats.formats.each { |format| format.get_xf_index }
25
+ # Delete the default url format.
26
+ @formats.formats.delete_at(1)
27
+
28
+ @formats.formats.each do |format|
29
+ format.get_xf_index
30
+ end
26
31
  end
27
32
  end
28
33
 
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionHyperlink31 < Minitest::Test
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true) if @tempfile
11
+ end
12
+
13
+ def test_hyperlink31
14
+ @xlsx = 'hyperlink31.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+ format1 = workbook.add_format(:bold => 1)
18
+
19
+ worksheet.write('A1', 'Test', format1)
20
+ worksheet.write('A3', 'http://www.python.org/')
21
+
22
+ workbook.close
23
+
24
+ compare_for_regression
25
+ end
26
+ end
@@ -25,6 +25,9 @@ def test_chart_bar08
25
25
  [ 3, 6, 9, 12, 15 ]
26
26
  ]
27
27
 
28
+ # Turn off default URL format for testing.
29
+ worksheet.instance_variable_set(:@default_url_format, nil)
30
+
28
31
  worksheet.write('A1', data)
29
32
  worksheet.write('A7', 'http://www.perl.com/')
30
33
 
@@ -24,6 +24,9 @@ def test_chart_bar11
24
24
  [3, 6, 9, 12, 15]
25
25
  ]
26
26
 
27
+ # Turn off default URL format for testing.
28
+ worksheet.instance_variable_set(:@default_url_format, nil)
29
+
27
30
  worksheet.write('A1', data)
28
31
  worksheet.write('A7', 'http://www.perl.com/')
29
32
  worksheet.write('A8', 'http://www.perl.org/')
@@ -32,6 +32,9 @@ def test_chart_bar14
32
32
  [3, 6, 9, 12, 15]
33
33
  ]
34
34
 
35
+ # Turn off default URL format for testing.
36
+ worksheet2.instance_variable_set(:@default_url_format, nil)
37
+
35
38
  worksheet2.write('A1', data)
36
39
  worksheet2.write('A6', 'http://www.perl.com/')
37
40
 
@@ -17,30 +17,29 @@ def test_chart_chartarea05
17
17
  chart = workbook.add_chart(:type => 'pie', :embedded => 1)
18
18
 
19
19
  data = [
20
- [2, 4, 6],
21
- [60, 30, 10]
22
- ]
20
+ [ 2, 4, 6],
21
+ [60, 30, 10]
22
+ ]
23
23
 
24
24
  worksheet.write('A1', data)
25
25
 
26
26
  chart.add_series(
27
- :categories => '=Sheet1!$A$1:$A$3',
28
- :values => '=Sheet1!$B$1:$B$3'
29
- )
27
+ :categories => '=Sheet1!$A$1:$A$3',
28
+ :values => '=Sheet1!$B$1:$B$3'
29
+ )
30
30
 
31
31
  chart.set_chartarea(
32
- :border => {
33
- :color => '#FFFF00',
34
- :dash_type => 'long_dash'
35
- },
36
- :fill => { :color => '#92D050' }
37
- )
38
-
39
- # This should be ignored for a pie chart.
32
+ :border => {
33
+ :color => '#FFFF00',
34
+ :dash_type => 'long_dash'
35
+ },
36
+ :fill => { :color => '#92D050' }
37
+ )
38
+
40
39
  chart.set_plotarea(
41
- :border => { :dash_type => 'dash_dot' },
42
- :fill => { :color => '#FFC000' }
43
- )
40
+ :border => { :dash_type => 'square_dot' },
41
+ :fill => { :color => '#FF0000' }
42
+ )
44
43
 
45
44
  worksheet.insert_chart('E9', chart)
46
45
 
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartChartArea06 < 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_chartarea06
14
+ @xlsx = 'chart_chartarea06.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+ chart = workbook.add_chart(:type => 'doughnut', :embedded => 1)
18
+
19
+ data = [
20
+ [ 2, 4, 6],
21
+ [60, 30, 10]
22
+ ]
23
+
24
+ worksheet.write('A1', data)
25
+
26
+ chart.add_series(
27
+ :categories => '=Sheet1!$A$1:$A$3',
28
+ :values => '=Sheet1!$B$1:$B$3'
29
+ )
30
+
31
+ chart.set_chartarea(
32
+ :border => {
33
+ :color => '#FFFF00',
34
+ :dash_type => 'long_dash'
35
+ },
36
+ :fill => { :color => '#92D050' }
37
+ )
38
+
39
+ chart.set_plotarea(
40
+ :border => { :dash_type => 'square_dot' },
41
+ :fill => { :color => '#FF0000' }
42
+ )
43
+
44
+ worksheet.insert_chart('E9', chart)
45
+
46
+ workbook.close
47
+ compare_for_regression
48
+ end
49
+ end
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartDataLabels25 < 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_data_labels25
14
+ @xlsx = 'chart_data_labels25.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, [108652800, 108656128])
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
+ :values => '=Sheet1!$A$1:$A$5',
32
+ :data_labels => {
33
+ :value => 1,
34
+ :position => 'outside_end',
35
+ :font => {
36
+ :rotation => 45,
37
+ :baseline => -1
38
+ }
39
+ }
40
+ )
41
+
42
+ chart.add_series(
43
+ :values => '=Sheet1!$B$1:$B$5',
44
+ :data_labels => {
45
+ :value => 1,
46
+ :position => 'inside_base',
47
+ :font => {
48
+ :rotation => -45,
49
+ :baseline => -1
50
+ }
51
+ }
52
+ )
53
+
54
+ chart.add_series(:values => '=Sheet1!$C$1:$C$5')
55
+
56
+ worksheet.insert_chart('E9', chart)
57
+
58
+ workbook.close
59
+ compare_for_regression
60
+ end
61
+ end
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartFormat26 < 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_format26
14
+ @xlsx = 'chart_format26.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 => { :type => 'linear', :display_equation => 1 }
34
+ )
35
+
36
+ chart.add_series(
37
+ :categories => '=Sheet1!$A$1:$A$5',
38
+ :values => '=Sheet1!$C$1:$C$5'
39
+ )
40
+
41
+ chart.set_legend(:delete_series => [2, 0])
42
+
43
+ worksheet.insert_chart('E9', chart)
44
+
45
+ workbook.close
46
+ compare_for_regression
47
+ end
48
+ end
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartFormat27 < 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_format27
14
+ @xlsx = 'chart_format27.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, [108645376, 108655360])
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
+ :display_equation => 1,
40
+ :line => {
41
+ :color => 'red',
42
+ :width => 1,
43
+ :dash_type => 'long_dash'
44
+ }
45
+ }
46
+ )
47
+
48
+ chart.add_series(
49
+ :categories => '=Sheet1!$A$1:$A$5',
50
+ :values => '=Sheet1!$C$1:$C$5'
51
+ )
52
+
53
+ worksheet.insert_chart('E9', chart)
54
+
55
+ workbook.close
56
+ compare_for_regression
57
+ end
58
+ end
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartFormat28 < 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_format28
14
+ @xlsx = 'chart_format28.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, [108645376, 108655360])
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
+ :display_equation => 1,
36
+ :display_r_squared => 1
37
+ }
38
+ )
39
+
40
+ chart.add_series(
41
+ :categories => '=Sheet1!$A$1:$A$5',
42
+ :values => '=Sheet1!$C$1:$C$5'
43
+ )
44
+
45
+ chart.set_legend(:delete_series => [0, 2])
46
+
47
+ worksheet.insert_chart('E9', chart)
48
+
49
+ workbook.close
50
+ compare_for_regression
51
+ end
52
+ end
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartFormat29 < 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_format29
14
+ @xlsx = 'chart_format29.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 => 'polynomial',
35
+ :name => 'My trend name',
36
+ :order => 2,
37
+ :forward => 0.5,
38
+ :backward => 0.5,
39
+ :display_equation => 1,
40
+ :display_r_squared => 1,
41
+ :line => {
42
+ :color => 'red',
43
+ :width => 1,
44
+ :dash_type => 'long_dash'
45
+ }
46
+ }
47
+ )
48
+
49
+ chart.add_series(
50
+ :categories => '=Sheet1!$A$1:$A$5',
51
+ :values => '=Sheet1!$C$1:$C$5'
52
+ )
53
+
54
+ worksheet.insert_chart('E9', chart)
55
+
56
+ workbook.close
57
+ compare_for_regression
58
+ end
59
+ end