write_xlsx 0.85.11 → 0.86.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 +17 -0
  3. data/examples/colors.rb +47 -0
  4. data/examples/comments2.rb +1 -1
  5. data/examples/conditional_format.rb +60 -9
  6. data/examples/data_validate.rb +7 -7
  7. data/examples/panes.rb +1 -1
  8. data/examples/tab_colors.rb +1 -1
  9. data/lib/write_xlsx/format.rb +1 -1
  10. data/lib/write_xlsx/package/app.rb +12 -0
  11. data/lib/write_xlsx/package/comments.rb +4 -2
  12. data/lib/write_xlsx/package/conditional_format.rb +6 -0
  13. data/lib/write_xlsx/package/table.rb +17 -5
  14. data/lib/write_xlsx/package/xml_writer_simple.rb +3 -2
  15. data/lib/write_xlsx/version.rb +1 -1
  16. data/lib/write_xlsx/workbook.rb +12 -11
  17. data/lib/write_xlsx/worksheet.rb +20 -4
  18. data/lib/write_xlsx/worksheet/data_validation.rb +22 -10
  19. data/lib/write_xlsx/worksheet/hyperlink.rb +12 -8
  20. data/test/regression/images/red_208.png +0 -0
  21. data/test/regression/test_data_validation08.rb +24 -0
  22. data/test/regression/test_hyperlink22.rb +24 -0
  23. data/test/regression/test_hyperlink23.rb +24 -0
  24. data/test/regression/test_hyperlink24.rb +24 -0
  25. data/test/regression/test_image28.rb +27 -0
  26. data/test/regression/test_image29.rb +27 -0
  27. data/test/regression/test_image30.rb +27 -0
  28. data/test/regression/test_image31.rb +30 -0
  29. data/test/regression/test_image32.rb +28 -0
  30. data/test/regression/test_image33.rb +32 -0
  31. data/test/regression/test_properties02.rb +28 -0
  32. data/test/regression/xlsx_files/data_validation08.xlsx +0 -0
  33. data/test/regression/xlsx_files/hyperlink22.xlsx +0 -0
  34. data/test/regression/xlsx_files/hyperlink23.xlsx +0 -0
  35. data/test/regression/xlsx_files/hyperlink24.xlsx +0 -0
  36. data/test/regression/xlsx_files/image28.xlsx +0 -0
  37. data/test/regression/xlsx_files/image29.xlsx +0 -0
  38. data/test/regression/xlsx_files/image30.xlsx +0 -0
  39. data/test/regression/xlsx_files/image31.xlsx +0 -0
  40. data/test/regression/xlsx_files/image32.xlsx +0 -0
  41. data/test/regression/xlsx_files/image33.xlsx +0 -0
  42. data/test/regression/xlsx_files/properties02.xlsx +0 -0
  43. data/test/regression/xlsx_files/table18.xlsx +0 -0
  44. data/test/regression/xlsx_files/table19.xlsx +0 -0
  45. data/test/worksheet/test_cond_format_21.rb +90 -0
  46. data/test/worksheet/test_sparkline_12.rb +94 -0
  47. data/test/worksheet/test_write_data_validation_02.rb +14 -1
  48. metadata +56 -2
@@ -32,11 +32,17 @@ def initialize(*args)
32
32
  @value = @minimum if @minimum
33
33
 
34
34
  @validate = valid_validation_type[@validate.downcase]
35
- if @validate == 'none'
35
+
36
+ # No action is required for validate type 'any'
37
+ # unless there are input messages.
38
+ if @validate == 'none' && !@input_message && !@input_title
36
39
  @validate_none = true
37
40
  return
38
41
  end
39
- if ['list', 'custom'].include?(@validate)
42
+
43
+ # The any, list and custom validations don't have a criteria
44
+ # so we use a default of 'between'
45
+ if ['none', 'list', 'custom'].include?(@validate)
40
46
  @criteria = 'between'
41
47
  @maximum = nil
42
48
  end
@@ -59,7 +65,7 @@ def initialize(*args)
59
65
  end
60
66
  set_some_defaults
61
67
 
62
- # A (for now) undocumented parameter to pass additional cell ranges.
68
+ # A (for now) undocumented parameter to pass additional cell ranges.
63
69
  @other_cells.each { |cells| @cells << cells } if has_key?(:other_cells)
64
70
  end
65
71
 
@@ -82,11 +88,15 @@ def validate_none?
82
88
  #
83
89
  def write_data_validation(writer) #:nodoc:
84
90
  @writer = writer
85
- @writer.tag_elements('dataValidation', attributes) do
86
- # Write the formula1 element.
87
- write_formula_1(@value)
88
- # Write the formula2 element.
89
- write_formula_2(@maximum) if @maximum
91
+ if @validate == 'none'
92
+ @writer.empty_tag('dataValidation', attributes)
93
+ else
94
+ @writer.tag_elements('dataValidation', attributes) do
95
+ # Write the formula1 element.
96
+ write_formula_1(@value)
97
+ # Write the formula2 element.
98
+ write_formula_2(@maximum) if @maximum
99
+ end
90
100
  end
91
101
  end
92
102
 
@@ -136,8 +146,10 @@ def attributes
136
146
  end
137
147
  end
138
148
 
139
- attributes << ['type', @validate]
140
- attributes << ['operator', @criteria] if @criteria != 'between'
149
+ if @validate != 'none'
150
+ attributes << ['type', @validate]
151
+ attributes << ['operator', @criteria] if @criteria != 'between'
152
+ end
141
153
 
142
154
  if @error_type
143
155
  attributes << ['errorStyle', 'warning'] if @error_type == 1
@@ -26,17 +26,20 @@ def initialize(url, str, tip)
26
26
  # Strip the mailto header.
27
27
  normalized_str = str.sub(/^mailto:/, '')
28
28
 
29
+ # Split url into the link and optional anchor/location.
30
+ url, @url_str = url.split(/#/)
31
+ url ||= ''
32
+
29
33
  # Escape URL unless it looks already escaped.
30
34
  url = escape_url(url)
31
35
 
32
- # Excel limits escaped URL to 255 characters.
33
- if url.bytesize > 255
34
- raise "URL '#{url}' > 255 characters, it exceeds Excel's limit for URLS."
36
+ # Excel limits the escaped URL and location/anchor to 255 characters.
37
+ if url.bytesize > 255 || (!@url_str.nil? && @url_str.bytesize > 255)
38
+ raise "Ignoring URL '#{url}' where link or anchor > 255 characters since it exceeds Excel's limit for URLS. See LIMITATIONS section of the Excel::Writer::XLSX documentation."
35
39
  end
36
40
 
37
41
  @url = url
38
42
  @str = normalized_str
39
- @url_str = nil
40
43
  @tip = tip
41
44
  end
42
45
 
@@ -144,14 +147,15 @@ def initialize(url, str, tip)
144
147
 
145
148
  # Convert a ./dir/file.xlsx link to dir/file.xlsx.
146
149
  url = url.sub(%r!^.\\!, '')
150
+ @url_str = url_str
147
151
 
148
- # Excel limits escaped URL to 255 characters.
149
- if url.bytesize > 255
150
- raise "URL '#{url}' > 255 characters, it exceeds Excel's limit for URLS."
152
+ # Excel limits the escaped URL and location/anchor to 255 characters.
153
+ if url.bytesize > 255 || (!@url_str.nil? && @url_str.bytesize > 255)
154
+ raise "Ignoring URL '#{url}' where link or anchor > 255 characters since it exceeds Excel's limit for URLS. See LIMITATIONS section of the Excel::Writer::XLSX documentation."
151
155
  end
156
+
152
157
  @url = url
153
158
  @str = str
154
- @url_str = url_str
155
159
  @tip = tip
156
160
  end
157
161
  end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestDataValidation08 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def test_data_validation08
10
+ @xlsx = 'data_validation08.xlsx'
11
+ workbook = WriteXLSX.new(@io)
12
+ worksheet = workbook.add_worksheet
13
+
14
+ worksheet.data_validation(
15
+ 'C2',
16
+ validate: 'any',
17
+ input_title: 'This is the input title',
18
+ input_message: 'This is the input message'
19
+ )
20
+ workbook.close
21
+
22
+ compare_for_regression
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionHyperlink22 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_hyperlink22
14
+ @xlsx = 'hyperlink22.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.write_url('A1', 'external:\\\\Vboxsvr\share\foo bar.xlsx')
19
+
20
+ workbook.close
21
+
22
+ compare_for_regression
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionHyperlink23 < Test::Unit::TestCase
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_hyperlink23
14
+ @xlsx = 'hyperlink23.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.write_url('A1', 'https://en.wikipedia.org/wiki/Microsoft_Excel#Data_storage_and_communication', 'Display text')
19
+
20
+ workbook.close
21
+
22
+ compare_for_regression
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionHyperlink24 < Test::Unit::TestCase
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_hyperlink24
14
+ @xlsx = 'hyperlink24.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.write_url('A1', 'http://www.example.com/some_long_url_that_is_255_characters_long_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_z#some_long_location_that_is_255_characters_long_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_abcdefgh_z')
19
+
20
+ workbook.close
21
+
22
+ compare_for_regression
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage28 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_image28
14
+ @xlsx = 'image28.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.insert_image(
19
+ 0, 6,
20
+ File.join(@test_dir, 'regression', 'images/red_208.png'),
21
+ 46, 1
22
+ )
23
+
24
+ workbook.close
25
+ compare_for_regression
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage29 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_image29
14
+ @xlsx = 'image29.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.insert_image(
19
+ 0, 10,
20
+ File.join(@test_dir, 'regression', 'images/red_208.png'),
21
+ -210, 1
22
+ )
23
+
24
+ workbook.close
25
+ compare_for_regression
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage30 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_image30
14
+ @xlsx = 'image30.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.insert_image(
19
+ 'E9',
20
+ File.join(@test_dir, 'regression', 'images/red.png'),
21
+ -2, -1
22
+ )
23
+
24
+ workbook.close
25
+ compare_for_regression
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage31 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_image31
14
+ @xlsx = 'image31.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.set_column('D:D', 3.86)
19
+ worksheet.set_row(7, 7.5)
20
+
21
+ worksheet.insert_image(
22
+ 'E9',
23
+ File.join(@test_dir, 'regression', 'images/red.png'),
24
+ -2, -1
25
+ )
26
+
27
+ workbook.close
28
+ compare_for_regression
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage32 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_image32
14
+ @xlsx = 'image32.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ # Negative offset should be ignored.
19
+ worksheet.insert_image(
20
+ 'B1',
21
+ File.join(@test_dir, 'regression', 'images/red.png'),
22
+ -100, -100
23
+ )
24
+
25
+ workbook.close
26
+ compare_for_regression
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionImage33 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_image33
14
+ @xlsx = 'image33.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.set_column('D:D', 3.86)
19
+ worksheet.set_column('E:E', 1.43)
20
+ worksheet.set_row(7, 7.5)
21
+ worksheet.set_row(8, 9.75)
22
+
23
+ worksheet.insert_image(
24
+ 'E9',
25
+ File.join(@test_dir, 'regression', 'images/red.png'),
26
+ -2, -1
27
+ )
28
+
29
+ workbook.close
30
+ compare_for_regression
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestRegressionProperties02 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_properties02
14
+ @xlsx = 'properties02.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ workbook.set_properties(
19
+ :hyperlink_base => 'C:\\'
20
+ )
21
+
22
+ workbook.close
23
+ compare_for_regression(
24
+ nil,
25
+ { 'xl/workbook.xml' => ['<workbookView'] }
26
+ )
27
+ end
28
+ end