workbook 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/workbook/readers/xls_reader.rb +13 -3
- data/lib/workbook/writers/csv_table_writer.rb +1 -1
- data/readme.markdown +2 -2
- data/test/artifacts/book_with_tabs_and_colours.xls +0 -0
- data/test/artifacts/excel_different_types.csv +4 -0
- data/test/artifacts/excel_different_types.txt +0 -0
- data/test/artifacts/excel_different_types.xls +0 -0
- data/test/artifacts/excel_different_types.xlsx +0 -0
- data/test/artifacts/simple_sheet.xls +0 -0
- data/test/artifacts/{medewerkers.xls → txt_in_xls.xls} +0 -0
- data/test/artifacts/zip_in_xls.xls +0 -0
- data/test/test_modules_table_diff_sort.rb +0 -15
- data/test/test_readers_csv_reader.rb +16 -0
- data/test/test_readers_txt_reader.rb +14 -34
- data/test/test_readers_xls_reader.rb +41 -6
- data/test/test_writers_xls_writer.rb +2 -3
- data/workbook.gemspec +2 -2
- metadata +15 -5
@@ -74,9 +74,19 @@ module Workbook
|
|
74
74
|
|
75
75
|
|
76
76
|
def load_xls file_obj
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
begin
|
78
|
+
sp = Spreadsheet.open(file_obj, mode='rb')
|
79
|
+
template.add_raw sp
|
80
|
+
parse_xls sp
|
81
|
+
rescue Ole::Storage::FormatError => e
|
82
|
+
begin
|
83
|
+
# Assuming it is a tab separated txt inside .xls
|
84
|
+
open(file_obj.path, 'txt')
|
85
|
+
rescue
|
86
|
+
raise e
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
80
90
|
end
|
81
91
|
|
82
92
|
|
data/readme.markdown
CHANGED
@@ -74,7 +74,7 @@ To some extent, sort_by works, it doesn't, however, adhere to the header setting
|
|
74
74
|
|
75
75
|
### Comparing tables
|
76
76
|
|
77
|
-
Simply call
|
77
|
+
Simply call on a Workbook::Table
|
78
78
|
|
79
79
|
t1.diff t2
|
80
80
|
|
@@ -86,7 +86,7 @@ Currently writing is limited to the following formats. Templating support is sti
|
|
86
86
|
|
87
87
|
b.to_xls # returns a spreadsheet workbook
|
88
88
|
b.write_to_xls filename # writes to filename
|
89
|
-
t.to_csv # returns a csv-string
|
89
|
+
t.to_csv # returns a csv-string (called on tables)
|
90
90
|
|
91
91
|
In case you want to display the table in HTML, some conversion is offered to convert text/background properties to css-entities. Internally the hash storing style elements tries to map to CSS where possible.
|
92
92
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
Binary file
|
@@ -101,20 +101,5 @@ module Modules
|
|
101
101
|
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n3,3 (was: 2),3,4\n4,2,3,4\n(was: 5),(was: 2),(was: 3),(was: 4)\n",diff_result.sheet.table.to_csv)
|
102
102
|
diff_result.write_to_xls({:rewrite_header=>true})
|
103
103
|
end
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
def test_diff_xls
|
108
|
-
(1..8).each do |index|
|
109
|
-
prev = "test/artifacts/compare#{index}_prev.xls"
|
110
|
-
curr = "test/artifacts/compare#{index}_current.xls"
|
111
|
-
|
112
|
-
wprev=Workbook::Book.open prev
|
113
|
-
wcurr=Workbook::Book.open curr
|
114
|
-
|
115
|
-
diff = wcurr.sheet.table.diff wprev.sheet.table
|
116
|
-
diff.write_to_xls({:filename=>"compare#{index}.xls"})
|
117
|
-
end
|
118
|
-
end
|
119
104
|
end
|
120
105
|
end
|
@@ -33,5 +33,21 @@ module Readers
|
|
33
33
|
assert_equal("6/12 ovk getekend terugontv.+>acq ter tekening. 13/12 ovk getekend terugontv.+>Fred ter tekening.", w.sheet.table[5][:b].value)
|
34
34
|
assert_equal(Date.new(2012,6,12),w.sheet.table[5][:c].value)
|
35
35
|
end
|
36
|
+
def test_excel_standardized_open
|
37
|
+
w = Workbook::Book.new
|
38
|
+
w.open("test/artifacts/excel_different_types.csv")
|
39
|
+
# reads
|
40
|
+
# a,b,c,d
|
41
|
+
# 2012-02-22,2014-12-27,2012-11-23,2012-11-12T04:20:00+00:00
|
42
|
+
# c,222.0,,0027-12-14T05:21:00+00:00
|
43
|
+
# 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
|
44
|
+
|
45
|
+
assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
|
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)
|
50
|
+
assert_equal(nil,w.sheet.table[2][:c].value)
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
@@ -7,42 +7,22 @@ module Readers
|
|
7
7
|
# w.open("test/artifacts/xls_with_txt_extension.txt")
|
8
8
|
# puts w.sheet.table
|
9
9
|
# end
|
10
|
-
|
10
|
+
|
11
|
+
def test_excel_standardized_open
|
11
12
|
w = Workbook::Book.new
|
12
|
-
w.open("test/artifacts/
|
13
|
+
w.open("test/artifacts/excel_different_types.txt")
|
13
14
|
# reads
|
14
|
-
# a
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
assert_equal([:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
:algehele_indruk,
|
26
|
-
:gemaakt_door,
|
27
|
-
:gemaakt,
|
28
|
-
:titel,
|
29
|
-
:toelichting,
|
30
|
-
:gewenste_migratie_maand,
|
31
|
-
:plek_ing_balie,
|
32
|
-
:plek_tnt_balie,
|
33
|
-
:alternatieve_locaties,
|
34
|
-
:datum_introductie_gesprek,
|
35
|
-
:geen_aanbod_voor_isp,
|
36
|
-
:oplevering_geslaagd_op,
|
37
|
-
:nazorgpunten,
|
38
|
-
:locatie],w.sheet.table.header.to_symbols)
|
39
|
-
assert_equal(Date.new(2011,11,01),w.sheet.table[29][:gewenste_migratie_maand].value)
|
40
|
-
assert_equal("Belt , G (Gerrit)",w.sheet.table[1][:gemaakt_door].value)
|
41
|
-
assert_equal(false,w.sheet.table[1][:geen_aanbod_voor_isp].value)
|
42
|
-
assert_equal(DateTime.new(2011,7,25,11,02),w.sheet.table[4][:gemaakt].value)
|
43
|
-
assert_equal("Roggeveen , PC (Peter)",w.sheet.table[4][:gemaakt_door].value)
|
44
|
-
assert_equal("Groeneveld, R (René)",w.sheet.table[400][:gemaakt_door].value)
|
45
|
-
assert_equal(24208,w.sheet.table[7][:locatie].value)
|
15
|
+
# a,b,c,d
|
16
|
+
# 2012-02-22,2014-12-27,2012-11-23,2012-11-12T04:20:00+00:00
|
17
|
+
# c,222.0,,0027-12-14T05:21:00+00:00
|
18
|
+
# 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
|
19
|
+
|
20
|
+
assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
|
21
|
+
assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
|
22
|
+
assert_equal("c",w.sheet.table[2][:a].value)
|
23
|
+
assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
|
24
|
+
assert_equal(42000,w.sheet.table[3][:b].value)
|
25
|
+
assert_equal(nil,w.sheet.table[2][:c].value)
|
46
26
|
end
|
47
27
|
|
48
28
|
end
|
@@ -4,12 +4,12 @@ module Readers
|
|
4
4
|
def test_open
|
5
5
|
w = Workbook::Book.new
|
6
6
|
w.open 'test/artifacts/book_with_tabs_and_colours.xls'
|
7
|
-
assert_equal([:
|
8
|
-
assert_equal(90588,w.sheet.table[2][:
|
9
|
-
assert_equal("#CCFFCC",w.sheet.table[3][:
|
10
|
-
assert_equal(8.13671875,w.sheet.table.first[:
|
11
|
-
assert_equal(3.85546875,w.sheet.table.first[:
|
12
|
-
assert_equal(25.14453125,w.sheet.table.first[:
|
7
|
+
assert_equal([:a, :b, :c, :d, :e],w.sheet.table.header.to_symbols)
|
8
|
+
assert_equal(90588,w.sheet.table[2][:b].value)
|
9
|
+
assert_equal("#CCFFCC",w.sheet.table[3][:c].format[:background_color])
|
10
|
+
assert_equal(8.13671875,w.sheet.table.first[:b].format[:width])
|
11
|
+
assert_equal(3.85546875,w.sheet.table.first[:a].format[:width])
|
12
|
+
assert_equal(25.14453125,w.sheet.table.first[:c].format[:width])
|
13
13
|
|
14
14
|
|
15
15
|
end
|
@@ -22,5 +22,40 @@ module Readers
|
|
22
22
|
assert_equal("sadfasdfsd", w.sheet.table[4][2].value)
|
23
23
|
assert_equal(1.2, w.sheet.table[3][1].value)
|
24
24
|
end
|
25
|
+
|
26
|
+
def test_excel_standardized_open
|
27
|
+
w = Workbook::Book.new
|
28
|
+
w.open("test/artifacts/excel_different_types.xls")
|
29
|
+
# reads
|
30
|
+
# a,b,c,d
|
31
|
+
# 2012-02-22,2014-12-27,2012-11-23,2012-11-12T04:20:00+00:00
|
32
|
+
# c,222.0,,0027-12-14T05:21:00+00:00
|
33
|
+
# 2012-01-22T11:00:00+00:00,42000.0,"goh, idd",ls
|
34
|
+
|
35
|
+
assert_equal([:a,:b,:c, :d],w.sheet.table.header.to_symbols)
|
36
|
+
assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
|
37
|
+
assert_equal("c",w.sheet.table[2][:a].value)
|
38
|
+
assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
|
39
|
+
assert_equal(42000,w.sheet.table[3][:b].value)
|
40
|
+
assert_equal(nil,w.sheet.table[2][:c].value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_txt_in_xls_open
|
44
|
+
w = Workbook::Book.new
|
45
|
+
w.open("test/artifacts/txt_in_xls.xls")
|
46
|
+
assert_equal([:naam,:nummer,:ilt,:corporate_key,:naam_medewerker, nil, nil, :telefoon, :openingsdatum],w.sheet.table.header.to_symbols)
|
47
|
+
assert_equal(["dddd",2222,"i9000","asd","Anita",nil,"Betera",DateTime.new(2012,1,12),Date.new(2011,10,5)],w.sheet.table[1].collect{|a| a.value})
|
48
|
+
end
|
49
|
+
def test_zip_in_xls_open
|
50
|
+
w = Workbook::Book.new
|
51
|
+
failed_properly = false
|
52
|
+
begin
|
53
|
+
w.open("test/artifacts/zip_in_xls.xls")
|
54
|
+
w.sheet.table.to_csv
|
55
|
+
rescue Ole::Storage::FormatError
|
56
|
+
failed_properly = true
|
57
|
+
end
|
58
|
+
assert_equal(true,failed_properly)
|
59
|
+
end
|
25
60
|
end
|
26
61
|
end
|
@@ -15,11 +15,10 @@ module Writers
|
|
15
15
|
|
16
16
|
def test_roundtrip
|
17
17
|
b = Workbook::Book.open('test/artifacts/simple_sheet.xls')
|
18
|
-
assert_equal(3.85546875,b.sheet.table.first[:
|
18
|
+
assert_equal(3.85546875,b.sheet.table.first[:a].format[:width])
|
19
19
|
filename = b.write_to_xls
|
20
20
|
b = Workbook::Book.open filename
|
21
|
-
assert_equal(3.85546875,b.sheet.table.first[:
|
22
|
-
|
21
|
+
assert_equal(3.85546875,b.sheet.table.first[:a].format[:width])
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_init_spreadsheet_template
|
data/workbook.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "workbook"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'workbook'
|
7
7
|
s.rubyforge_project = 'workbook'
|
8
|
-
s.version = '0.1.
|
9
|
-
s.date = '2012-
|
8
|
+
s.version = '0.1.2'
|
9
|
+
s.date = '2012-11-12'
|
10
10
|
s.summary = "Workbook is a datastructure to contain books of tables (an anlogy used in e.g. Excel)"
|
11
11
|
s.description = "Workbook contains workbooks, as in a table, contains rows, contains cells, reads/writes excels and csv's and tab separated, and offers basic diffing and sorting capabilities."
|
12
12
|
s.authors = ["Maarten Brouwers"]
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Maarten Brouwers
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-11-12 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -89,11 +89,16 @@ files:
|
|
89
89
|
- readme.markdown
|
90
90
|
- test/artifacts/book_with_tabs_and_colours.xls
|
91
91
|
- test/artifacts/complex_types.xls
|
92
|
-
- test/artifacts/
|
92
|
+
- test/artifacts/excel_different_types.csv
|
93
|
+
- test/artifacts/excel_different_types.txt
|
94
|
+
- test/artifacts/excel_different_types.xls
|
95
|
+
- test/artifacts/excel_different_types.xlsx
|
93
96
|
- test/artifacts/simple_csv.csv
|
94
97
|
- test/artifacts/simple_excel_csv.csv
|
95
98
|
- test/artifacts/simple_sheet.xls
|
99
|
+
- test/artifacts/txt_in_xls.xls
|
96
100
|
- test/artifacts/xls_with_txt_extension.txt
|
101
|
+
- test/artifacts/zip_in_xls.xls
|
97
102
|
- test/helper.rb
|
98
103
|
- test/test_book.rb
|
99
104
|
- test/test_cell.rb
|
@@ -143,11 +148,16 @@ summary: Workbook is a datastructure to contain books of tables (an anlogy used
|
|
143
148
|
test_files:
|
144
149
|
- test/artifacts/book_with_tabs_and_colours.xls
|
145
150
|
- test/artifacts/complex_types.xls
|
146
|
-
- test/artifacts/
|
151
|
+
- test/artifacts/excel_different_types.csv
|
152
|
+
- test/artifacts/excel_different_types.txt
|
153
|
+
- test/artifacts/excel_different_types.xls
|
154
|
+
- test/artifacts/excel_different_types.xlsx
|
147
155
|
- test/artifacts/simple_csv.csv
|
148
156
|
- test/artifacts/simple_excel_csv.csv
|
149
157
|
- test/artifacts/simple_sheet.xls
|
158
|
+
- test/artifacts/txt_in_xls.xls
|
150
159
|
- test/artifacts/xls_with_txt_extension.txt
|
160
|
+
- test/artifacts/zip_in_xls.xls
|
151
161
|
- test/helper.rb
|
152
162
|
- test/test_book.rb
|
153
163
|
- test/test_cell.rb
|