workbook 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +21 -0
  3. data/.gitignore +4 -1
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +4 -4
  6. data/CHANGELOG.md +8 -0
  7. data/Gemfile +2 -2
  8. data/README.md +9 -7
  9. data/Rakefile +6 -6
  10. data/json_test.json +1 -0
  11. data/lib/workbook/book.rb +73 -62
  12. data/lib/workbook/cell.rb +58 -13
  13. data/lib/workbook/column.rb +31 -28
  14. data/lib/workbook/format.rb +23 -24
  15. data/lib/workbook/generatetypes.rb +4 -4
  16. data/lib/workbook/modules/cache.rb +6 -7
  17. data/lib/workbook/modules/cell.rb +77 -100
  18. data/lib/workbook/modules/diff_sort.rb +92 -83
  19. data/lib/workbook/modules/raw_objects_storage.rb +6 -8
  20. data/lib/workbook/modules/type_parser.rb +30 -22
  21. data/lib/workbook/nil_value.rb +4 -9
  22. data/lib/workbook/readers/csv_reader.rb +7 -10
  23. data/lib/workbook/readers/ods_reader.rb +51 -50
  24. data/lib/workbook/readers/txt_reader.rb +6 -8
  25. data/lib/workbook/readers/xls_reader.rb +21 -33
  26. data/lib/workbook/readers/xls_shared.rb +106 -117
  27. data/lib/workbook/readers/xlsx_reader.rb +45 -46
  28. data/lib/workbook/row.rb +99 -84
  29. data/lib/workbook/sheet.rb +47 -38
  30. data/lib/workbook/table.rb +96 -72
  31. data/lib/workbook/template.rb +12 -15
  32. data/lib/workbook/types/false.rb +0 -1
  33. data/lib/workbook/types/nil.rb +0 -1
  34. data/lib/workbook/types/nil_class.rb +1 -1
  35. data/lib/workbook/types/numeric.rb +1 -1
  36. data/lib/workbook/types/string.rb +1 -1
  37. data/lib/workbook/types/time.rb +1 -1
  38. data/lib/workbook/types/true.rb +0 -1
  39. data/lib/workbook/types/true_class.rb +1 -1
  40. data/lib/workbook/version.rb +2 -3
  41. data/lib/workbook/writers/csv_table_writer.rb +10 -13
  42. data/lib/workbook/writers/html_writer.rb +34 -38
  43. data/lib/workbook/writers/json_table_writer.rb +8 -11
  44. data/lib/workbook/writers/xls_writer.rb +30 -36
  45. data/lib/workbook/writers/xlsx_writer.rb +45 -29
  46. data/lib/workbook.rb +16 -15
  47. data/test/artifacts/currency_test.ods +0 -0
  48. data/test/helper.rb +6 -5
  49. data/test/test_book.rb +41 -38
  50. data/test/test_column.rb +26 -24
  51. data/test/test_format.rb +51 -55
  52. data/test/test_functional.rb +7 -8
  53. data/test/test_modules_cache.rb +18 -17
  54. data/test/test_modules_cell.rb +55 -46
  55. data/test/test_modules_table_diff_sort.rb +55 -64
  56. data/test/test_modules_type_parser.rb +61 -31
  57. data/test/test_readers_csv_reader.rb +48 -42
  58. data/test/test_readers_ods_reader.rb +36 -31
  59. data/test/test_readers_txt_reader.rb +21 -23
  60. data/test/test_readers_xls_reader.rb +20 -23
  61. data/test/test_readers_xls_shared.rb +2 -3
  62. data/test/test_readers_xlsx_reader.rb +44 -37
  63. data/test/test_row.rb +105 -109
  64. data/test/test_sheet.rb +35 -41
  65. data/test/test_table.rb +82 -60
  66. data/test/test_template.rb +16 -15
  67. data/test/test_types_date.rb +4 -6
  68. data/test/test_writers_csv_writer.rb +24 -0
  69. data/test/test_writers_html_writer.rb +42 -41
  70. data/test/test_writers_json_writer.rb +16 -9
  71. data/test/test_writers_xls_writer.rb +50 -35
  72. data/test/test_writers_xlsx_writer.rb +62 -34
  73. data/workbook.gemspec +25 -27
  74. metadata +96 -42
@@ -1,26 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
  module Readers
6
- class TestCsvWriter < Minitest::Test
5
+ class TestCsvReader < Minitest::Test
7
6
  def test_open
8
7
  w = Workbook::Book.new
9
- w.import File.join(File.dirname(__FILE__), 'artifacts/simple_csv.csv')
8
+ w.import File.join(File.dirname(__FILE__), "artifacts/simple_csv.csv")
10
9
  # reads
11
10
  # a,b,c,d
12
11
  # 1,2,3,4
13
12
  # 5,3,2,1
14
13
  # "asdf",123,12,2001-02-02
15
14
  #
16
- assert_equal([:a,:b,:c,:d],w.sheet.table.header.to_symbols)
17
- assert_equal(3,w.sheet.table[2][:b].value)
18
- assert_equal("asdf",w.sheet.table[3][:a].value)
19
- assert_equal(Date.new(2001,2,2),w.sheet.table[3][:d].value)
15
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
16
+ assert_equal(3, w.sheet.table[2][:b].value)
17
+ assert_equal("asdf", w.sheet.table[3][:a].value)
18
+ assert_equal(Date.new(2001, 2, 2), w.sheet.table[3][:d].value)
20
19
  end
20
+
21
21
  def test_excel_csv_open
22
22
  w = Workbook::Book.new
23
- w.import File.join(File.dirname(__FILE__), 'artifacts/simple_excel_csv.csv')
23
+ w.import File.join(File.dirname(__FILE__), "artifacts/simple_excel_csv.csv")
24
24
  # reads
25
25
  # a;b;c
26
26
  # 1-1-2001;23;1
@@ -28,81 +28,87 @@ module Readers
28
28
  # 23;asdf;sadf
29
29
  # 12;23;12-02-2011 12:23
30
30
  # 12 asadf; 6/12 ovk getekend teru...; 6/12
31
- #y w.sheet.table
32
- assert_equal([:a,:b,:c],w.sheet.table.header.to_symbols)
33
- assert_equal(23,w.sheet.table[2][:b].value)
34
- assert_equal("sadf",w.sheet.table[3][:c].value)
35
- assert_equal(Date.new(2001,1,1),w.sheet.table[1][:a].value)
36
- assert_equal(DateTime.new(2011,2,12,12,23),w.sheet.table[4][:c].value)
31
+ # y w.sheet.table
32
+ assert_equal([:a, :b, :c], w.sheet.table.header.to_symbols)
33
+ assert_equal(23, w.sheet.table[2][:b].value)
34
+ assert_equal("sadf", w.sheet.table[3][:c].value)
35
+ assert_equal(Date.new(2001, 1, 1), w.sheet.table[1][:a].value)
36
+ assert_equal(DateTime.new(2011, 2, 12, 12, 23), w.sheet.table[4][:c].value)
37
37
  assert_equal("6/12 ovk getekend terugontv.+>acq ter tekening. 13/12 ovk getekend terugontv.+>Fred ter tekening.", w.sheet.table[5][:b].value)
38
- assert_equal("6/12",w.sheet.table[5][:c].value)
38
+ assert_equal("6/12", w.sheet.table[5][:c].value)
39
39
  end
40
+
40
41
  def test_excel_standardized_open
41
42
  w = Workbook::Book.new
42
- w.import File.join(File.dirname(__FILE__), 'artifacts/excel_different_types.csv')
43
+ w.import File.join(File.dirname(__FILE__), "artifacts/excel_different_types.csv")
43
44
  # reads
44
45
  # a,b,c,d
45
46
  # 2012-02-22,2014-12-27,2012-11-23,2012-11-12T04:20:00+00:00
46
47
  # c,222.0,,0027-12-14T05:21:00+00:00
47
48
  # 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
48
49
 
49
- assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
50
- assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
51
- assert_equal("c",w.sheet.table[2][:a].value)
52
- assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
53
- assert_equal(42000,w.sheet.table[3][:b].value)
50
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
51
+ assert_equal(Date.new(2012, 2, 22), w.sheet.table[1][:a].value)
52
+ assert_equal("c", w.sheet.table[2][:a].value)
53
+ assert_equal(DateTime.new(2012, 1, 22, 11), w.sheet.table[3][:a].value)
54
+ assert_equal(42000, w.sheet.table[3][:b].value)
54
55
  assert_nil(w.sheet.table[2][:c].value)
55
56
  end
57
+
56
58
  def test_class_read_string
57
- s = File.read File.join(File.dirname(__FILE__), 'artifacts/simple_csv.csv')
58
- w = Workbook::Book.read( s, :csv )
59
+ s = File.read File.join(File.dirname(__FILE__), "artifacts/simple_csv.csv")
60
+ w = Workbook::Book.read(s, :csv)
59
61
  # reads
60
62
  # a,b,c,d
61
63
  # 1,2,3,4
62
64
  # 5,3,2,1
63
65
  # "asdf",123,12,2001-02-02
64
66
  #
65
- assert_equal([:a,:b,:c,:d],w.sheet.table.header.to_symbols)
66
- assert_equal(3,w.sheet.table[2][:b].value)
67
- assert_equal("asdf",w.sheet.table[3][:a].value)
68
- assert_equal(Date.new(2001,2,2),w.sheet.table[3][:d].value)
67
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
68
+ assert_equal(3, w.sheet.table[2][:b].value)
69
+ assert_equal("asdf", w.sheet.table[3][:a].value)
70
+ assert_equal(Date.new(2001, 2, 2), w.sheet.table[3][:d].value)
69
71
  end
72
+
70
73
  def test_instance_read_string
71
74
  w = Workbook::Book.new
72
- s = File.read File.join(File.dirname(__FILE__), 'artifacts/simple_csv.csv')
73
- w.read( s, :csv )
75
+ s = File.read File.join(File.dirname(__FILE__), "artifacts/simple_csv.csv")
76
+ w.read(s, :csv)
74
77
  # reads
75
78
  # a,b,c,d
76
79
  # 1,2,3,4
77
80
  # 5,3,2,1
78
81
  # "asdf",123,12,2001-02-02
79
82
  #
80
- assert_equal([:a,:b,:c,:d],w.sheet.table.header.to_symbols)
81
- assert_equal(3,w.sheet.table[2][:b].value)
82
- assert_equal("asdf",w.sheet.table[3][:a].value)
83
- assert_equal(Date.new(2001,2,2),w.sheet.table[3][:d].value)
83
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
84
+ assert_equal(3, w.sheet.table[2][:b].value)
85
+ assert_equal("asdf", w.sheet.table[3][:a].value)
86
+ assert_equal(Date.new(2001, 2, 2), w.sheet.table[3][:d].value)
84
87
  end
88
+
85
89
  def test_instance_read_stringio
86
90
  w = Workbook::Book.new
87
- sio = StringIO.new(File.read File.join(File.dirname(__FILE__), 'artifacts/simple_csv.csv'))
88
- w.read( sio, :csv )
91
+ sio = StringIO.new(File.read(File.join(File.dirname(__FILE__), "artifacts/simple_csv.csv")))
92
+ w.read(sio, :csv)
89
93
  # reads
90
94
  # a,b,c,d
91
95
  # 1,2,3,4
92
96
  # 5,3,2,1
93
97
  # "asdf",123,12,2001-02-02
94
98
  #
95
- assert_equal([:a,:b,:c,:d],w.sheet.table.header.to_symbols)
96
- assert_equal(3,w.sheet.table[2][:b].value)
97
- assert_equal("asdf",w.sheet.table[3][:a].value)
98
- assert_equal(Date.new(2001,2,2),w.sheet.table[3][:d].value)
99
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
100
+ assert_equal(3, w.sheet.table[2][:b].value)
101
+ assert_equal("asdf", w.sheet.table[3][:a].value)
102
+ assert_equal(Date.new(2001, 2, 2), w.sheet.table[3][:d].value)
99
103
  end
104
+
100
105
  def test_from_string
101
106
  w = Workbook::Book.read("2013-03-19,JV,211,032,1,DBG A,,13,0147,\n", :csv, {converters: []})
102
- assert_equal("2013-03-19,JV,211,032,1,DBG A,,13,0147,\n",w.sheet.table.to_csv)
107
+ assert_equal("2013-03-19,JV,211,032,1,DBG A,,13,0147,\n", w.sheet.table.to_csv)
103
108
  end
109
+
104
110
  def test_semi_colon_separated_csv
105
- w = Workbook::Book.open(File.join(File.dirname(__FILE__), 'artifacts/semicolonseparated_in_csv.csv'))
111
+ w = Workbook::Book.open(File.join(File.dirname(__FILE__), "artifacts/semicolonseparated_in_csv.csv"))
106
112
  assert_equal("artikel,aantal,bedrag,reservering,aanmaaktijd_reservering,gastnummer,titel,voorletters,tussenvoegsels,naam,straat,huisnummer,postcode,woonplaats,email,tel_land,tel_net,tel_abon\nVriend - € 50,1,50.0,123,2016-10-27,7891,asdf,A.,,asdf,asdf ,55,1234 LM,AMSTERDAM,a@example.com,43,,123123\nVriend - € 35,1,35.0,123,2016-11-02,5676,Dasdfr,B.,,asdf,asdf asdf,12,1234 NN,UTRECHT,b@example.com,31,60,123123\n", w.sheet.table.to_csv)
107
113
  end
108
114
  end
@@ -1,23 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
  module Readers
6
5
  class TestOdsWriter < Minitest::Test
7
6
  def test_ods_open
8
-
9
7
  w = Workbook::Book.new
10
- w.import File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.ods')
8
+ w.import File.join(File.dirname(__FILE__), "artifacts/book_with_tabs_and_colours.ods")
11
9
 
12
- assert_equal([:a, :b, :c, :d, :e],w.sheet.table.header.to_symbols)
13
- assert_equal(90588,w.sheet.table[2][:b].value)
10
+ assert_equal([:a, :b, :c, :d, :e], w.sheet.table.header.to_symbols)
11
+ assert_equal(90588, w.sheet.table[2][:b].value)
14
12
  end
15
13
 
16
14
  def test_styling
17
15
  w = Workbook::Book.new
18
- w.import File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.ods')
19
- assert_equal("#ffff99",w.sheet.table[3][:c].format[:background_color])
20
- assert_equal(true,w.sheet.table[0][:e].format.all_names.include?("Heading1"))
16
+ w.import File.join(File.dirname(__FILE__), "artifacts/book_with_tabs_and_colours.ods")
17
+ assert_equal("#ffff99", w.sheet.table[3][:c].format[:background_color])
18
+ assert_equal(true, w.sheet.table[0][:e].format.all_names.include?("Heading1"))
21
19
  # TODO: column styles
22
20
  # assert_equal(8.13671875,w.sheet.table.first[:b].format[:width])
23
21
  # assert_equal(3.85546875,w.sheet.table.first[:a].format[:width])
@@ -26,48 +24,55 @@ module Readers
26
24
 
27
25
  def test_complex_types
28
26
  w = Workbook::Book.new
29
- w.import File.join(File.dirname(__FILE__), 'artifacts/complex_types.ods')
30
- assert_equal(Date.new(2011,11,15), w.sheet.table[2][3].value)
27
+ w.import File.join(File.dirname(__FILE__), "artifacts/complex_types.ods")
28
+ assert_equal(Date.new(2011, 11, 15), w.sheet.table[2][3].value)
31
29
  assert_equal("http://murb.nl", w.sheet.table[3][2].value)
32
30
  assert_equal("Sadfasdfsd > 2", w.sheet.table[4][2].value)
33
31
  assert_equal(1.2, w.sheet.table[3][1].value)
34
32
  end
35
33
 
34
+ def test_currency
35
+ w = Workbook::Book.new
36
+ w.import File.join(File.dirname(__FILE__), "artifacts/currency_test.ods")
37
+
38
+ assert_equal(1200, w.sheet.table["H2"].value)
39
+ assert_equal(1200.4, w.sheet.table["H4"].value)
40
+ end
41
+
36
42
  def test_excel_standardized_open
37
43
  w = Workbook::Book.new
38
- w.import File.join(File.dirname(__FILE__), 'artifacts/excel_different_types.ods')
39
- assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols[0..3])
40
- assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
41
- assert_equal("c",w.sheet.table[2][:a].value)
42
- assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
43
- assert_equal("42000",w.sheet.table[3][:b].value.to_s)
44
+ w.import File.join(File.dirname(__FILE__), "artifacts/excel_different_types.ods")
45
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols[0..3])
46
+ assert_equal(Date.new(2012, 2, 22), w.sheet.table[1][:a].value)
47
+ assert_equal("c", w.sheet.table[2][:a].value)
48
+ assert_equal(DateTime.new(2012, 1, 22, 11), w.sheet.table[3][:a].value)
49
+ assert_equal("42000", w.sheet.table[3][:b].value.to_s)
44
50
  assert_nil(w.sheet.table[2][:c].value)
45
51
  end
46
52
 
47
53
  def test_sheet_with_combined_cells
48
54
  w = Workbook::Book.new
49
- w.import File.join(File.dirname(__FILE__), 'artifacts/sheet_with_combined_cells.ods')
55
+ w.import File.join(File.dirname(__FILE__), "artifacts/sheet_with_combined_cells.ods")
50
56
  t = w.sheet.table
51
- assert_equal("14 90589",t[1][:a].value)
52
- assert_equal(Workbook::NilValue,t[1][:b].value.class)
53
- assert_equal(:covered,t[1][:b].value.reason)
54
- assert_equal(2,t[1][:a].colspan)
57
+ assert_equal("14 90589", t[1][:a].value)
58
+ assert_equal(Workbook::NilValue, t[1][:b].value.class)
59
+ assert_equal(:covered, t[1][:b].value.reason)
60
+ assert_equal(2, t[1][:a].colspan)
55
61
  assert_nil(t[1][:c].colspan)
56
- assert_equal(2,t["D3"].rowspan)
57
- assert_equal(2,t["D5"].rowspan)
58
- assert_equal(2,t["D5"].colspan)
62
+ assert_equal(2, t["D3"].rowspan)
63
+ assert_equal(2, t["D5"].rowspan)
64
+ assert_equal(2, t["D5"].colspan)
59
65
  end
60
66
 
61
67
  def test_book_with_colspans
62
68
  w = Workbook::Book.new
63
- w.import File.join(File.dirname(__FILE__), 'artifacts/book_with_colspans.ods')
69
+ w.import File.join(File.dirname(__FILE__), "artifacts/book_with_colspans.ods")
64
70
  t = w.sheet.table
65
- assert_equal(2,t["B1"].colspan)
66
- assert_equal(2,t["D1"].colspan)
71
+ assert_equal(2, t["B1"].colspan)
72
+ assert_equal(2, t["D1"].colspan)
67
73
  assert_nil(t["D3"].value)
68
- assert_equal("g",t["A19"].value)
69
- assert_equal(0.03,t["D17"].value)
74
+ assert_equal("g", t["A19"].value)
75
+ assert_equal(0.03, t["D17"].value)
70
76
  end
71
-
72
77
  end
73
78
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
  module Readers
6
5
  class TestTxtReader < Minitest::Test
7
6
  # Should one day throw an error..
@@ -20,11 +19,11 @@ module Readers
20
19
  # c,222.0,,0027-12-14T05:21:00+00:00
21
20
  # 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
22
21
 
23
- assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
24
- assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
25
- assert_equal("c",w.sheet.table[2][:a].value)
26
- assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
27
- assert_equal(42000,w.sheet.table[3][:b].value)
22
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
23
+ assert_equal(Date.new(2012, 2, 22), w.sheet.table[1][:a].value)
24
+ assert_equal("c", w.sheet.table[2][:a].value)
25
+ assert_equal(DateTime.new(2012, 1, 22, 11), w.sheet.table[3][:a].value)
26
+ assert_equal(42000, w.sheet.table[3][:b].value)
28
27
  assert_nil(w.sheet.table[2][:c].value)
29
28
  end
30
29
 
@@ -37,11 +36,11 @@ module Readers
37
36
  # c,222.0,,0027-12-14T05:21:00+00:00
38
37
  # 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
39
38
 
40
- assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
41
- assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
42
- assert_equal("c",w.sheet.table[2][:a].value)
43
- assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
44
- assert_equal("42000",w.sheet.table[3][:b].value.to_s)
39
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
40
+ assert_equal(Date.new(2012, 2, 22), w.sheet.table[1][:a].value)
41
+ assert_equal("c", w.sheet.table[2][:a].value)
42
+ assert_equal(DateTime.new(2012, 1, 22, 11), w.sheet.table[3][:a].value)
43
+ assert_equal("42000", w.sheet.table[3][:b].value.to_s)
45
44
  assert_nil(w.sheet.table[2][:c].value)
46
45
  end
47
46
 
@@ -55,11 +54,11 @@ module Readers
55
54
  # c,222.0,,0027-12-14T05:21:00+00:00
56
55
  # 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
57
56
 
58
- assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
59
- assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
60
- assert_equal("c",w.sheet.table[2][:a].value)
61
- assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
62
- assert_equal(42000,w.sheet.table[3][:b].value)
57
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
58
+ assert_equal(Date.new(2012, 2, 22), w.sheet.table[1][:a].value)
59
+ assert_equal("c", w.sheet.table[2][:a].value)
60
+ assert_equal(DateTime.new(2012, 1, 22, 11), w.sheet.table[3][:a].value)
61
+ assert_equal(42000, w.sheet.table[3][:b].value)
63
62
  assert_nil(w.sheet.table[2][:c].value)
64
63
  end
65
64
 
@@ -73,13 +72,12 @@ module Readers
73
72
  # c,222.0,,0027-12-14T05:21:00+00:00
74
73
  # 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
75
74
 
76
- assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
77
- assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
78
- assert_equal("c",w.sheet.table[2][:a].value)
79
- assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
80
- assert_equal(42000,w.sheet.table[3][:b].value)
75
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
76
+ assert_equal(Date.new(2012, 2, 22), w.sheet.table[1][:a].value)
77
+ assert_equal("c", w.sheet.table[2][:a].value)
78
+ assert_equal(DateTime.new(2012, 1, 22, 11), w.sheet.table[3][:a].value)
79
+ assert_equal(42000, w.sheet.table[3][:b].value)
81
80
  assert_nil(w.sheet.table[2][:c].value)
82
81
  end
83
-
84
82
  end
85
83
  end
@@ -1,26 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
  module Readers
6
5
  class TestXlsWriter < Minitest::Test
7
6
  def test_xls_open
8
7
  w = Workbook::Book.new
9
- w.import File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xls')
10
- assert_equal([:a, :b, :c, :d, :e],w.sheet.table.header.to_symbols)
11
- assert_equal(90588,w.sheet.table[2][:b].value)
12
- assert_equal("#CCFFCC",w.sheet.table[3][:c].format[:background_color])
13
- assert_equal(8.13671875,w.sheet.table.first[:b].format[:width])
14
- assert_equal(3.85546875,w.sheet.table.first[:a].format[:width])
15
- assert_equal(25.14453125,w.sheet.table.first[:c].format[:width])
16
-
17
-
8
+ w.import File.join(File.dirname(__FILE__), "artifacts/book_with_tabs_and_colours.xls")
9
+ assert_equal([:a, :b, :c, :d, :e], w.sheet.table.header.to_symbols)
10
+ assert_equal(90588, w.sheet.table[2][:b].value)
11
+ assert_equal("#CCFFCC", w.sheet.table[3][:c].format[:background_color])
12
+ assert_equal(8.13671875, w.sheet.table.first[:b].format[:width])
13
+ assert_equal(3.85546875, w.sheet.table.first[:a].format[:width])
14
+ assert_equal(25.14453125, w.sheet.table.first[:c].format[:width])
18
15
  end
19
16
 
20
17
  def test_xls_complex_types
21
18
  w = Workbook::Book.new
22
- w.import File.join(File.dirname(__FILE__), 'artifacts/complex_types.xls')
23
- assert_equal(Date.new(2011,11,15), w.sheet.table[2][3].value)
19
+ w.import File.join(File.dirname(__FILE__), "artifacts/complex_types.xls")
20
+ assert_equal(Date.new(2011, 11, 15), w.sheet.table[2][3].value)
24
21
  assert_equal("http://murb.nl", w.sheet.table[3][2].value)
25
22
  assert_equal("sadfasdfsd!", w.sheet.table[4][2].value)
26
23
  assert_equal(1.2, w.sheet.table[2][1].value)
@@ -36,11 +33,11 @@ module Readers
36
33
  # c,222.0,,0027-12-14T05:21:00+00:00
37
34
  # 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
38
35
 
39
- assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
40
- assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
41
- assert_equal("c",w.sheet.table[2][:a].value)
42
- assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
43
- assert_equal(42000,w.sheet.table[3][:b].value)
36
+ assert_equal([:a, :b, :c, :d], w.sheet.table.header.to_symbols)
37
+ assert_equal(Date.new(2012, 2, 22), w.sheet.table[1][:a].value)
38
+ assert_equal("c", w.sheet.table[2][:a].value)
39
+ assert_equal(DateTime.new(2012, 1, 22, 11), w.sheet.table[3][:a].value)
40
+ assert_equal(42000, w.sheet.table[3][:b].value)
44
41
  assert_nil(w.sheet.table[2][:c].value)
45
42
  end
46
43
 
@@ -48,7 +45,7 @@ module Readers
48
45
  w = Workbook::Book.new
49
46
  w.import(File.join(File.dirname(__FILE__), "artifacts/txt_in_xls.xls"))
50
47
  assert_equal([:naam, :nummer, :ilt, :corporate_key, :naam_medewerker, nil, nil, :telefoon, :openingsdatum], w.sheet.table.header.to_symbols)
51
- assert_equal(["dddd", 2222, "i9000", "asd", "Anita", nil, "Betera", "012-3456789", Date.new(2011,10,5)], w.sheet.table[1].collect{|a| a.value})
48
+ assert_equal(["dddd", 2222, "i9000", "asd", "Anita", nil, "Betera", "012-3456789", Date.new(2011, 10, 5)], w.sheet.table[1].collect { |a| a.value })
52
49
  end
53
50
 
54
51
  def test_zip_in_xls_open
@@ -60,13 +57,13 @@ module Readers
60
57
  rescue CSV::MalformedCSVError
61
58
  failed_properly = true
62
59
  end
63
- assert_equal(true,failed_properly)
60
+ assert_equal(true, failed_properly)
64
61
  end
65
62
 
66
63
  def test_multi_sheet_opening
67
- b = Workbook::Book.open(File.join(File.dirname(__FILE__), 'artifacts/simple_sheet_many_sheets.xls'))
68
- assert_equal(["Diff_10", "Diff_9", "Diff_8", "Diff_7", "Diff_6", "Diff_5", "Diff_4", "Diff_3", "Diff_2", "Diff_1"], b.collect{|a| a.name})
69
- assert_equal([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], b.collect{|a| a.table[1][0].value})
64
+ b = Workbook::Book.open(File.join(File.dirname(__FILE__), "artifacts/simple_sheet_many_sheets.xls"))
65
+ assert_equal(["Diff_10", "Diff_9", "Diff_8", "Diff_7", "Diff_6", "Diff_5", "Diff_4", "Diff_3", "Diff_2", "Diff_1"], b.collect { |a| a.name })
66
+ assert_equal([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], b.collect { |a| a.table[1][0].value })
70
67
  end
71
68
  end
72
69
  end
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
  module Readers
6
5
  class TestXlsShared < Minitest::Test
7
6
  def test_xls_number_to_time
8
7
  w = Workbook::Book.new
9
- assert_equal(DateTime.new(2011,11,15),w.xls_number_to_time(40862))
8
+ assert_equal(DateTime.new(2011, 11, 15), w.xls_number_to_time(40862))
10
9
  end
11
10
  end
12
11
  end
@@ -1,77 +1,84 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
  module Readers
6
5
  class TestXlsxReader < Minitest::Test
7
6
  def test_xlsx_open
8
7
  w = Workbook::Book.new
9
- w.import File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xlsx')
10
- assert_equal([:a, :b, :c, :d, :e],w.sheet.table.header.to_symbols)
11
- assert_equal([:anders,:dit],w[1].table.header.to_symbols)
12
- assert_equal(90588,w.sheet.table[2][:b].value)
13
- assert_equal(DateTime.new(2011,11,15),w.sheet.table[3][:d].value)
8
+ w.import File.join(File.dirname(__FILE__), "artifacts/book_with_tabs_and_colours.xlsx")
9
+ assert_equal([:a, :b, :c, :d, :e], w.sheet.table.header.to_symbols)
10
+ assert_equal([:anders, :dit], w[1].table.header.to_symbols)
11
+ assert_equal(90588, w.sheet.table[2][:b].value)
12
+ assert_equal(DateTime.new(2011, 11, 15), w.sheet.table[3][:d].value)
14
13
  # assert_equal("#CCFFCC",w.sheet.table[3][:c].format[:background_color]) #colour compatibility turned off for now...
15
- #assert_equal(8,w.sheet.table.first[:b].format[:width].round)
14
+ # assert_equal(8,w.sheet.table.first[:b].format[:width].round)
16
15
  # assert_equal(4,w.sheet.table.first[:a].format[:width].round)
17
16
  # assert_equal(25,w.sheet.table.first[:c].format[:width].round)
18
17
  end
18
+
19
19
  def test_open_native_xlsx
20
20
  w = Workbook::Book.new
21
- w.import File.join(File.dirname(__FILE__), 'artifacts/native_xlsx.xlsx')
22
- assert_equal([:datum_gemeld, :adm_gereed, :callnr],w.last.table.header.to_symbols)
23
- assert_equal("Callnr.",w.sheet.table[0][:callnr].value)
24
- assert_equal("2475617.00",w.sheet.table[3][:callnr].value)
25
- assert_equal("2012-12-03T12:30:00+00:00",w.sheet.table[7][:datum_gemeld].value.to_s)
26
- assert_equal("2012-12-03T09:4",w.sheet.table[6][:datum_gemeld].value.to_s[0..14])
21
+ w.import File.join(File.dirname(__FILE__), "artifacts/native_xlsx.xlsx")
22
+ assert_equal([:datum_gemeld, :adm_gereed, :callnr], w.last.table.header.to_symbols)
23
+ assert_equal("Callnr.", w.sheet.table[0][:callnr].value)
24
+ assert_equal("2475617.00", w.sheet.table[3][:callnr].value)
25
+ assert_equal("2012-12-03T12:30:00+00:00", w.sheet.table[7][:datum_gemeld].value.to_s)
26
+ assert_equal("2012-12-03T09:4", w.sheet.table[6][:datum_gemeld].value.to_s[0..14])
27
27
  end
28
+
28
29
  def test_ms_formatting_to_strftime
29
30
  w = Workbook::Book.new
30
- assert_nil(w.ms_formatting_to_strftime(nil));
31
- assert_nil(w.ms_formatting_to_strftime(""));
31
+ assert_nil(w.ms_formatting_to_strftime(nil))
32
+ assert_nil(w.ms_formatting_to_strftime(""))
32
33
  end
34
+
33
35
  def test_open_integer_xlsx
34
- w = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/integer_test.xlsx')
35
- assert_equal("2",w.sheet.table[1][1].value.to_s)
36
- assert_equal(2,w.sheet.table[1][1].value)
36
+ w = Workbook::Book.open File.join(File.dirname(__FILE__), "artifacts/integer_test.xlsx")
37
+ assert_equal("2", w.sheet.table[1][1].value.to_s)
38
+ assert_equal(2, w.sheet.table[1][1].value)
37
39
  end
40
+
38
41
  def test_different_types_xlsx
39
- w = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/excel_different_types.xlsx')
42
+ w = Workbook::Book.open File.join(File.dirname(__FILE__), "artifacts/excel_different_types.xlsx")
40
43
  t = w.sheet.table
41
- assert_equal("ls",t["D4"].value)
42
- assert_equal(true,t["C3"].value)
43
- assert_equal("c",t["C1"].value)
44
- assert_equal(222,t["B3"].value)
45
- assert_equal(4.23,t["C2"].value)
44
+ assert_equal("ls", t["D4"].value)
45
+ assert_equal(true, t["C3"].value)
46
+ assert_equal("c", t["C1"].value)
47
+ assert_equal(222, t["B3"].value)
48
+ assert_equal(4.23, t["C2"].value)
46
49
  assert(t["A4"].value.is_a?(Date))
47
- assert((DateTime.new(2012,1,22,11)-t["A4"].value) < 0.00001)
48
- assert_equal(42000,t["B4"].value)
49
- assert_equal(42000.22323,t["D2"].value)
50
+ assert((DateTime.new(2012, 1, 22, 11) - t["A4"].value) < 0.00001)
51
+ assert_equal(42000, t["B4"].value)
52
+ assert_equal(42000.22323, t["D2"].value)
50
53
  assert(t["A2"].value.is_a?(Date))
51
- assert((Date.new(2012,2,22)-t["A2"].value) < 0.00001)
52
- assert((Date.new(2014,12,27)-t["B2"].value) < 0.00001)
53
- assert_equal(false,t["E2"].value)
54
- assert_equal(true,t["E3"].value)
55
- assert_equal(true,t["E4"].value)
54
+ assert((Date.new(2012, 2, 22) - t["A2"].value) < 0.00001)
55
+ assert((Date.new(2014, 12, 27) - t["B2"].value) < 0.00001)
56
+ assert_equal(false, t["E2"].value)
57
+ assert_equal(true, t["E3"].value)
58
+ assert_equal(true, t["E4"].value)
56
59
  end
60
+
57
61
  def test_skipping_cells
58
- w = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/skippingcells.xlsx')
62
+ w = Workbook::Book.open File.join(File.dirname(__FILE__), "artifacts/skippingcells.xlsx")
59
63
  t = w.sheet.table
60
64
  assert_equal("a,b,c,d,e,f,g,h,i,j,k,l,m,n\n1,,,,,,,,,,,,,\n,2,,,,,,,,,,,,\n,,3,,,,,,,,,,,\n,,,4,,,,,,,,,,\n,,,,5,,,,,,,,,\n,,,,,6,,,,,,,,\n,,,,,,7,,,,,,,\n,,,,,,,8,,,,,,\n,,,,,,,,9,,,,,\n,,,,,,,,,10,,,,\n,,,,,,,,,,11,,,\n,,,,,,,,,,,12,,\n,,,,,,,,,,,,13,\n,,,,,,,,,,,,,14\na,,,,,,,,,,,,,\n,b,,,,,,,,,,,,\n,,c,,,,,,,,,,,\n,,,d,,,,,,,,,,\n,,,,e,,,,,,,,,\n,,,,,f,,,,,,,,\n,,,,,,g,,,,,,,\n,,,,,,,h,,,,,,\n,,,,,,,,i,,,,,\n,,,,,,,,,j,,,,\n,,,,,,,,,,k,,,\n,,,,,,,,,,,l,,\n,,,,,,,,,,,,m,\n,,,,,,,,,,,,,n\n", t.to_csv)
61
65
  end
66
+
62
67
  def test_bit_table_xlsx
63
- b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/bigtable.xlsx')
68
+ b = Workbook::Book.open File.join(File.dirname(__FILE__), "artifacts/bigtable.xlsx")
64
69
  assert_equal(553, b.sheet.table.count)
65
70
  end
71
+
66
72
  def test_xlsx_with_empty_start
67
- b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/xlsx_with_empty_start.xlsx')
73
+ b = Workbook::Book.open File.join(File.dirname(__FILE__), "artifacts/xlsx_with_empty_start.xlsx")
68
74
  t = b.sheet.table
69
75
  assert_nil(t["A3"].value)
70
76
  end
77
+
71
78
  def test_parse_shared_string_file
72
79
  file_contents = "<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"3095\" uniqueCount=\"1241\"><si><t>Nummer</t></si><si><t>Locatie</t></si><si><r><t>ZR 1</t></r><r><rPr><vertAlign val=\"superscript\"/><sz val=\"11\"/><rFont val=\"Calibri\"/><scheme val=\"minor\"/></rPr><t>e</t></r><r><rPr><sz val=\"11\"/><rFont val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></rPr><t xml:space=\"preserve\"> etage</t></r></si><si><t>Kaas</t></si></sst>"
73
80
  result = Workbook::Book.new.parse_shared_string_file(file_contents)
74
- assert_equal(["Nummer", "Locatie", "ZR 1e etage", "Kaas"],result)
81
+ assert_equal(["Nummer", "Locatie", "ZR 1e etage", "Kaas"], result)
75
82
  end
76
83
  end
77
84
  end