roo 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ module Roo
2
2
  module Tempdir
3
3
  def finalize_tempdirs(object_id)
4
4
  if @tempdirs && (dirs_to_remove = @tempdirs[object_id])
5
- @tempdirs[object_id] = nil
5
+ @tempdirs.delete(object_id)
6
6
  dirs_to_remove.each do |dir|
7
7
  ::FileUtils.remove_entry(dir)
8
8
  end
@@ -10,16 +10,11 @@ module Roo
10
10
  end
11
11
 
12
12
  def make_tempdir(object, prefix, root)
13
- root ||= ENV['ROO_TMP']
14
- # folder is cleaned up in .finalize_tempdirs
13
+ root ||= ENV["ROO_TMP"]
14
+ # NOTE: This folder is cleaned up by finalize_tempdirs.
15
15
  ::Dir.mktmpdir("#{Roo::TEMP_PREFIX}#{prefix}", root).tap do |tmpdir|
16
- @tempdirs ||= {}
17
- if @tempdirs[object.object_id]
18
- @tempdirs[object.object_id] << tmpdir
19
- else
20
- @tempdirs[object.object_id] = [tmpdir]
21
- ObjectSpace.define_finalizer(object, method(:finalize_tempdirs))
22
- end
16
+ @tempdirs ||= Hash.new { |h, k| h[k] = [] }
17
+ @tempdirs[object.object_id] << tmpdir
23
18
  end
24
19
  end
25
20
  end
@@ -1,3 +1,3 @@
1
1
  module Roo
2
- VERSION = "2.6.0"
2
+ VERSION = "2.7.0"
3
3
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency 'rake', '~> 10.1'
24
24
  spec.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.3'
25
+ spec.add_development_dependency 'rack', '~> 1.6', '< 2.0.0'
25
26
  end
@@ -1,13 +1,9 @@
1
1
  require 'simplecov'
2
2
  require 'roo'
3
- require 'vcr'
4
3
  require 'helpers'
5
4
 
6
5
  RSpec.configure do |c|
7
6
  c.include Helpers
8
- end
9
-
10
- VCR.configure do |c|
11
- c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
12
- c.hook_into :webmock # or :fakeweb
7
+ c.color = true
8
+ c.formatter = :documentation
13
9
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestRooExcelxCellTime < Minitest::Test
4
- def time
4
+ def roo_time
5
5
  Roo::Excelx::Cell::Time
6
6
  end
7
7
 
@@ -18,13 +18,13 @@ class TestRooExcelxCellTime < Minitest::Test
18
18
  ['[h]:mm:ss', '[1]:48:09'],
19
19
  ['mmss.0', '4809.0'] # Cell::Time always get rounded to the nearest second.
20
20
  ].each do |style_format, result|
21
- cell = time.new(value, nil, [:numeric_or_formula, style_format], 6, nil, base_date, nil)
21
+ cell = roo_time.new(value, nil, [:numeric_or_formula, style_format], 6, nil, base_date, nil)
22
22
  assert_equal result, cell.formatted_value, "Style=#{style_format} is not properly formatted"
23
23
  end
24
24
  end
25
25
 
26
26
  def test_value
27
- cell = time.new('0.0751', nil, [:numeric_or_formula, 'h:mm'], 6, nil, base_date, nil)
27
+ cell = roo_time.new('0.0751', nil, [:numeric_or_formula, 'h:mm'], 6, nil, base_date, nil)
28
28
  assert_kind_of Integer, cell.value
29
29
  end
30
30
  end
@@ -0,0 +1,119 @@
1
+ require "test_helper"
2
+
3
+ class TestRooFormatterCSV < Minitest::Test
4
+ def test_date_time_to_csv
5
+ with_each_spreadsheet(name: "time-test") do |workbook|
6
+ Dir.mktmpdir do |tempdir|
7
+ csv_output = File.join(tempdir, "time_test.csv")
8
+ assert workbook.to_csv(csv_output)
9
+ assert File.exist?(csv_output)
10
+ assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/time-test.csv #{csv_output}`
11
+ # --strip-trailing-cr is needed because the test-file use 0A and
12
+ # the test on an windows box generates 0D 0A as line endings
13
+ end
14
+ end
15
+ end
16
+
17
+ def test_boolean_to_csv
18
+ with_each_spreadsheet(name: "boolean") do |workbook|
19
+ Dir.mktmpdir do |tempdir|
20
+ csv_output = File.join(tempdir,"boolean.csv")
21
+ assert workbook.to_csv(csv_output)
22
+ assert File.exist?(csv_output)
23
+ assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/boolean.csv #{csv_output}`
24
+ # --strip-trailing-cr is needed because the test-file use 0A and
25
+ # the test on an windows box generates 0D 0A as line endings
26
+ end
27
+ end
28
+ end
29
+
30
+ def test_link_to_csv
31
+ with_each_spreadsheet(name: "link", format: :excelx) do |workbook|
32
+ Dir.mktmpdir do |tempdir|
33
+ csv_output = File.join(tempdir, "link.csv")
34
+ assert workbook.to_csv(csv_output)
35
+ assert File.exist?(csv_output)
36
+ assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/link.csv #{csv_output}`
37
+ # --strip-trailing-cr is needed because the test-file use 0A and
38
+ # the test on an windows box generates 0D 0A as line endings
39
+ end
40
+ end
41
+ end
42
+
43
+ # "/tmp/xxxx" darf man unter Windows nicht verwenden, weil das nicht erkannt
44
+ # wird.
45
+ # Besser: Methode um temporaeres Dir. portabel zu bestimmen
46
+ def test_huge_document_to_csv
47
+ skip unless ENV["LONG_RUN"]
48
+
49
+ original_csv_path = File.join(TESTDIR, "Bibelbund.csv")
50
+ with_each_spreadsheet(name: "Bibelbund", format: [:openoffice, :excelx]) do |workbook|
51
+ Dir.mktmpdir do |tempdir|
52
+ new_csv_path = File.join(tempdir, "Bibelbund.csv")
53
+ assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", workbook.cell(45, "A")
54
+ assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", workbook.cell(46, "A")
55
+ assert_equal "Tagebuch aus Chile Juli 1977", workbook.cell(55, "A")
56
+ assert workbook.to_csv(new_csv_path)
57
+ assert File.exist?(new_csv_path)
58
+ assert FileUtils.identical?(original_csv_path, new_csv_path), "error in class #{workbook.class}"
59
+ end
60
+ end
61
+ end
62
+
63
+ def test_bug_empty_sheet
64
+ with_each_spreadsheet(name: "formula", format: [:openoffice, :excelx]) do |workbook|
65
+ workbook.default_sheet = "Sheet3" # is an empty sheet
66
+ Dir.mktmpdir do |tempdir|
67
+ workbook.to_csv(File.join(tempdir, "emptysheet.csv"))
68
+ assert_equal "", `cat #{File.join(tempdir, "emptysheet.csv")}`
69
+ end
70
+ end
71
+ end
72
+
73
+ def test_bug_quotes_excelx
74
+ skip unless ENV["LONG_RUN"]
75
+ # TODO: run this test with a much smaller document
76
+ with_each_spreadsheet(name: "Bibelbund", format: [:openoffice, :excelx]) do |workbook|
77
+ workbook.default_sheet = workbook.sheets.first
78
+ assert_equal(
79
+ 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
80
+ workbook.cell("A", 76)
81
+ )
82
+ workbook.to_csv("csv#{$$}")
83
+ assert_equal(
84
+ 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
85
+ workbook.cell("A", 78)
86
+ )
87
+ File.delete_if_exist("csv#{$$}")
88
+ end
89
+ end
90
+
91
+ def test_bug_datetime_to_csv
92
+ with_each_spreadsheet(name: "datetime") do |workbook|
93
+ Dir.mktmpdir do |tempdir|
94
+ datetime_csv_file = File.join(tempdir, "datetime.csv")
95
+
96
+ assert workbook.to_csv(datetime_csv_file)
97
+ assert File.exist?(datetime_csv_file)
98
+ assert_equal "", file_diff("#{TESTDIR}/so_datetime.csv", datetime_csv_file)
99
+ end
100
+ end
101
+ end
102
+
103
+ def test_true_class
104
+ assert_equal "true", cell_to_csv(1, 1)
105
+ end
106
+
107
+ def test_false_class
108
+ assert_equal "false", cell_to_csv(2, 1)
109
+ end
110
+
111
+ def test_date_class
112
+ assert_equal "2017-01-01", cell_to_csv(3, 1)
113
+ end
114
+
115
+ def cell_to_csv(row, col)
116
+ filename = File.join(TESTDIR, "formula_cell_types.xlsx")
117
+ Roo::Spreadsheet.open(filename).send("cell_to_csv", row, col, "Sheet1")
118
+ end
119
+ end
@@ -0,0 +1,76 @@
1
+ require "test_helper"
2
+ require "matrix"
3
+
4
+ class TestRooFormatterMatrix < Minitest::Test
5
+ def test_matrix
6
+ expected_result = Matrix[
7
+ [1.0, 2.0, 3.0],
8
+ [4.0, 5.0, 6.0],
9
+ [7.0, 8.0, 9.0]
10
+ ]
11
+ with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
12
+ workbook.default_sheet = workbook.sheets.first
13
+ assert_equal expected_result, workbook.to_matrix
14
+ end
15
+ end
16
+
17
+ def test_matrix_selected_range
18
+ expected_result = Matrix[
19
+ [1.0, 2.0, 3.0],
20
+ [4.0, 5.0, 6.0],
21
+ [7.0, 8.0, 9.0]
22
+ ]
23
+ with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
24
+ workbook.default_sheet = "Sheet2"
25
+ assert_equal expected_result, workbook.to_matrix(3, 4, 5, 6)
26
+ end
27
+ end
28
+
29
+ def test_matrix_all_nil
30
+ expected_result = Matrix[
31
+ [nil, nil, nil],
32
+ [nil, nil, nil],
33
+ [nil, nil, nil]
34
+ ]
35
+ with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
36
+ workbook.default_sheet = "Sheet2"
37
+ assert_equal expected_result, workbook.to_matrix(10, 10, 12, 12)
38
+ end
39
+ end
40
+
41
+ def test_matrix_values_and_nil
42
+ expected_result = Matrix[
43
+ [1.0, nil, 3.0],
44
+ [4.0, 5.0, 6.0],
45
+ [7.0, 8.0, nil]
46
+ ]
47
+ with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
48
+ workbook.default_sheet = "Sheet3"
49
+ assert_equal expected_result, workbook.to_matrix(1, 1, 3, 3)
50
+ end
51
+ end
52
+
53
+ def test_matrix_specifying_sheet
54
+ expected_result = Matrix[
55
+ [1.0, nil, 3.0],
56
+ [4.0, 5.0, 6.0],
57
+ [7.0, 8.0, nil]
58
+ ]
59
+ with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
60
+ workbook.default_sheet = workbook.sheets.first
61
+ assert_equal expected_result, workbook.to_matrix(nil, nil, nil, nil, "Sheet3")
62
+ end
63
+ end
64
+
65
+ # #to_matrix of an empty sheet should return an empty matrix and not result in
66
+ # an error message
67
+ # 2011-06-25
68
+ def test_bug_to_matrix_empty_sheet
69
+ options = { name: "emptysheets", format: [:openoffice, :excelx] }
70
+ with_each_spreadsheet(options) do |workbook|
71
+ workbook.default_sheet = workbook.sheets.first
72
+ workbook.to_matrix
73
+ assert_equal(Matrix.empty(0, 0), workbook.to_matrix)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,74 @@
1
+ require "test_helper"
2
+
3
+ class TestRooFormatterXML < Minitest::Test
4
+ def test_to_xml
5
+ expected_sheet_count = 5
6
+ with_each_spreadsheet(name: "numbers1", encoding: "utf8") do |workbook|
7
+ skip if defined? JRUBY_VERSION
8
+ workbook.to_xml
9
+ sheetname = workbook.sheets.first
10
+ doc = Nokogiri::XML(workbook.to_xml)
11
+ all_cells = init_all_cells(workbook, sheetname)
12
+
13
+ assert_equal expected_sheet_count, doc.xpath("//spreadsheet/sheet").count
14
+
15
+ doc.xpath("//spreadsheet/sheet").each do |xml_sheet|
16
+ assert_equal sheetname, xml_sheet.attributes["name"].value
17
+ xml_sheet.children.each_with_index do |cell, i|
18
+ next unless cell.attributes["name"]
19
+
20
+ expected = [
21
+ all_cells[i][:row],
22
+ all_cells[i][:column],
23
+ all_cells[i][:content],
24
+ all_cells[i][:type],
25
+ ]
26
+ result = [
27
+ cell.attributes["row"],
28
+ cell.attributes["column"],
29
+ cell.content,
30
+ cell.attributes["type"],
31
+ ]
32
+ assert_equal expected, result
33
+ end # end of sheet
34
+ sheetname = workbook.sheets[workbook.sheets.index(sheetname) + 1]
35
+ end
36
+ end
37
+ end
38
+
39
+ def test_bug_to_xml_with_empty_sheets
40
+ with_each_spreadsheet(name: "emptysheets", format: [:openoffice, :excelx]) do |workbook|
41
+ workbook.sheets.each do |sheet|
42
+ assert_nil workbook.first_row, "first_row not nil in sheet #{sheet}"
43
+ assert_nil workbook.last_row, "last_row not nil in sheet #{sheet}"
44
+ assert_nil workbook.first_column, "first_column not nil in sheet #{sheet}"
45
+ assert_nil workbook.last_column, "last_column not nil in sheet #{sheet}"
46
+ assert_nil workbook.first_row(sheet), "first_row not nil in sheet #{sheet}"
47
+ assert_nil workbook.last_row(sheet), "last_row not nil in sheet #{sheet}"
48
+ assert_nil workbook.first_column(sheet), "first_column not nil in sheet #{sheet}"
49
+ assert_nil workbook.last_column(sheet), "last_column not nil in sheet #{sheet}"
50
+ end
51
+ workbook.to_xml
52
+ end
53
+ end
54
+
55
+ # Erstellt eine Liste aller Zellen im Spreadsheet. Dies ist nötig, weil ein einfacher
56
+ # Textvergleich des XML-Outputs nicht funktioniert, da xml-builder die Attribute
57
+ # nicht immer in der gleichen Reihenfolge erzeugt.
58
+ def init_all_cells(workbook, sheet)
59
+ all = []
60
+ workbook.first_row(sheet).upto(workbook.last_row(sheet)) do |row|
61
+ workbook.first_column(sheet).upto(workbook.last_column(sheet)) do |col|
62
+ next if workbook.empty?(row, col, sheet)
63
+
64
+ all << {
65
+ row: row.to_s,
66
+ column: col.to_s,
67
+ content: workbook.cell(row, col, sheet).to_s,
68
+ type: workbook.celltype(row, col, sheet).to_s,
69
+ }
70
+ end
71
+ end
72
+ all
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+ require "test_helper"
2
+
3
+ class TestRooFormatterYAML < Minitest::Test
4
+ def test_date_time_yaml
5
+ name = "time-test"
6
+ expected = File.open(TESTDIR + "/expected_results/#{name}.yml").read
7
+ with_each_spreadsheet(name: name) do |workbook|
8
+ assert_equal expected, workbook.to_yaml
9
+ end
10
+ end
11
+
12
+ def test_bug_to_yaml_empty_sheet
13
+ formats = [:openoffice, :excelx]
14
+ with_each_spreadsheet(name: "emptysheets", format: formats) do |workbook|
15
+ workbook.default_sheet = workbook.sheets.first
16
+ workbook.to_yaml
17
+ assert_equal "", workbook.to_yaml
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class TestRooCSV < Minitest::Test
4
+ def test_sheets
5
+ file = filename("numbers1")
6
+ workbook = roo_class.new(File.join(TESTDIR, file))
7
+ assert_equal ["default"], workbook.sheets
8
+ assert_raises(RangeError) { workbook.default_sheet = "no_sheet" }
9
+ assert_raises(TypeError) { workbook.default_sheet = [1, 2, 3] }
10
+ workbook.sheets.each do |sh|
11
+ workbook.default_sheet = sh
12
+ assert_equal sh, workbook.default_sheet
13
+ end
14
+ end
15
+
16
+ def test_nil_rows_and_lines_csv
17
+ # x_123
18
+ oo = Roo::CSV.new(File.join(TESTDIR,'Bibelbund.csv'))
19
+ oo.default_sheet = oo.sheets.first
20
+ assert_equal 1, oo.first_row
21
+ assert_equal 3735, oo.last_row
22
+ assert_equal 1, oo.first_column
23
+ assert_equal 8, oo.last_column
24
+ end
25
+
26
+ def test_empty_csv
27
+ # x_123
28
+ oo = Roo::CSV.new(File.join(TESTDIR,'emptysheets.csv'))
29
+ oo.default_sheet = oo.sheets.first
30
+ assert_equal 1, oo.first_row
31
+ assert_equal 1, oo.last_row
32
+ assert_equal 1, oo.first_column
33
+ assert_equal 1, oo.last_column
34
+ end
35
+
36
+ def test_csv_parsing_with_headers
37
+ return unless CSV
38
+ headers = ["TITEL", "VERFASSER", "OBJEKT", "NUMMER", "SEITE", "INTERNET", "PC", "KENNUNG"]
39
+
40
+ oo = Roo::Spreadsheet.open(File.join(TESTDIR, "Bibelbund.csv"))
41
+ parsed = oo.parse(headers: true)
42
+ assert_equal headers, parsed[1].keys
43
+ end
44
+
45
+ def roo_class
46
+ Roo::CSV
47
+ end
48
+
49
+ def filename(name)
50
+ "#{name}.csv"
51
+ end
52
+ end
@@ -0,0 +1,186 @@
1
+ require "test_helper"
2
+
3
+ class TestRooExcelx < Minitest::Test
4
+ def test_download_uri_with_invalid_host
5
+ assert_raises(RuntimeError) do
6
+ Roo::Excelx.new("http://example.com/file.xlsx")
7
+ end
8
+ end
9
+
10
+ def test_download_uri_with_query_string
11
+ file = filename("simple_spreadsheet")
12
+ port = 12_344
13
+ url = "#{local_server(port)}/#{file}?query-param=value"
14
+
15
+ start_local_server(file, port) do
16
+ spreadsheet = roo_class.new(url)
17
+ assert_equal "Task 1", spreadsheet.cell("f", 4)
18
+ end
19
+ end
20
+
21
+ def test_should_raise_file_not_found_error
22
+ assert_raises(IOError) do
23
+ Roo::Excelx.new(File.join("testnichtvorhanden", "Bibelbund.xlsx"))
24
+ end
25
+ end
26
+
27
+ def test_file_warning_default
28
+ assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR, "numbers1.ods")) }
29
+ assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR, "numbers1.xls")) }
30
+ end
31
+
32
+ def test_file_warning_error
33
+ %w(ods xls).each do |extension|
34
+ assert_raises(TypeError) do
35
+ options = { packed: false, file_warning: :error }
36
+ Roo::Excelx.new(File.join(TESTDIR, "numbers1. #{extension}"), options)
37
+ end
38
+ end
39
+ end
40
+
41
+ def test_file_warning_warning
42
+ options = { packed: false, file_warning: :warning }
43
+ assert_raises(ArgumentError) do
44
+ Roo::Excelx.new(File.join(TESTDIR, "numbers1.ods"), options)
45
+ end
46
+ end
47
+
48
+ def test_file_warning_ignore
49
+ options = { packed: false, file_warning: :ignore }
50
+ sheet = Roo::Excelx.new(File.join(TESTDIR, "type_excelx.ods"), options)
51
+ assert sheet, "Should not throw an error"
52
+ end
53
+
54
+ def test_bug_xlsx_reference_cell
55
+ # NOTE: If cell A contains a string and cell B references cell A. When
56
+ # reading the value of cell B, the result will be "0.0" instead of the
57
+ # value of cell A.
58
+ #
59
+ # Before this test case, the following code:
60
+ #
61
+ # spreadsheet = Roo::Excelx.new("formula_string_error.xlsx")
62
+ # spreadsheet.default_sheet = "sheet1"
63
+ # p "A: #{spreadsheet.cell(1, 1)}" #=> "A: TestString"
64
+ # p "B: #{spreadsheet.cell(2, 1)}" #=> "B: 0.0"
65
+ #
66
+ # where the expected result is
67
+ # "A: TestString"
68
+ # "B: TestString"
69
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "formula_string_error.xlsx"))
70
+ assert_equal "Teststring", xlsx.cell("a", 1)
71
+ assert_equal "Teststring", xlsx.cell("a", 2)
72
+ end
73
+
74
+ def test_parsing_xslx_from_numbers
75
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "numbers-export.xlsx"))
76
+
77
+ xlsx.default_sheet = xlsx.sheets.first
78
+ assert_equal "Sheet 1", xlsx.cell("a", 1)
79
+
80
+ # Another buggy behavior of Numbers 3.1: if a warkbook has more than a
81
+ # single sheet, all sheets except the first one will have an extra row and
82
+ # column added to the beginning. That's why we assert against cell B2 and
83
+ # not A1
84
+ xlsx.default_sheet = xlsx.sheets.last
85
+ assert_equal "Sheet 2", xlsx.cell("b", 2)
86
+ end
87
+
88
+ def assert_cell_range_values(sheet, row_range, column_range, is_merged_range, expected_value)
89
+ row_range.each do |row|
90
+ column_range.each do |col|
91
+ value = sheet.cell(col, row)
92
+ if is_merged_range.call(row, col)
93
+ assert_equal expected_value, value
94
+ else
95
+ assert_nil value
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ def test_expand_merged_range
102
+ options = { expand_merged_ranges: true }
103
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"), options)
104
+
105
+ [
106
+ {
107
+ rows: (3..7),
108
+ columns: ("a".."b"),
109
+ conditional: ->(row, col) { row > 3 && row < 7 && col == "a" },
110
+ expected_value: "vertical1"
111
+ },
112
+ {
113
+ rows: (3..11),
114
+ columns: ("f".."h"),
115
+ conditional: ->(row, col) { row > 3 && row < 11 && col == "g" },
116
+ expected_value: "vertical2"
117
+ },
118
+ {
119
+ rows: (3..5),
120
+ columns: ("b".."f"),
121
+ conditional: ->(row, col) { row == 4 && col > "b" && col < "f" },
122
+ expected_value: "horizontal"
123
+ },
124
+ {
125
+ rows: (8..13),
126
+ columns: ("a".."e"),
127
+ conditional: ->(row, col) { row > 8 && row < 13 && col > "a" && col < "e" },
128
+ expected_value: "block"
129
+ }
130
+ ].each do |data|
131
+ rows, cols, conditional, expected_value = data.values
132
+ assert_cell_range_values(xlsx, rows, cols, conditional, expected_value)
133
+ end
134
+ end
135
+
136
+ def test_noexpand_merged_range
137
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"))
138
+
139
+ [
140
+ {
141
+ rows: (3..7),
142
+ columns: ("a".."b"),
143
+ conditional: ->(row, col) { row == 4 && col == "a" },
144
+ expected_value: "vertical1"
145
+ },
146
+ {
147
+ rows: (3..11),
148
+ columns: ("f".."h"),
149
+ conditional: ->(row, col) { row == 4 && col == "g" },
150
+ expected_value: "vertical2"
151
+ },
152
+ {
153
+ rows: (3..5),
154
+ columns: ("b".."f"),
155
+ conditional: ->(row, col) { row == 4 && col == "c" },
156
+ expected_value: "horizontal"
157
+ },
158
+ {
159
+ rows: (8..13),
160
+ columns: ("a".."e"),
161
+ conditional: ->(row, col) { row == 9 && col == "b" },
162
+ expected_value: "block"
163
+ }
164
+ ].each do |data|
165
+ rows, cols, conditional, expected_value = data.values
166
+ assert_cell_range_values(xlsx, rows, cols, conditional, expected_value)
167
+ end
168
+ end
169
+
170
+ def test_open_stream
171
+ file = filename(:numbers1)
172
+ file_contents = File.read File.join(TESTDIR, file), encoding: "BINARY"
173
+ stream = StringIO.new(file_contents)
174
+ xlsx = Roo::Excelx.new(stream)
175
+ expected_sheet_names = ["Tabelle1", "Name of Sheet 2", "Sheet3", "Sheet4", "Sheet5"]
176
+ assert_equal expected_sheet_names, xlsx.sheets
177
+ end
178
+
179
+ def roo_class
180
+ Roo::Excelx
181
+ end
182
+
183
+ def filename(name)
184
+ "#{name}.xlsx"
185
+ end
186
+ end