Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added integer support #52

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/roo/xls/excel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def cell(row, col, sheet = default_sheet)
end

# returns the type of a cell:
# * :integer
# * :float
# * :string,
# * :date
Expand Down Expand Up @@ -205,6 +206,8 @@ def set_cell_values(sheet, row, col, i, v, value_type, formula, _tr, font)

@cell[sheet][key] =
case value_type
when :integer
v.to_i
when :float
v.to_f
when :string
Expand Down Expand Up @@ -336,8 +339,13 @@ def read_cell(row, idx)
cell = read_cell_content(row, idx)
case cell
when Float, Integer
value_type = :float
value = cell.to_f
if cell.to_i == cell
value_type = :integer
value = cell.to_i
else
value_type = :float
value = cell.to_f
end
when ::Spreadsheet::Link
value_type = :link
value = cell
Expand Down
Binary file modified test/files/simple_spreadsheet_from_italo.xls
Binary file not shown.
8 changes: 4 additions & 4 deletions test/test_roo_excel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_italo_table
assert_equal 1, oo.cell('A', 2).to_i
assert_equal 2, oo.cell('B', 2).to_i
assert_equal 1, oo.cell('C', 2).to_i
assert_equal 1, oo.cell('A', 3)
assert_equal 1.25, oo.cell('A', 3)
assert_equal 3, oo.cell('B', 3)
assert_equal 1, oo.cell('C', 3)
assert_equal 'A', oo.cell('A', 4)
Expand All @@ -215,9 +215,9 @@ def test_italo_table
assert_equal '1:string', oo.cell(2, 3) + ':' + oo.celltype(2, 3).to_s

# Cells values in row 3:
assert_equal '1.0:float', oo.cell(3, 1).to_s + ':' + oo.celltype(3, 1).to_s
assert_equal '3.0:float', oo.cell(3, 2).to_s + ':' + oo.celltype(3, 2).to_s
assert_equal '1.0:float', oo.cell(3, 3).to_s + ':' + oo.celltype(3, 3).to_s
assert_equal '1.25:float', oo.cell(3, 1).to_s + ':' + oo.celltype(3, 1).to_s
assert_equal '3:integer', oo.cell(3, 2).to_s + ':' + oo.celltype(3, 2).to_s
assert_equal '1:integer', oo.cell(3, 3).to_s + ':' + oo.celltype(3, 3).to_s

# Cells values in row 4:
assert_equal 'A:string', oo.cell(4, 1) + ':' + oo.celltype(4, 1).to_s
Expand Down