write_xlsx 1.07.0 → 1.08.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Changes +31 -0
  3. data/README.md +1 -1
  4. data/lib/write_xlsx/chart.rb +3 -5
  5. data/lib/write_xlsx/drawing.rb +80 -17
  6. data/lib/write_xlsx/package/app.rb +3 -3
  7. data/lib/write_xlsx/package/conditional_format.rb +2 -8
  8. data/lib/write_xlsx/package/packager.rb +1 -0
  9. data/lib/write_xlsx/package/styles.rb +16 -3
  10. data/lib/write_xlsx/utility.rb +5 -1
  11. data/lib/write_xlsx/version.rb +1 -1
  12. data/lib/write_xlsx/workbook.rb +23 -0
  13. data/lib/write_xlsx/worksheet/data_validation.rb +1 -6
  14. data/lib/write_xlsx/worksheet.rb +71 -20
  15. data/test/drawing/{test_write_ext.rb → test_write_xdr_ext.rb} +2 -2
  16. data/test/regression/test_chart_crossing01.rb +1 -1
  17. data/test/regression/test_chart_crossing05.rb +46 -0
  18. data/test/regression/test_chart_crossing06.rb +46 -0
  19. data/test/regression/test_chart_data_labels48.rb +55 -0
  20. data/test/regression/test_chart_data_labels49.rb +55 -0
  21. data/test/regression/test_chart_data_labels50.rb +57 -0
  22. data/test/regression/test_format16.rb +24 -0
  23. data/test/regression/test_format17.rb +24 -0
  24. data/test/regression/test_image52.rb +26 -0
  25. data/test/regression/test_image53.rb +26 -0
  26. data/test/regression/test_image54.rb +26 -0
  27. data/test/regression/test_image55.rb +27 -0
  28. data/test/regression/test_protect04.rb +32 -0
  29. data/test/regression/test_protect05.rb +35 -0
  30. data/test/regression/test_protect06.rb +35 -0
  31. data/test/regression/test_protect07.rb +23 -0
  32. data/test/regression/xlsx_files/chart_crossing05.xlsx +0 -0
  33. data/test/regression/xlsx_files/chart_crossing06.xlsx +0 -0
  34. data/test/regression/xlsx_files/chart_data_labels48.xlsx +0 -0
  35. data/test/regression/xlsx_files/chart_data_labels49.xlsx +0 -0
  36. data/test/regression/xlsx_files/chart_data_labels50.xlsx +0 -0
  37. data/test/regression/xlsx_files/format16.xlsx +0 -0
  38. data/test/regression/xlsx_files/format17.xlsx +0 -0
  39. data/test/regression/xlsx_files/image52.xlsx +0 -0
  40. data/test/regression/xlsx_files/image53.xlsx +0 -0
  41. data/test/regression/xlsx_files/image54.xlsx +0 -0
  42. data/test/regression/xlsx_files/image55.xlsx +0 -0
  43. data/test/regression/xlsx_files/protect04.xlsx +0 -0
  44. data/test/regression/xlsx_files/protect05.xlsx +0 -0
  45. data/test/regression/xlsx_files/protect06.xlsx +0 -0
  46. data/test/regression/xlsx_files/protect07.xlsx +0 -0
  47. data/test/utility/test_range.rb +20 -0
  48. metadata +70 -8
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartCrossing05 < 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_crossing05
14
+ @xlsx = 'chart_crossing05.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, [55948032, 55950336])
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(:crossing => 'min')
35
+
36
+ worksheet.insert_chart('E9', chart)
37
+
38
+ workbook.close
39
+ compare_for_regression(
40
+ nil,
41
+ {
42
+ 'xl/charts/chart1.xml' => [ '<c:pageMargins' ]
43
+ }
44
+ )
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartCrossing06 < 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_crossing06
14
+ @xlsx = 'chart_crossing06.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, [72794880, 72796416])
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_y_axis(:crossing => 'min')
35
+
36
+ worksheet.insert_chart('E9', chart)
37
+
38
+ workbook.close
39
+ compare_for_regression(
40
+ nil,
41
+ {
42
+ 'xl/charts/chart1.xml' => [ '<c:pageMargins' ]
43
+ }
44
+ )
45
+ end
46
+ end
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartDataLabels48 < 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_labels48
14
+ @xlsx = 'chart_data_labels48.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, [61160832, 61167104])
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
+ :custom => [{:value => 31}]
36
+ }
37
+ )
38
+
39
+ chart.add_series(
40
+ :values => '=Sheet1!$B$1:$B$5',
41
+ :data_labels => {
42
+ :value => 1,
43
+ :position => 'inside_base',
44
+ :custom => [{:value => 32}]
45
+ }
46
+ )
47
+
48
+ chart.add_series(:values => '=Sheet1!$C$1:$C$5')
49
+
50
+ worksheet.insert_chart('E9', chart)
51
+
52
+ workbook.close
53
+ compare_for_regression
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartDataLabels49 < 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_labels49
14
+ @xlsx = 'chart_data_labels49.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, [59202176, 60966784])
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
+ :custom => [{:value => '=Sheet1!$B$1'}]
36
+ }
37
+ )
38
+
39
+ chart.add_series(
40
+ :values => '=Sheet1!$B$1:$B$5',
41
+ :data_labels => {
42
+ :value => 1,
43
+ :position => 'inside_base',
44
+ :custom => [{:value => '=Sheet1!$B$2'}]
45
+ }
46
+ )
47
+
48
+ chart.add_series(:values => '=Sheet1!$C$1:$C$5')
49
+
50
+ worksheet.insert_chart('E9', chart)
51
+
52
+ workbook.close
53
+ compare_for_regression
54
+ end
55
+ end
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionChartDataLabels50 < 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_labels50
14
+ @xlsx = 'chart_data_labels50.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, [84605184, 84639744])
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 => 'center',
35
+ :custom => [
36
+ {
37
+ :font => {
38
+ :bold => 1,
39
+ :italic => 1,
40
+ :color => 'red',
41
+ :baseline => -1
42
+ },
43
+ :border => { :color => 'red' }
44
+ }
45
+ ]
46
+ }
47
+ )
48
+
49
+ chart.add_series(:values => '=Sheet1!$B$1:$B$5')
50
+ chart.add_series(:values => '=Sheet1!$C$1:$C$5')
51
+
52
+ worksheet.insert_chart('E9', chart)
53
+
54
+ workbook.close
55
+ compare_for_regression
56
+ end
57
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionFormat16 < 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_format16
14
+ @xlsx = 'format16.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+ pattern = workbook.add_format(:pattern => 2)
18
+
19
+ worksheet.write('A1', '', pattern)
20
+
21
+ workbook.close
22
+ compare_for_regression
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionFormat17 < 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_format17
14
+ @xlsx = 'format17.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+ pattern = workbook.add_format(:pattern => 2, :fg_color => 'red')
18
+
19
+ worksheet.write('A1', '', pattern)
20
+
21
+ workbook.close
22
+ compare_for_regression
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage52 < 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_image52
14
+ @xlsx = 'image52.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.insert_image(
19
+ 'E9', 'test/regression/images/red.png',
20
+ :description => 'This is some alternative text'
21
+ )
22
+
23
+ workbook.close
24
+ compare_for_regression
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage53 < 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_image53
14
+ @xlsx = 'image53.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.insert_image(
19
+ 'E9', 'test/regression/images/red.png',
20
+ :description => ''
21
+ )
22
+
23
+ workbook.close
24
+ compare_for_regression
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage54 < 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_image54
14
+ @xlsx = 'image54.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.insert_image(
19
+ 'E9', 'test/regression/images/red.png',
20
+ :decorative => 1
21
+ )
22
+
23
+ workbook.close
24
+ compare_for_regression
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage55 < 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_image55
14
+ @xlsx = 'image55.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.insert_image(
19
+ 'E9', 'test/regression/images/red.png',
20
+ :url => 'https://github.com/jmcnamara',
21
+ :decorative => 1
22
+ )
23
+
24
+ workbook.close
25
+ compare_for_regression
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionProtect04 < 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_protect04
14
+ @xlsx = 'protect04.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ unlocked = workbook.add_format(:locked => 0, :hidden => 0)
19
+ hidden = workbook.add_format(:locked => 0, :hidden => 1)
20
+
21
+ worksheet.protect
22
+
23
+ worksheet.unprotect_range('A1')
24
+
25
+ worksheet.write('A1', 1)
26
+ worksheet.write('A2', 2, unlocked)
27
+ worksheet.write('A3', 3, hidden)
28
+
29
+ workbook.close
30
+ compare_for_regression
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionProtect05 < 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_protect05
14
+ @xlsx = 'protect05.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ unlocked = workbook.add_format(:locked => 0, :hidden => 0)
19
+ hidden = workbook.add_format(:locked => 0, :hidden => 1)
20
+
21
+ worksheet.protect
22
+
23
+ worksheet.unprotect_range('A1')
24
+ worksheet.unprotect_range('$C$1:$C$3')
25
+ worksheet.unprotect_range('G4:I6', 'MyRange')
26
+ worksheet.unprotect_range('K7')
27
+
28
+ worksheet.write('A1', 1)
29
+ worksheet.write('A2', 2, unlocked)
30
+ worksheet.write('A3', 3, hidden)
31
+
32
+ workbook.close
33
+ compare_for_regression
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionProtect06 < 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_protect06
14
+ @xlsx = 'protect06.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ unlocked = workbook.add_format(:locked => 0, :hidden => 0)
19
+ hidden = workbook.add_format(:locked => 0, :hidden => 1)
20
+
21
+ worksheet.protect
22
+
23
+ worksheet.unprotect_range('A1', nil, 'password')
24
+ worksheet.unprotect_range('C1:C3')
25
+ worksheet.unprotect_range('G4:I6', 'MyRange')
26
+ worksheet.unprotect_range('K7', nil, 'foobar')
27
+
28
+ worksheet.write('A1', 1)
29
+ worksheet.write('A2', 2, unlocked)
30
+ worksheet.write('A3', 3, hidden)
31
+
32
+ workbook.close
33
+ compare_for_regression
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionProtect07 < 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_protect07
14
+ @xlsx = 'protect07.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ workbook.read_only_recommended
19
+
20
+ workbook.close
21
+ compare_for_regression
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRange < Minitest::Test
5
+ include Writexlsx::Utility
6
+
7
+ def test_range_0_0_1_1
8
+ assert_equal(
9
+ 'B1',
10
+ xl_range(0, 0, 1, 1)
11
+ )
12
+ end
13
+
14
+ def test_range_0_0_1_1_1_1_1_1
15
+ assert_equal(
16
+ '$B$1',
17
+ xl_range(0, 0, 1, 1, 1, 1, 1, 1)
18
+ )
19
+ end
20
+ end