roo 1.13.2 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.github/ISSUE_TEMPLATE +10 -0
- data/.gitignore +11 -0
- data/.simplecov +4 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +626 -0
- data/Gemfile +17 -12
- data/Gemfile_ruby2 +30 -0
- data/Guardfile +23 -0
- data/LICENSE +3 -1
- data/README.md +285 -0
- data/Rakefile +23 -23
- data/examples/roo_soap_client.rb +28 -31
- data/examples/roo_soap_server.rb +4 -6
- data/examples/write_me.rb +9 -10
- data/lib/roo/base.rb +298 -495
- data/lib/roo/constants.rb +5 -0
- data/lib/roo/csv.rb +127 -113
- data/lib/roo/errors.rb +11 -0
- data/lib/roo/excelx/cell/base.rb +94 -0
- data/lib/roo/excelx/cell/boolean.rb +27 -0
- data/lib/roo/excelx/cell/date.rb +28 -0
- data/lib/roo/excelx/cell/datetime.rb +111 -0
- data/lib/roo/excelx/cell/empty.rb +19 -0
- data/lib/roo/excelx/cell/number.rb +87 -0
- data/lib/roo/excelx/cell/string.rb +19 -0
- data/lib/roo/excelx/cell/time.rb +43 -0
- data/lib/roo/excelx/cell.rb +106 -0
- data/lib/roo/excelx/comments.rb +55 -0
- data/lib/roo/excelx/coordinate.rb +12 -0
- data/lib/roo/excelx/extractor.rb +21 -0
- data/lib/roo/excelx/format.rb +64 -0
- data/lib/roo/excelx/relationships.rb +25 -0
- data/lib/roo/excelx/shared.rb +32 -0
- data/lib/roo/excelx/shared_strings.rb +157 -0
- data/lib/roo/excelx/sheet.rb +112 -0
- data/lib/roo/excelx/sheet_doc.rb +211 -0
- data/lib/roo/excelx/styles.rb +64 -0
- data/lib/roo/excelx/workbook.rb +59 -0
- data/lib/roo/excelx.rb +376 -602
- data/lib/roo/font.rb +17 -0
- data/lib/roo/formatters/base.rb +15 -0
- data/lib/roo/formatters/csv.rb +84 -0
- data/lib/roo/formatters/matrix.rb +23 -0
- data/lib/roo/formatters/xml.rb +31 -0
- data/lib/roo/formatters/yaml.rb +40 -0
- data/lib/roo/libre_office.rb +4 -0
- data/lib/roo/link.rb +34 -0
- data/lib/roo/open_office.rb +626 -0
- data/lib/roo/spreadsheet.rb +22 -23
- data/lib/roo/tempdir.rb +21 -0
- data/lib/roo/utils.rb +78 -0
- data/lib/roo/version.rb +3 -0
- data/lib/roo.rb +23 -24
- data/roo.gemspec +21 -204
- data/spec/helpers.rb +5 -0
- data/spec/lib/roo/base_spec.rb +229 -3
- data/spec/lib/roo/csv_spec.rb +38 -11
- data/spec/lib/roo/excelx/format_spec.rb +7 -6
- data/spec/lib/roo/excelx_spec.rb +510 -11
- data/spec/lib/roo/libreoffice_spec.rb +16 -6
- data/spec/lib/roo/openoffice_spec.rb +30 -8
- data/spec/lib/roo/spreadsheet_spec.rb +60 -12
- data/spec/lib/roo/utils_spec.rb +106 -0
- data/spec/spec_helper.rb +7 -6
- data/test/all_ss.rb +12 -11
- data/test/excelx/cell/test_base.rb +63 -0
- data/test/excelx/cell/test_boolean.rb +36 -0
- data/test/excelx/cell/test_date.rb +38 -0
- data/test/excelx/cell/test_datetime.rb +45 -0
- data/test/excelx/cell/test_empty.rb +7 -0
- data/test/excelx/cell/test_number.rb +74 -0
- data/test/excelx/cell/test_string.rb +28 -0
- data/test/excelx/cell/test_time.rb +30 -0
- data/test/formatters/test_csv.rb +119 -0
- data/test/formatters/test_matrix.rb +76 -0
- data/test/formatters/test_xml.rb +74 -0
- data/test/formatters/test_yaml.rb +20 -0
- data/test/roo/test_csv.rb +52 -0
- data/test/roo/test_excelx.rb +186 -0
- data/test/roo/test_libre_office.rb +9 -0
- data/test/roo/test_open_office.rb +126 -0
- data/test/test_helper.rb +73 -53
- data/test/test_roo.rb +1211 -2292
- metadata +119 -298
- data/CHANGELOG +0 -417
- data/Gemfile.lock +0 -78
- data/README.markdown +0 -126
- data/VERSION +0 -1
- data/lib/roo/excel.rb +0 -355
- data/lib/roo/excel2003xml.rb +0 -300
- data/lib/roo/google.rb +0 -292
- data/lib/roo/openoffice.rb +0 -496
- data/lib/roo/roo_rails_helper.rb +0 -83
- data/lib/roo/worksheet.rb +0 -18
- data/scripts/txt2html +0 -67
- data/spec/lib/roo/excel2003xml_spec.rb +0 -15
- data/spec/lib/roo/excel_spec.rb +0 -17
- data/spec/lib/roo/google_spec.rb +0 -64
- data/test/files/1900_base.xls +0 -0
- data/test/files/1900_base.xlsx +0 -0
- data/test/files/1904_base.xls +0 -0
- data/test/files/1904_base.xlsx +0 -0
- data/test/files/Bibelbund.csv +0 -3741
- data/test/files/Bibelbund.ods +0 -0
- data/test/files/Bibelbund.xls +0 -0
- data/test/files/Bibelbund.xlsx +0 -0
- data/test/files/Bibelbund.xml +0 -62518
- data/test/files/Bibelbund1.ods +0 -0
- data/test/files/Pfand_from_windows_phone.xlsx +0 -0
- data/test/files/bad_excel_date.xls +0 -0
- data/test/files/bbu.ods +0 -0
- data/test/files/bbu.xls +0 -0
- data/test/files/bbu.xlsx +0 -0
- data/test/files/bbu.xml +0 -152
- data/test/files/bode-v1.ods.zip +0 -0
- data/test/files/bode-v1.xls.zip +0 -0
- data/test/files/boolean.csv +0 -2
- data/test/files/boolean.ods +0 -0
- data/test/files/boolean.xls +0 -0
- data/test/files/boolean.xlsx +0 -0
- data/test/files/boolean.xml +0 -112
- data/test/files/borders.ods +0 -0
- data/test/files/borders.xls +0 -0
- data/test/files/borders.xlsx +0 -0
- data/test/files/borders.xml +0 -144
- data/test/files/bug-numbered-sheet-names.xlsx +0 -0
- data/test/files/bug-row-column-fixnum-float.xls +0 -0
- data/test/files/bug-row-column-fixnum-float.xml +0 -127
- data/test/files/comments.ods +0 -0
- data/test/files/comments.xls +0 -0
- data/test/files/comments.xlsx +0 -0
- data/test/files/csvtypes.csv +0 -1
- data/test/files/datetime.ods +0 -0
- data/test/files/datetime.xls +0 -0
- data/test/files/datetime.xlsx +0 -0
- data/test/files/datetime.xml +0 -142
- data/test/files/datetime_floatconv.xls +0 -0
- data/test/files/datetime_floatconv.xml +0 -148
- data/test/files/dreimalvier.ods +0 -0
- data/test/files/emptysheets.ods +0 -0
- data/test/files/emptysheets.xls +0 -0
- data/test/files/emptysheets.xlsx +0 -0
- data/test/files/emptysheets.xml +0 -105
- data/test/files/excel2003.xml +0 -21140
- data/test/files/false_encoding.xls +0 -0
- data/test/files/false_encoding.xml +0 -132
- data/test/files/file_item_error.xlsx +0 -0
- data/test/files/formula.ods +0 -0
- data/test/files/formula.xls +0 -0
- data/test/files/formula.xlsx +0 -0
- data/test/files/formula.xml +0 -134
- data/test/files/formula_parse_error.xls +0 -0
- data/test/files/formula_parse_error.xml +0 -1833
- data/test/files/formula_string_error.xlsx +0 -0
- data/test/files/html-escape.ods +0 -0
- data/test/files/link.xls +0 -0
- data/test/files/link.xlsx +0 -0
- data/test/files/matrix.ods +0 -0
- data/test/files/matrix.xls +0 -0
- data/test/files/named_cells.ods +0 -0
- data/test/files/named_cells.xls +0 -0
- data/test/files/named_cells.xlsx +0 -0
- data/test/files/no_spreadsheet_file.txt +0 -1
- data/test/files/numbers1.csv +0 -18
- data/test/files/numbers1.ods +0 -0
- data/test/files/numbers1.xls +0 -0
- data/test/files/numbers1.xlsx +0 -0
- data/test/files/numbers1.xml +0 -312
- data/test/files/numeric-link.xlsx +0 -0
- data/test/files/only_one_sheet.ods +0 -0
- data/test/files/only_one_sheet.xls +0 -0
- data/test/files/only_one_sheet.xlsx +0 -0
- data/test/files/only_one_sheet.xml +0 -67
- data/test/files/paragraph.ods +0 -0
- data/test/files/paragraph.xls +0 -0
- data/test/files/paragraph.xlsx +0 -0
- data/test/files/paragraph.xml +0 -127
- data/test/files/prova.xls +0 -0
- data/test/files/ric.ods +0 -0
- data/test/files/simple_spreadsheet.ods +0 -0
- data/test/files/simple_spreadsheet.xls +0 -0
- data/test/files/simple_spreadsheet.xlsx +0 -0
- data/test/files/simple_spreadsheet.xml +0 -225
- data/test/files/simple_spreadsheet_from_italo.ods +0 -0
- data/test/files/simple_spreadsheet_from_italo.xls +0 -0
- data/test/files/simple_spreadsheet_from_italo.xml +0 -242
- data/test/files/so_datetime.csv +0 -7
- data/test/files/style.ods +0 -0
- data/test/files/style.xls +0 -0
- data/test/files/style.xlsx +0 -0
- data/test/files/style.xml +0 -154
- data/test/files/time-test.csv +0 -2
- data/test/files/time-test.ods +0 -0
- data/test/files/time-test.xls +0 -0
- data/test/files/time-test.xlsx +0 -0
- data/test/files/time-test.xml +0 -131
- data/test/files/type_excel.ods +0 -0
- data/test/files/type_excel.xlsx +0 -0
- data/test/files/type_excelx.ods +0 -0
- data/test/files/type_excelx.xls +0 -0
- data/test/files/type_openoffice.xls +0 -0
- data/test/files/type_openoffice.xlsx +0 -0
- data/test/files/whitespace.ods +0 -0
- data/test/files/whitespace.xls +0 -0
- data/test/files/whitespace.xlsx +0 -0
- data/test/files/whitespace.xml +0 -184
- data/test/rm_sub_test.rb +0 -12
- data/test/rm_test.rb +0 -7
- data/test/test_generic_spreadsheet.rb +0 -259
- data/website/index.html +0 -385
- data/website/index.txt +0 -423
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -130
- data/website/template.rhtml +0 -48
@@ -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
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "test_helper"
|
3
|
+
|
4
|
+
class TestRooOpenOffice < Minitest::Test
|
5
|
+
def test_openoffice_download_uri_and_zipped
|
6
|
+
port = 12_345
|
7
|
+
file = "rata.ods.zip"
|
8
|
+
start_local_server(file, port) do
|
9
|
+
url = "#{local_server(port)}/#{file}"
|
10
|
+
|
11
|
+
oo = roo_class.new(url, packed: :zip)
|
12
|
+
assert_in_delta 0.001, 505.14, oo.cell("c", 33).to_f
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_download_uri_with_invalid_host
|
17
|
+
assert_raises(RuntimeError) do
|
18
|
+
roo_class.new("http://example.com/file.ods")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_download_uri_with_query_string
|
23
|
+
file = filename("simple_spreadsheet")
|
24
|
+
port = 12_346
|
25
|
+
url = "#{local_server(port)}/#{file}?query-param=value"
|
26
|
+
start_local_server(file, port) do
|
27
|
+
spreadsheet = roo_class.new(url)
|
28
|
+
assert_equal "Task 1", spreadsheet.cell("f", 4)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_openoffice_zipped
|
33
|
+
oo = roo_class.new(File.join(TESTDIR, "bode-v1.ods.zip"), packed: :zip)
|
34
|
+
assert oo
|
35
|
+
assert_equal 'ist "e" im Nenner von H(s)', oo.cell("b", 5)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_raise_file_not_found_error
|
39
|
+
assert_raises(IOError) do
|
40
|
+
roo_class.new(File.join("testnichtvorhanden", "Bibelbund.ods"))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def test_file_warning_default_is_error
|
46
|
+
expected_message = "test/files/numbers1.xls is not an openoffice spreadsheet"
|
47
|
+
assert_raises(TypeError, expected_message) do
|
48
|
+
roo_class.new(File.join(TESTDIR, "numbers1.xls"))
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_raises(TypeError) do
|
52
|
+
roo_class.new(File.join(TESTDIR, "numbers1.xlsx"))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_file_warning_error
|
57
|
+
assert_raises(TypeError) do
|
58
|
+
roo_class.new(File.join(TESTDIR, "numbers1.xls"),
|
59
|
+
packed: false,
|
60
|
+
file_warning: :error
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_raises(TypeError) do
|
65
|
+
roo_class.new(File.join(TESTDIR, "numbers1.xlsx"),
|
66
|
+
packed: false,
|
67
|
+
file_warning: :error)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_file_warning_warning
|
72
|
+
assert_raises(ArgumentError) do
|
73
|
+
roo_class.new(File.join(TESTDIR, "numbers1.xlsx"),
|
74
|
+
packed: false,
|
75
|
+
file_warning: :warning)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_file_warning_ignore
|
80
|
+
assert roo_class.new(File.join(TESTDIR, "type_openoffice.xlsx"),
|
81
|
+
packed: false,
|
82
|
+
file_warning: :ignore), "Should not throw an error"
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_encrypted_file
|
86
|
+
oo = roo_class.new(File.join(TESTDIR, "encrypted-letmein.ods"), password: "letmein")
|
87
|
+
assert_equal "Hello World", oo.cell("a", 1)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_encrypted_file_requires_password
|
91
|
+
assert_raises(ArgumentError) { roo_class.new(File.join(TESTDIR, "encrypted-letmein.ods")) }
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_encrypted_file_with_incorrect_password
|
95
|
+
assert_raises(ArgumentError) { roo_class.new(File.join(TESTDIR, "encrypted-letmein.ods"), password: "badpassword") }
|
96
|
+
end
|
97
|
+
|
98
|
+
# 2011-08-11
|
99
|
+
def test_bug_openoffice_formula_missing_letters
|
100
|
+
# NOTE: This document was created using LibreOffice. The formulas seem
|
101
|
+
# different from a document created using OpenOffice.
|
102
|
+
#
|
103
|
+
# TODO: translate
|
104
|
+
# Bei den OpenOffice-Dateien ist in diesem Feld in der XML-
|
105
|
+
# Datei of: als Prefix enthalten, waehrend in dieser Datei
|
106
|
+
# irgendetwas mit oooc: als Prefix verwendet wird.
|
107
|
+
oo = Roo::OpenOffice.new(File.join(TESTDIR,'dreimalvier.ods'))
|
108
|
+
assert_equal '=SUM([.A1:.D1])', oo.formula('e',1)
|
109
|
+
assert_equal '=SUM([.A2:.D2])', oo.formula('e',2)
|
110
|
+
assert_equal '=SUM([.A3:.D3])', oo.formula('e',3)
|
111
|
+
assert_equal [
|
112
|
+
[1,5,'=SUM([.A1:.D1])'],
|
113
|
+
[2,5,'=SUM([.A2:.D2])'],
|
114
|
+
[3,5,'=SUM([.A3:.D3])'],
|
115
|
+
], oo.formulas
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def roo_class
|
120
|
+
Roo::OpenOffice
|
121
|
+
end
|
122
|
+
|
123
|
+
def filename(name)
|
124
|
+
"#{name}.ods"
|
125
|
+
end
|
126
|
+
end
|