workbook 0.6 → 0.7
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/workbook/column.rb +13 -1
- data/lib/workbook/format.rb +1 -1
- data/lib/workbook/modules/diff_sort.rb +31 -20
- data/lib/workbook/readers/csv_reader.rb +8 -6
- data/lib/workbook/readers/xls_reader.rb +1 -1
- data/lib/workbook/readers/xlsx_reader.rb +27 -3
- data/lib/workbook/row.rb +11 -3
- data/lib/workbook/table.rb +2 -14
- data/lib/workbook/version.rb +1 -1
- data/test/artifacts/excel_different_types.xlsx +0 -0
- data/test/artifacts/semicolonseparated_in_csv.csv +3 -0
- data/test/artifacts/xlsx_with_empty_start.xlsx +0 -0
- data/test/test_column.rb +11 -0
- data/test/test_readers_csv_reader.rb +4 -0
- data/test/test_readers_txt_reader.rb +1 -1
- data/test/test_readers_xlsx_reader.rb +21 -0
- data/test/test_row.rb +12 -1
- data/test/test_table.rb +0 -13
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6be5061a431a70bb33a5f09f77260bc6b43c806
|
4
|
+
data.tar.gz: c29da70505ab5d7e16820ec96c28600388ed56d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6880c1ea1b7bc8bd49c27a7e19a08ffa74f7e62e628a9dfe4fb81c1a0cac65bc83099d428ec2973d9fc2ea7742a9faa6eb677866050efdbd2c4d2e8616431c3d
|
7
|
+
data.tar.gz: 54a41200b7ec799da9920120426fc2e883d208a1afd1dfdb135c5639316ec499316142b756e2265edf1134bcfb5bb55343d44d82667e04c52f81c63b9e77c0e7
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ Alternatively (more spreadsheet like) you can read cells like this (writing to b
|
|
59
59
|
If you want to use an existing file as a template (which you can create in Excel to create nice looking templates),
|
60
60
|
simply clone the row, and add it back:
|
61
61
|
|
62
|
-
b = Workbook::Book.
|
62
|
+
b = Workbook::Book.open("template.xls")
|
63
63
|
table = b.sheet.table
|
64
64
|
template_row = table[1] # can be any, but I typically have a well
|
65
65
|
# formatted header row + an example template
|
@@ -78,7 +78,7 @@ simply clone the row, and add it back:
|
|
78
78
|
Another typical use case is exporting a list of ActiveRecord-objects to xls (it is assumed that the headers of the excel-table correspond
|
79
79
|
(like "Total order price" and `total_order_price` match) to the headers of the database-table ):
|
80
80
|
|
81
|
-
b = Workbook::Book.
|
81
|
+
b = Workbook::Book.open("template.xls")
|
82
82
|
table = b.sheet.table
|
83
83
|
template_row = table[1] # see above
|
84
84
|
Order.where("created_at > ?", Time.now - 1.week).each do |order|
|
data/lib/workbook/column.rb
CHANGED
@@ -76,6 +76,18 @@ module Workbook
|
|
76
76
|
@default = Cell.new(value)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
class << self
|
80
|
+
# Helps to convert from e.g. "AA" to 26
|
81
|
+
# @param [String] string that typically identifies a column
|
82
|
+
# @return [Integer]
|
83
|
+
def alpha_index_to_number_index string
|
84
|
+
string.upcase!
|
85
|
+
sum = 0
|
86
|
+
string.chars.each_with_index do | char, char_index|
|
87
|
+
sum = sum * 26 + char.unpack('U')[0]-64
|
88
|
+
end
|
89
|
+
return sum-1
|
90
|
+
end
|
91
|
+
end
|
80
92
|
end
|
81
93
|
end
|
data/lib/workbook/format.rb
CHANGED
@@ -52,21 +52,24 @@ module Workbook
|
|
52
52
|
# create an overview of the differences between itself with another 'previous' table, returns a book with a single sheet and table (containing the diffs)
|
53
53
|
#
|
54
54
|
# @return [Workbook::Table] the return result
|
55
|
-
def diff other, options={
|
55
|
+
def diff other, options={}
|
56
|
+
options = {:sort=>true,:ignore_headers=>false}.merge(options)
|
56
57
|
|
57
58
|
aligned = align(other, options)
|
58
59
|
aself = aligned[:self]
|
59
60
|
aother = aligned[:other]
|
61
|
+
|
60
62
|
iteration_cols = []
|
61
63
|
if options[:ignore_headers]
|
62
64
|
iteration_cols = [aother.first.count,aself.first.count].max.times.collect
|
63
65
|
else
|
64
66
|
iteration_cols = (aother.header.to_symbols+aother.header.to_symbols).uniq
|
65
67
|
end
|
68
|
+
|
66
69
|
diff_table = diff_template
|
67
70
|
maxri = (aself.count-1)
|
71
|
+
|
68
72
|
for ri in 0..maxri do
|
69
|
-
row = diff_table[ri]
|
70
73
|
row = diff_table[ri] = Workbook::Row.new(nil, diff_table)
|
71
74
|
srow = aself[ri]
|
72
75
|
orow = aother[ri]
|
@@ -74,24 +77,7 @@ module Workbook
|
|
74
77
|
iteration_cols.each_with_index do |ch, ci|
|
75
78
|
scell = srow[ch]
|
76
79
|
ocell = orow[ch]
|
77
|
-
|
78
|
-
if (scell == ocell)
|
79
|
-
dcell.format = scell.format if scell
|
80
|
-
elsif scell.nil?
|
81
|
-
dcell = Workbook::Cell.new "(was: #{ocell.to_s})"
|
82
|
-
dcell.format = diff_template.template.create_or_find_format_by 'destroyed'
|
83
|
-
elsif ocell.nil?
|
84
|
-
dcell = scell.clone
|
85
|
-
fmt = scell.nil? ? :default : scell.format[:number_format]
|
86
|
-
f = diff_template.template.create_or_find_format_by 'created', fmt
|
87
|
-
f[:number_format] = scell.format[:number_format]
|
88
|
-
dcell.format = f
|
89
|
-
elsif scell != ocell
|
90
|
-
dcell = Workbook::Cell.new "#{scell.to_s} (was: #{ocell.to_s})"
|
91
|
-
f = diff_template.template.create_or_find_format_by 'updated'
|
92
|
-
dcell.format = f
|
93
|
-
end
|
94
|
-
row[ci]=dcell
|
80
|
+
row[ci] = create_diff_cell(scell, ocell)
|
95
81
|
end
|
96
82
|
end
|
97
83
|
if !options[:ignore_headers]
|
@@ -101,6 +87,31 @@ module Workbook
|
|
101
87
|
diff_table
|
102
88
|
end
|
103
89
|
|
90
|
+
# creates a new cell describing the difference between two cells
|
91
|
+
#
|
92
|
+
# @return [Workbook::Cell] the diff cell
|
93
|
+
def create_diff_cell(scell, ocell)
|
94
|
+
dcell = scell.nil? ? Workbook::Cell.new(nil) : scell
|
95
|
+
if (scell == ocell)
|
96
|
+
dcell.format = scell.format if scell
|
97
|
+
elsif scell.nil?
|
98
|
+
dcell = Workbook::Cell.new "(was: #{ocell.to_s})"
|
99
|
+
dcell.format = diff_template.template.create_or_find_format_by 'destroyed'
|
100
|
+
elsif ocell.nil?
|
101
|
+
dcell = scell.clone
|
102
|
+
fmt = scell.nil? ? :default : scell.format[:number_format]
|
103
|
+
f = diff_template.template.create_or_find_format_by 'created', fmt
|
104
|
+
f[:number_format] = scell.format[:number_format]
|
105
|
+
dcell.format = f
|
106
|
+
elsif scell != ocell
|
107
|
+
dcell = Workbook::Cell.new "#{scell.to_s} (was: #{ocell.to_s})"
|
108
|
+
f = diff_template.template.create_or_find_format_by 'updated'
|
109
|
+
dcell.format = f
|
110
|
+
end
|
111
|
+
|
112
|
+
dcell
|
113
|
+
end
|
114
|
+
|
104
115
|
# Return template table to write the diff result in; in case non exists a default is generated.
|
105
116
|
#
|
106
117
|
# @return [Workbook::Table] the empty table, linked to a book
|
@@ -20,16 +20,18 @@ module Workbook
|
|
20
20
|
def parse_csv csv_raw, options={}
|
21
21
|
custom_date_converter = Workbook::Cell.new.string_optimistic_date_converter
|
22
22
|
options = {
|
23
|
-
converters: [:
|
23
|
+
converters: [:all,custom_date_converter]
|
24
24
|
}.merge(options)
|
25
25
|
|
26
26
|
csv=nil
|
27
|
-
|
28
|
-
|
27
|
+
begin
|
28
|
+
csv = csv_lib.parse(csv_raw,options)
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
rescue CSV::MalformedCSVError
|
31
|
+
csv_excel = csv_lib.parse(csv_raw,options.merge({:col_sep=>';'}))
|
32
|
+
csv = csv_excel if csv_excel[0].count > 1
|
33
|
+
|
34
|
+
end
|
33
35
|
|
34
36
|
if csv==nil or csv[0].count == 1
|
35
37
|
csv_excel = csv_lib.parse(csv_raw,options.merge({:col_sep=>';'}))
|
@@ -12,7 +12,7 @@ module Workbook
|
|
12
12
|
sp = Spreadsheet.open(file_obj, 'rb')
|
13
13
|
template.add_raw sp
|
14
14
|
parse_xls sp, options
|
15
|
-
rescue Ole::Storage::FormatError
|
15
|
+
rescue Ole::Storage::FormatError
|
16
16
|
begin
|
17
17
|
# Assuming it is a tab separated txt inside .xls
|
18
18
|
import(file_obj.path, 'txt')
|
@@ -146,29 +146,53 @@ module Workbook
|
|
146
146
|
col
|
147
147
|
end
|
148
148
|
def parse_xlsx_row row
|
149
|
-
|
150
|
-
row = Workbook::Row.new
|
149
|
+
cells_with_pos = row.css('c').collect{|a| parse_xlsx_cell(a)}
|
150
|
+
row = Workbook::Row.new
|
151
|
+
cells_with_pos.each do |cell_with_pos|
|
152
|
+
position = cell_with_pos[:position]
|
153
|
+
col = position.match(/^[A-Z]*/).to_s
|
154
|
+
row[col] = cell_with_pos[:cell]
|
155
|
+
end
|
156
|
+
row = pad_xlsx_row(row)
|
157
|
+
row
|
158
|
+
end
|
159
|
+
|
160
|
+
def pad_xlsx_row(row)
|
161
|
+
row.each_with_index do |cell, index|
|
162
|
+
row[index]=Workbook::Cell.new(nil) if cell.nil? and !cell.is_a?(Workbook::Cell)
|
163
|
+
end
|
164
|
+
row
|
151
165
|
end
|
166
|
+
|
152
167
|
def parse_xlsx_cell cell
|
153
168
|
# style_id = cell.attr('s')
|
154
169
|
# p cell
|
155
170
|
type = cell.attr('t')
|
156
171
|
formatIndex = cell.attr('s').to_i
|
172
|
+
position = cell.attr('r')
|
173
|
+
formula = cell.css('f').text()
|
157
174
|
value = cell.text
|
158
175
|
fmt = template.formats[formatIndex]
|
176
|
+
|
159
177
|
# puts type
|
160
178
|
if type == "n" or type == nil
|
161
179
|
if fmt.derived_type == :date
|
162
180
|
value = xls_number_to_date(value)
|
163
181
|
elsif fmt.derived_type == :time
|
164
182
|
value = xls_number_to_time(value)
|
183
|
+
elsif formula == "TRUE()"
|
184
|
+
value = true
|
185
|
+
elsif formula == "FALSE()"
|
186
|
+
value = false
|
165
187
|
elsif type == "n"
|
166
188
|
value = value.match(/\./) ? value.to_f : value.to_i
|
167
189
|
end
|
168
190
|
elsif type == "s"
|
169
191
|
value = @shared_strings[value.to_i]
|
170
192
|
end
|
171
|
-
Workbook::Cell.new(value, format: fmt)
|
193
|
+
cell = Workbook::Cell.new(value, format: fmt)
|
194
|
+
cell.formula = formula
|
195
|
+
{cell: cell, position: position}
|
172
196
|
end
|
173
197
|
def parse_xlsx
|
174
198
|
end
|
data/lib/workbook/row.rb
CHANGED
@@ -18,8 +18,9 @@ module Workbook
|
|
18
18
|
cells = [] if cells==nil
|
19
19
|
self.table= table
|
20
20
|
cells.each do |c|
|
21
|
-
|
22
|
-
|
21
|
+
if c.is_a? Workbook::Cell
|
22
|
+
c = c.clone if options[:clone_cells]
|
23
|
+
else
|
23
24
|
c = Workbook::Cell.new(c, {row:self})
|
24
25
|
c.parse!(options[:cell_parse_options]) if options[:parse_cells_on_batch_creation]
|
25
26
|
end
|
@@ -91,10 +92,11 @@ module Workbook
|
|
91
92
|
end
|
92
93
|
|
93
94
|
|
94
|
-
# Overrides normal Array's []-function with support for symbols that identify a column based on the header-values
|
95
|
+
# Overrides normal Array's []-function with support for symbols that identify a column based on the header-values and / or
|
95
96
|
#
|
96
97
|
# @example Lookup using fixnum or header value encoded as symbol
|
97
98
|
# row[1] #=> <Cell value="a">
|
99
|
+
# row["A"] #=> <Cell value="a">
|
98
100
|
# row[:a] #=> <Cell value="a">
|
99
101
|
#
|
100
102
|
# @param [Fixnum, Symbol, String] index_or_hash that identifies the column (strings are converted to symbols)
|
@@ -107,6 +109,9 @@ module Workbook
|
|
107
109
|
rescue NoMethodError
|
108
110
|
end
|
109
111
|
return rv
|
112
|
+
elsif index_or_hash.is_a? String and index_or_hash.match(/^[A-Z]*$/)
|
113
|
+
# it looks like a column indicator
|
114
|
+
return to_a[Workbook::Column.alpha_index_to_number_index(index_or_hash)]
|
110
115
|
elsif index_or_hash.is_a? String
|
111
116
|
symbolized = Workbook::Cell.new(index_or_hash, {row:self}).to_sym
|
112
117
|
self[symbolized]
|
@@ -130,6 +135,9 @@ module Workbook
|
|
130
135
|
index = index_or_hash
|
131
136
|
if index_or_hash.is_a? Symbol
|
132
137
|
index = table_header_keys.index(index_or_hash)
|
138
|
+
elsif index_or_hash.is_a? String and index_or_hash.match(/^[A-Z]*$/)
|
139
|
+
# it looks like a column indicator
|
140
|
+
index = Workbook::Column.alpha_index_to_number_index(index_or_hash)
|
133
141
|
elsif index_or_hash.is_a? String
|
134
142
|
symbolized = Workbook::Cell.new(index_or_hash, {row:self}).to_sym
|
135
143
|
index = table_header_keys.index(symbolized)
|
data/lib/workbook/table.rb
CHANGED
@@ -177,7 +177,7 @@ module Workbook
|
|
177
177
|
def [](index_or_string)
|
178
178
|
if index_or_string.is_a? String
|
179
179
|
match = index_or_string.match(/([A-Z]+)([0-9]*)/i)
|
180
|
-
col_index = alpha_index_to_number_index(match[1])
|
180
|
+
col_index = Workbook::Column.alpha_index_to_number_index(match[1])
|
181
181
|
row_index = match[2].to_i - 1
|
182
182
|
return self[row_index][col_index]
|
183
183
|
elsif index_or_string.is_a? Range
|
@@ -201,7 +201,7 @@ module Workbook
|
|
201
201
|
def []= (index_or_string, new_value)
|
202
202
|
if index_or_string.is_a? String
|
203
203
|
match = index_or_string.upcase.match(/([A-Z]*)([0-9]*)/)
|
204
|
-
cell_index = alpha_index_to_number_index(match[1])
|
204
|
+
cell_index = Workbook::Column.alpha_index_to_number_index(match[1])
|
205
205
|
row_index = match[2].to_i - 1
|
206
206
|
self[row_index][cell_index].value = new_value
|
207
207
|
else
|
@@ -212,18 +212,6 @@ module Workbook
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
-
# Helps to convert from e.g. "AA" to 26
|
216
|
-
# @param [String] string that typically identifies a column
|
217
|
-
# @return [Integer]
|
218
|
-
def alpha_index_to_number_index string
|
219
|
-
string.upcase!
|
220
|
-
sum = 0
|
221
|
-
string.chars.each_with_index do | char, char_index|
|
222
|
-
sum = sum * 26 + char.unpack('U')[0]-64
|
223
|
-
end
|
224
|
-
return sum-1
|
225
|
-
end
|
226
|
-
|
227
215
|
# remove all the trailing empty-rows (returning a trimmed clone)
|
228
216
|
#
|
229
217
|
# @param [Integer] desired_row_length of the rows
|
data/lib/workbook/version.rb
CHANGED
Binary file
|
@@ -0,0 +1,3 @@
|
|
1
|
+
artikel;aantal;bedrag;reservering;aanmaaktijd_reservering;gastnummer;titel;voorletters;tussenvoegsels;naam;straat;huisnummer;postcode;woonplaats;email;tel_land;tel_net;tel_abon
|
2
|
+
"Vriend - € 50";1;50.00;123;2016-10-27;7891;asdf;A.;;asdf;"asdf ";55;"1234 LM";AMSTERDAM;a@example.com;053;;123123
|
3
|
+
"Vriend - € 35";1;35.00;123;2016-11-02;5676;"Dasdfr";B.;;asdf;"asdf asdf";12;"1234 NN";UTRECHT;b@example.com;+31;074;123123
|
Binary file
|
data/test/test_column.rb
CHANGED
@@ -51,4 +51,15 @@ class TestColumn < Minitest::Test
|
|
51
51
|
t[2].delete_at(3)
|
52
52
|
assert_equal([:boolean, :float, :string, :integer], t.columns.collect{|a| a.column_type})
|
53
53
|
end
|
54
|
+
|
55
|
+
def test_alpha_index_to_number_index
|
56
|
+
assert_equal(0,Workbook::Column.alpha_index_to_number_index("A"))
|
57
|
+
assert_equal(2,Workbook::Column.alpha_index_to_number_index("C"))
|
58
|
+
assert_equal(25,Workbook::Column.alpha_index_to_number_index("Z"))
|
59
|
+
assert_equal(26,Workbook::Column.alpha_index_to_number_index("AA"))
|
60
|
+
assert_equal(27,Workbook::Column.alpha_index_to_number_index("AB"))
|
61
|
+
assert_equal(51,Workbook::Column.alpha_index_to_number_index("AZ"))
|
62
|
+
assert_equal(52,Workbook::Column.alpha_index_to_number_index("BA"))
|
63
|
+
assert_equal((27*26)-1,Workbook::Column.alpha_index_to_number_index("ZZ"))
|
64
|
+
end
|
54
65
|
end
|
@@ -99,5 +99,9 @@ module Readers
|
|
99
99
|
w = Workbook::Book.read("2013-03-19,JV,211,032,1,DBG A,,13,0147,\n", :csv, {converters: []})
|
100
100
|
assert_equal("2013-03-19,JV,211,032,1,DBG A,,13,0147,\n",w.sheet.table.to_csv)
|
101
101
|
end
|
102
|
+
def test_semi_colon_separated_csv
|
103
|
+
w = Workbook::Book.open(File.join(File.dirname(__FILE__), 'artifacts/semicolonseparated_in_csv.csv'))
|
104
|
+
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)
|
105
|
+
end
|
102
106
|
end
|
103
107
|
end
|
@@ -39,7 +39,7 @@ module Readers
|
|
39
39
|
assert_equal(Date.new(2012,2,22),w.sheet.table[1][:a].value)
|
40
40
|
assert_equal("c",w.sheet.table[2][:a].value)
|
41
41
|
assert_equal(DateTime.new(2012,1,22,11),w.sheet.table[3][:a].value)
|
42
|
-
assert_equal(42000,w.sheet.table[3][:b].value)
|
42
|
+
assert_equal("42000",w.sheet.table[3][:b].value.to_s)
|
43
43
|
assert_nil(w.sheet.table[2][:c].value)
|
44
44
|
end
|
45
45
|
|
@@ -33,9 +33,30 @@ module Readers
|
|
33
33
|
assert_equal("2",w.sheet.table[1][1].value.to_s)
|
34
34
|
assert_equal(2,w.sheet.table[1][1].value)
|
35
35
|
end
|
36
|
+
def test_different_types_xlsx
|
37
|
+
w = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/excel_different_types.xlsx')
|
38
|
+
t = w.sheet.table
|
39
|
+
assert_equal("ls",t["D4"].value)
|
40
|
+
assert_equal(true,t["C3"].value)
|
41
|
+
assert_equal("c",t["C1"].value)
|
42
|
+
assert_equal(222,t["B3"].value)
|
43
|
+
assert_equal(4.23,t["C2"].value)
|
44
|
+
assert(t["A4"].value.is_a?(Date))
|
45
|
+
assert((DateTime.new(2012,1,22,11)-t["A4"].value) < 0.00001)
|
46
|
+
assert_equal(42000,t["B4"].value)
|
47
|
+
assert_equal(42000.22323,t["D2"].value)
|
48
|
+
assert(t["A2"].value.is_a?(Date))
|
49
|
+
assert((Date.new(2012,2,22)-t["A2"].value) < 0.00001)
|
50
|
+
assert((Date.new(2014,12,27)-t["B2"].value) < 0.00001)
|
51
|
+
end
|
36
52
|
def test_bit_table_xlsx
|
37
53
|
b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/bigtable.xlsx')
|
38
54
|
assert_equal(553, b.sheet.table.count)
|
39
55
|
end
|
56
|
+
def test_xlsx_with_empty_start
|
57
|
+
b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/xlsx_with_empty_start.xlsx')
|
58
|
+
t = b.sheet.table
|
59
|
+
assert_nil(t["A3"].value)
|
60
|
+
end
|
40
61
|
end
|
41
62
|
end
|
data/test/test_row.rb
CHANGED
@@ -244,13 +244,22 @@ class TestRow < Minitest::Test
|
|
244
244
|
row[1]= 12
|
245
245
|
assert_equal(12, table.last["b"])
|
246
246
|
assert_nil(table.last["a"])
|
247
|
+
end
|
247
248
|
|
249
|
+
def test_find_by_column_string
|
250
|
+
b = Workbook::Book.new
|
251
|
+
table = b.sheet.table
|
252
|
+
table << Workbook::Row.new(["b","a"])
|
253
|
+
row = Workbook::Row.new([],table)
|
254
|
+
row[1]= 12
|
255
|
+
assert_equal(12, table.last["B"])
|
256
|
+
assert_nil(table.last["A"])
|
248
257
|
end
|
249
258
|
|
250
259
|
def test_row_hash_index_string_assignment
|
251
260
|
b = Workbook::Book.new
|
252
261
|
table = b.sheet.table
|
253
|
-
table << Workbook::Row.new(["a","b"])
|
262
|
+
table << Workbook::Row.new(["a","b","d"])
|
254
263
|
row = Workbook::Row.new([],table)
|
255
264
|
row[1]= 12
|
256
265
|
assert_equal(12, table.last.last.value)
|
@@ -258,6 +267,8 @@ class TestRow < Minitest::Test
|
|
258
267
|
assert_equal(15, table.last.last.value)
|
259
268
|
row["b"]= 18
|
260
269
|
assert_equal(18, table.last.last.value)
|
270
|
+
row["C"]= 2
|
271
|
+
assert_equal(2, table.last[2].value)
|
261
272
|
end
|
262
273
|
|
263
274
|
def test_trim!
|
data/test/test_table.rb
CHANGED
@@ -111,19 +111,6 @@ class TestTable< Minitest::Test
|
|
111
111
|
assert_equal(4,t["B4"].value)
|
112
112
|
end
|
113
113
|
|
114
|
-
def test_alpha_index_to_number_index
|
115
|
-
w = Workbook::Book.new
|
116
|
-
t = w.sheet.table
|
117
|
-
assert_equal(0,t.alpha_index_to_number_index("A"))
|
118
|
-
assert_equal(2,t.alpha_index_to_number_index("C"))
|
119
|
-
assert_equal(25,t.alpha_index_to_number_index("Z"))
|
120
|
-
assert_equal(26,t.alpha_index_to_number_index("AA"))
|
121
|
-
assert_equal(27,t.alpha_index_to_number_index("AB"))
|
122
|
-
assert_equal(51,t.alpha_index_to_number_index("AZ"))
|
123
|
-
assert_equal(52,t.alpha_index_to_number_index("BA"))
|
124
|
-
assert_equal((27*26)-1,t.alpha_index_to_number_index("ZZ"))
|
125
|
-
end
|
126
|
-
|
127
114
|
def test_multirowselect_through_collections
|
128
115
|
w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
|
129
116
|
t = w.sheet.table
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maarten Brouwers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-prof
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- test/artifacts/heavy.xlsx
|
200
200
|
- test/artifacts/integer_test.xlsx
|
201
201
|
- test/artifacts/native_xlsx.xlsx
|
202
|
+
- test/artifacts/semicolonseparated_in_csv.csv
|
202
203
|
- test/artifacts/sheet_with_combined_cells.ods
|
203
204
|
- test/artifacts/sheetduplication.xls
|
204
205
|
- test/artifacts/simple_csv.csv
|
@@ -209,6 +210,7 @@ files:
|
|
209
210
|
- test/artifacts/simple_sheet_many_sheets.xls
|
210
211
|
- test/artifacts/txt_in_xls.xls
|
211
212
|
- test/artifacts/xls_with_txt_extension.txt
|
213
|
+
- test/artifacts/xlsx_with_empty_start.xlsx
|
212
214
|
- test/artifacts/zip_in_xls.xls
|
213
215
|
- test/helper.rb
|
214
216
|
- test/test_book.rb
|
@@ -278,6 +280,7 @@ test_files:
|
|
278
280
|
- test/artifacts/heavy.xlsx
|
279
281
|
- test/artifacts/integer_test.xlsx
|
280
282
|
- test/artifacts/native_xlsx.xlsx
|
283
|
+
- test/artifacts/semicolonseparated_in_csv.csv
|
281
284
|
- test/artifacts/sheet_with_combined_cells.ods
|
282
285
|
- test/artifacts/sheetduplication.xls
|
283
286
|
- test/artifacts/simple_csv.csv
|
@@ -288,6 +291,7 @@ test_files:
|
|
288
291
|
- test/artifacts/simple_sheet_many_sheets.xls
|
289
292
|
- test/artifacts/txt_in_xls.xls
|
290
293
|
- test/artifacts/xls_with_txt_extension.txt
|
294
|
+
- test/artifacts/xlsx_with_empty_start.xlsx
|
291
295
|
- test/artifacts/zip_in_xls.xls
|
292
296
|
- test/helper.rb
|
293
297
|
- test/test_book.rb
|