roo 1.13.1 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +16 -0
- data/.github/pull_request_template.md +14 -0
- data/.github/workflows/pull-request.yml +15 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +186 -0
- data/.simplecov +4 -0
- data/CHANGELOG.md +702 -0
- data/Gemfile +18 -12
- data/Guardfile +23 -0
- data/LICENSE +5 -1
- data/README.md +328 -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 +317 -504
- data/lib/roo/constants.rb +7 -0
- data/lib/roo/csv.rb +141 -113
- data/lib/roo/errors.rb +11 -0
- data/lib/roo/excelx/cell/base.rb +108 -0
- data/lib/roo/excelx/cell/boolean.rb +30 -0
- data/lib/roo/excelx/cell/date.rb +28 -0
- data/lib/roo/excelx/cell/datetime.rb +107 -0
- data/lib/roo/excelx/cell/empty.rb +20 -0
- data/lib/roo/excelx/cell/number.rb +99 -0
- data/lib/roo/excelx/cell/string.rb +19 -0
- data/lib/roo/excelx/cell/time.rb +44 -0
- data/lib/roo/excelx/cell.rb +110 -0
- data/lib/roo/excelx/comments.rb +55 -0
- data/lib/roo/excelx/coordinate.rb +19 -0
- data/lib/roo/excelx/extractor.rb +39 -0
- data/lib/roo/excelx/format.rb +71 -0
- data/lib/roo/excelx/images.rb +26 -0
- data/lib/roo/excelx/relationships.rb +33 -0
- data/lib/roo/excelx/shared.rb +39 -0
- data/lib/roo/excelx/shared_strings.rb +151 -0
- data/lib/roo/excelx/sheet.rb +151 -0
- data/lib/roo/excelx/sheet_doc.rb +257 -0
- data/lib/roo/excelx/styles.rb +64 -0
- data/lib/roo/excelx/workbook.rb +64 -0
- data/lib/roo/excelx.rb +407 -601
- 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/helpers/default_attr_reader.rb +20 -0
- data/lib/roo/helpers/weak_instance_cache.rb +41 -0
- data/lib/roo/libre_office.rb +4 -0
- data/lib/roo/link.rb +34 -0
- data/lib/roo/open_office.rb +631 -0
- data/lib/roo/spreadsheet.rb +28 -23
- data/lib/roo/tempdir.rb +24 -0
- data/lib/roo/utils.rb +128 -0
- data/lib/roo/version.rb +3 -0
- data/lib/roo.rb +26 -24
- data/roo.gemspec +29 -202
- data/spec/helpers.rb +5 -0
- data/spec/lib/roo/base_spec.rb +291 -3
- data/spec/lib/roo/csv_spec.rb +38 -11
- data/spec/lib/roo/excelx/cell/time_spec.rb +15 -0
- data/spec/lib/roo/excelx/format_spec.rb +7 -6
- data/spec/lib/roo/excelx/relationships_spec.rb +43 -0
- data/spec/lib/roo/excelx/sheet_doc_spec.rb +11 -0
- data/spec/lib/roo/excelx_spec.rb +682 -6
- 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/strict_spec.rb +43 -0
- data/spec/lib/roo/utils_spec.rb +119 -0
- data/spec/lib/roo/weak_instance_cache_spec.rb +92 -0
- data/spec/lib/roo_spec.rb +0 -0
- data/spec/spec_helper.rb +7 -6
- data/test/all_ss.rb +12 -11
- data/test/excelx/cell/test_attr_reader_default.rb +72 -0
- data/test/excelx/cell/test_base.rb +68 -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 +18 -0
- data/test/excelx/cell/test_number.rb +90 -0
- data/test/excelx/cell/test_string.rb +48 -0
- data/test/excelx/cell/test_time.rb +30 -0
- data/test/excelx/test_coordinate.rb +51 -0
- data/test/formatters/test_csv.rb +136 -0
- data/test/formatters/test_matrix.rb +76 -0
- data/test/formatters/test_xml.rb +78 -0
- data/test/formatters/test_yaml.rb +20 -0
- data/test/helpers/test_accessing_files.rb +81 -0
- data/test/helpers/test_comments.rb +43 -0
- data/test/helpers/test_formulas.rb +9 -0
- data/test/helpers/test_labels.rb +103 -0
- data/test/helpers/test_sheets.rb +55 -0
- data/test/helpers/test_styles.rb +62 -0
- data/test/roo/test_base.rb +182 -0
- data/test/roo/test_csv.rb +88 -0
- data/test/roo/test_excelx.rb +360 -0
- data/test/roo/test_libre_office.rb +9 -0
- data/test/roo/test_open_office.rb +289 -0
- data/test/test_helper.rb +123 -59
- data/test/test_roo.rb +392 -2292
- metadata +153 -296
- data/CHANGELOG +0 -412
- 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/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,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRooExcelxCellDate < Minitest::Test
|
4
|
+
def date_cell
|
5
|
+
Roo::Excelx::Cell::Date
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_date
|
9
|
+
::Date.new(1899, 12, 30)
|
10
|
+
end
|
11
|
+
|
12
|
+
def base_date_1904
|
13
|
+
::Date.new(1904, 01, 01)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_handles_1904_base_date
|
17
|
+
cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date_1904, nil)
|
18
|
+
assert_equal ::Date.new(2018, 06, 02), cell.value
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_formatted_value
|
22
|
+
cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil)
|
23
|
+
assert_equal '06-01-14', cell.formatted_value
|
24
|
+
|
25
|
+
cell = date_cell.new('41791', nil, [:numeric_or_formula, 'yyyy-mm-dd'], 6, nil, base_date, nil)
|
26
|
+
assert_equal '2014-06-01', cell.formatted_value
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_value_is_date
|
30
|
+
cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil)
|
31
|
+
assert_kind_of ::Date, cell.value
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_value
|
35
|
+
cell = date_cell.new('41791', nil, [:numeric_or_formula, 'mm-dd-yy'], 6, nil, base_date, nil)
|
36
|
+
assert_equal ::Date.new(2014, 06, 01), cell.value
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRooExcelxCellDateTime < Minitest::Test
|
4
|
+
def test_cell_value_is_datetime
|
5
|
+
cell = datetime.new('30000.323212', nil, ['mm-dd-yy'], nil, nil, base_timestamp, nil)
|
6
|
+
assert_kind_of ::DateTime, cell.value
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_cell_type_is_datetime
|
10
|
+
cell = datetime.new('30000.323212', nil, [], nil, nil, base_timestamp, nil)
|
11
|
+
assert_equal :datetime, cell.type
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_standard_formatted_value
|
15
|
+
[
|
16
|
+
['mm-dd-yy', '01-25-15'],
|
17
|
+
['d-mmm-yy', '25-JAN-15'],
|
18
|
+
['d-mmm ', '25-JAN'],
|
19
|
+
['mmm-yy', 'JAN-15'],
|
20
|
+
['m/d/yy h:mm', '1/25/15 8:15']
|
21
|
+
].each do |format, formatted_value|
|
22
|
+
cell = datetime.new '42029.34375', nil, [format], nil, nil, base_timestamp, nil
|
23
|
+
assert_equal formatted_value, cell.formatted_value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_custom_formatted_value
|
28
|
+
[
|
29
|
+
['yyyy/mm/dd hh:mm:ss', '2015/01/25 08:15:00'],
|
30
|
+
['h:mm:ss000 mm/yy', '8:15:00000 01/15'],
|
31
|
+
['mmm yyy', '2015-01-25 08:15:00']
|
32
|
+
].each do |format, formatted_value|
|
33
|
+
cell = datetime.new '42029.34375', nil, [format], nil, nil, base_timestamp, nil
|
34
|
+
assert_equal formatted_value, cell.formatted_value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def datetime
|
39
|
+
Roo::Excelx::Cell::DateTime
|
40
|
+
end
|
41
|
+
|
42
|
+
def base_timestamp
|
43
|
+
DateTime.new(1899, 12, 30).to_time.to_i
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRooExcelxCellEmpty < Minitest::Test
|
4
|
+
def empty
|
5
|
+
Roo::Excelx::Cell::Empty
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_empty?
|
9
|
+
cell = empty.new(nil)
|
10
|
+
assert_same true, cell.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_nil_presence
|
14
|
+
cell = empty.new(nil)
|
15
|
+
assert_nil cell.presence
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRooExcelxCellNumber < Minitest::Test
|
4
|
+
def number
|
5
|
+
Roo::Excelx::Cell::Number
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_float
|
9
|
+
cell = Roo::Excelx::Cell::Number.new '42.1', nil, ['General'], nil, nil, nil
|
10
|
+
assert_kind_of(Float, cell.value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_integer
|
14
|
+
cell = Roo::Excelx::Cell::Number.new '42', nil, ['0'], nil, nil, nil
|
15
|
+
assert_kind_of(Integer, cell.value)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_scientific_notation
|
19
|
+
cell = Roo::Excelx::Cell::Number.new '1.2E-3', nil, ['0'], nil, nil, nil
|
20
|
+
assert_kind_of(Float, cell.value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_simple_scientific_notation
|
24
|
+
cell = Roo::Excelx::Cell::Number.new '1E-3', nil, ['0'], nil, nil, nil
|
25
|
+
assert_kind_of(Float, cell.value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_very_simple_scientific_notation
|
29
|
+
cell = Roo::Excelx::Cell::Number.new '1e6', nil, ['0'], nil, nil, nil
|
30
|
+
assert_kind_of(Float, cell.value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_percent
|
34
|
+
cell = Roo::Excelx::Cell::Number.new '42.1', nil, ['0.00%'], nil, nil, nil
|
35
|
+
assert_kind_of(Float, cell.value)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_rounded_percent_formatted_value
|
39
|
+
cell = Roo::Excelx::Cell::Number.new '0.569999999995', nil, ['0%'], nil, nil, nil
|
40
|
+
assert_equal('57%', cell.formatted_value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_formats_with_negative_numbers
|
44
|
+
[
|
45
|
+
['#,##0 ;(#,##0)', '(1,042)'],
|
46
|
+
['#,##0 ;[Red](#,##0)', '[Red](1,042)'],
|
47
|
+
['#,##0.00;(#,##0.00)', '(1,042.00)'],
|
48
|
+
['#,##0.00;[Red](#,##0.00)', '[Red](1,042.00)']
|
49
|
+
].each do |style_format, result|
|
50
|
+
cell = Roo::Excelx::Cell::Number.new '-1042', nil, [style_format], nil, nil, nil
|
51
|
+
assert_equal result, cell.formatted_value, "Style=#{style_format}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_numbers_with_cell_errors
|
56
|
+
Roo::Excelx::ERROR_VALUES.each do |error|
|
57
|
+
cell = Roo::Excelx::Cell::Number.new error, nil, ['General'], nil, nil, nil
|
58
|
+
assert_equal error, cell.value
|
59
|
+
assert_equal error, cell.formatted_value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_formats
|
64
|
+
[
|
65
|
+
['General', '1042'],
|
66
|
+
['GENERAL', '1042'],
|
67
|
+
['0', '1042'],
|
68
|
+
['000000', '001042'],
|
69
|
+
['0.00', '1042.00'],
|
70
|
+
['0.0000', '1042.0000'],
|
71
|
+
['0.000000000', '1042.000000000'],
|
72
|
+
['#,##0', '1,042'],
|
73
|
+
['#,##0.00', '1,042.00'],
|
74
|
+
['#,##0.000', '1,042.000'],
|
75
|
+
['0%', '104200%'],
|
76
|
+
['0.00%', '104200.00%'],
|
77
|
+
['0.00E+00', '1.04E+03'],
|
78
|
+
['#,##0 ;(#,##0)', '1,042'],
|
79
|
+
['#,##0 ;[Red](#,##0)', '1,042'],
|
80
|
+
['#,##0.00;(#,##0.00)', '1,042.00'],
|
81
|
+
['#,##0.00;[Red](#,##0.00)', '1,042.00'],
|
82
|
+
['##0.0E+0', '1.0E+03'],
|
83
|
+
["_-* #,##0.00\\ _€_-;\\-* #,##0.00\\ _€_-;_-* \"-\"??\\ _€_-;_-@_-", '1,042.00'],
|
84
|
+
['@', '1042']
|
85
|
+
].each do |style_format, result|
|
86
|
+
cell = Roo::Excelx::Cell::Number.new '1042', nil, [style_format], nil, nil, nil
|
87
|
+
assert_equal result, cell.formatted_value, "Style=#{style_format}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRooExcelxCellString < Minitest::Test
|
4
|
+
def string
|
5
|
+
Roo::Excelx::Cell::String
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def test_formatted_value
|
10
|
+
cell = string.new '1', nil, nil, nil, nil
|
11
|
+
assert_equal '1', cell.formatted_value
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_to_s
|
15
|
+
cell = string.new '0', nil, nil, nil, nil
|
16
|
+
assert_equal '0', cell.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_cell_value
|
20
|
+
cell = string.new '1', nil, nil, nil, nil
|
21
|
+
assert_equal '1', cell.cell_value
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_value
|
25
|
+
cell = string.new '0', nil, nil, nil, nil
|
26
|
+
assert_equal '0', cell.value
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_not_empty?
|
30
|
+
cell = string.new '1', nil, nil, nil, nil
|
31
|
+
assert_equal false, cell.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_empty?
|
35
|
+
cell = string.new '', nil, nil, nil, nil
|
36
|
+
assert_equal true, cell.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_presence
|
40
|
+
cell = string.new '1', nil, nil, nil, nil
|
41
|
+
assert_equal cell, cell.presence
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_nil_presence
|
45
|
+
cell = string.new '', nil, nil, nil, nil
|
46
|
+
assert_nil cell.presence
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRooExcelxCellTime < Minitest::Test
|
4
|
+
def roo_time
|
5
|
+
Roo::Excelx::Cell::Time
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_timestamp
|
9
|
+
DateTime.new(1899, 12, 30).to_time.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_formatted_value
|
13
|
+
value = '0.0751' # 6488.64 seconds, or 1:48:08.64
|
14
|
+
[
|
15
|
+
['h:mm', '1:48'],
|
16
|
+
['h:mm:ss', '1:48:09'],
|
17
|
+
['mm:ss', '48:09'],
|
18
|
+
['[h]:mm:ss', '[1]:48:09'],
|
19
|
+
['mmss.0', '4809.0'] # Cell::Time always get rounded to the nearest second.
|
20
|
+
].each do |style_format, result|
|
21
|
+
cell = roo_time.new(value, nil, [:numeric_or_formula, style_format], 6, nil, base_timestamp, nil)
|
22
|
+
assert_equal result, cell.formatted_value, "Style=#{style_format} is not properly formatted"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_value
|
27
|
+
cell = roo_time.new('0.0751', nil, [:numeric_or_formula, 'h:mm'], 6, nil, base_timestamp, nil)
|
28
|
+
assert_kind_of Integer, cell.value
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class TestRooExcelxCoordinate < Minitest::Test
|
6
|
+
def row
|
7
|
+
10
|
8
|
+
end
|
9
|
+
|
10
|
+
def column
|
11
|
+
20
|
12
|
+
end
|
13
|
+
|
14
|
+
def coordinate
|
15
|
+
Roo::Excelx::Coordinate.new(row, column)
|
16
|
+
end
|
17
|
+
|
18
|
+
def array
|
19
|
+
[row, column]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_row
|
23
|
+
assert_same row, coordinate.row
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_column
|
27
|
+
assert_same column, coordinate.column
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_frozen?
|
31
|
+
assert coordinate.frozen?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_equality
|
35
|
+
hash = {}
|
36
|
+
hash[coordinate] = true
|
37
|
+
assert hash.key?(coordinate)
|
38
|
+
assert hash.key?(array)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_expand
|
42
|
+
r, c = coordinate
|
43
|
+
assert_same row, r
|
44
|
+
assert_same column, c
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_aref
|
48
|
+
assert_same row, coordinate[0]
|
49
|
+
assert_same column, coordinate[1]
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,136 @@
|
|
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_long_test
|
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_long_test
|
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_bug_datetime_offset_change
|
104
|
+
# DO NOT REMOVE Asia/Calcutta
|
105
|
+
[nil, "US/Eastern", "US/Pacific", "Asia/Calcutta"].each do |zone|
|
106
|
+
with_timezone(zone) do
|
107
|
+
with_each_spreadsheet(name: "datetime_timezone_ist_offset_change", format: %i[excelx openoffice libreoffice]) do |workbook|
|
108
|
+
Dir.mktmpdir do |tempdir|
|
109
|
+
datetime_csv_file = File.join(tempdir, "datetime_timezone_ist_offset_change.csv")
|
110
|
+
|
111
|
+
assert workbook.to_csv(datetime_csv_file)
|
112
|
+
assert File.exist?(datetime_csv_file)
|
113
|
+
assert_equal "", file_diff("#{TESTDIR}/so_datetime_timezone_ist_offset_change.csv", datetime_csv_file)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_true_class
|
121
|
+
assert_equal "true", cell_to_csv(1, 1)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_false_class
|
125
|
+
assert_equal "false", cell_to_csv(2, 1)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_date_class
|
129
|
+
assert_equal "2017-01-01", cell_to_csv(3, 1)
|
130
|
+
end
|
131
|
+
|
132
|
+
def cell_to_csv(row, col)
|
133
|
+
filename = File.join(TESTDIR, "formula_cell_types.xlsx")
|
134
|
+
Roo::Spreadsheet.open(filename).send("cell_to_csv", row, col, "Sheet1")
|
135
|
+
end
|
136
|
+
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,78 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestRooFormatterXML < Minitest::Test
|
4
|
+
def test_to_xml
|
5
|
+
expected_sheet_count = 5
|
6
|
+
options = { name: "numbers1", encoding: "utf8" }
|
7
|
+
with_each_spreadsheet(options) do |workbook|
|
8
|
+
skip if defined? JRUBY_VERSION
|
9
|
+
workbook.to_xml
|
10
|
+
sheetname = workbook.sheets.first
|
11
|
+
doc = Nokogiri::XML(workbook.to_xml)
|
12
|
+
|
13
|
+
assert_equal expected_sheet_count, doc.xpath("//spreadsheet/sheet").count
|
14
|
+
|
15
|
+
doc.xpath("//spreadsheet/sheet").each do |xml_sheet|
|
16
|
+
all_cells = init_all_cells(workbook, sheetname)
|
17
|
+
cells = xml_sheet.children.reject(&:text?)
|
18
|
+
|
19
|
+
assert_equal sheetname, xml_sheet["name"]
|
20
|
+
assert_equal all_cells.size, cells.size
|
21
|
+
|
22
|
+
cells.each_with_index do |cell, i|
|
23
|
+
expected = [
|
24
|
+
all_cells[i][:row],
|
25
|
+
all_cells[i][:column],
|
26
|
+
all_cells[i][:content],
|
27
|
+
all_cells[i][:type],
|
28
|
+
]
|
29
|
+
result = [
|
30
|
+
cell["row"],
|
31
|
+
cell["column"],
|
32
|
+
cell.text,
|
33
|
+
cell["type"],
|
34
|
+
]
|
35
|
+
|
36
|
+
assert_equal expected, result
|
37
|
+
end # end of sheet
|
38
|
+
sheetname = workbook.sheets[workbook.sheets.index(sheetname) + 1]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_bug_to_xml_with_empty_sheets
|
44
|
+
with_each_spreadsheet(name: "emptysheets", format: [:openoffice, :excelx]) do |workbook|
|
45
|
+
workbook.sheets.each do |sheet|
|
46
|
+
assert_nil workbook.first_row, "first_row not nil in sheet #{sheet}"
|
47
|
+
assert_nil workbook.last_row, "last_row not nil in sheet #{sheet}"
|
48
|
+
assert_nil workbook.first_column, "first_column not nil in sheet #{sheet}"
|
49
|
+
assert_nil workbook.last_column, "last_column not nil in sheet #{sheet}"
|
50
|
+
assert_nil workbook.first_row(sheet), "first_row not nil in sheet #{sheet}"
|
51
|
+
assert_nil workbook.last_row(sheet), "last_row not nil in sheet #{sheet}"
|
52
|
+
assert_nil workbook.first_column(sheet), "first_column not nil in sheet #{sheet}"
|
53
|
+
assert_nil workbook.last_column(sheet), "last_column not nil in sheet #{sheet}"
|
54
|
+
end
|
55
|
+
workbook.to_xml
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Erstellt eine Liste aller Zellen im Spreadsheet. Dies ist nötig, weil ein einfacher
|
60
|
+
# Textvergleich des XML-Outputs nicht funktioniert, da xml-builder die Attribute
|
61
|
+
# nicht immer in der gleichen Reihenfolge erzeugt.
|
62
|
+
def init_all_cells(workbook, sheet)
|
63
|
+
all = []
|
64
|
+
workbook.first_row(sheet).upto(workbook.last_row(sheet)) do |row|
|
65
|
+
workbook.first_column(sheet).upto(workbook.last_column(sheet)) do |col|
|
66
|
+
next if workbook.empty?(row, col, sheet)
|
67
|
+
|
68
|
+
all << {
|
69
|
+
row: row.to_s,
|
70
|
+
column: col.to_s,
|
71
|
+
content: workbook.cell(row, col, sheet).to_s,
|
72
|
+
type: workbook.celltype(row, col, sheet).to_s,
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
all
|
77
|
+
end
|
78
|
+
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
|