Skip to content

Commit

Permalink
Merge pull request #580 from patrickkulling/fix/open-office-boolean-g…
Browse files Browse the repository at this point in the history
…oogle-sheets

Add support for boolean values in open office files coming from Google Sheets
  • Loading branch information
patrickkulling authored Feb 7, 2023
2 parents 92634fb + ab4a73e commit 13677da
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased
- Fix gsub! usage for open office documents on a frozen string [580](https://github.com/roo-rb/roo/pull/580)
- Fix gsub! usage for open office documents on a frozen string [581](https://github.com/roo-rb/roo/pull/581)
- Add support for boolean values in open office files that were generated via Google Sheets [580](https://github.com/roo-rb/roo/pull/580)

### Changed/Added
- Roo::Base#each_with_pagename returns Enumerator Object [576](https://github.com/roo-rb/roo/pull/576)
Expand Down
5 changes: 4 additions & 1 deletion lib/roo/open_office.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ def set_cell_values(sheet, x, y, i, v, value_type, formula, table_cell, str_v, s
@style[sheet][key] = style_name
case @cell_type[sheet][key]
when :float
@cell[sheet][key] = (table_cell.attributes['value'].to_s.include?(".") || table_cell.children.first.text.include?(".")) ? v.to_f : v.to_i
value = (table_cell.attributes['value'].to_s.include?(".") || table_cell.children.first.text.include?(".")) ? v.to_f : v.to_i
value = 'true' if formula == '=TRUE()'
value = 'false' if formula == '=FALSE()'
@cell[sheet][key] = value
when :percentage
@cell[sheet][key] = v.to_f
when :string
Expand Down
Binary file added test/files/boolean-from-google-sheets.ods
Binary file not shown.
Binary file added test/files/boolean-from-google-sheets.xlsx
Binary file not shown.
18 changes: 18 additions & 0 deletions test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,24 @@ def test_cell_boolean
end
end

def test_cell_boolean_from_google_sheets
with_each_spreadsheet(:name=>'boolean-from-google-sheets', :format=>[:openoffice, :excelx]) do |oo|
if oo.class == Roo::Excelx
assert_equal true, oo.cell(1, 1), "failure in #{oo.class}"
assert_equal false, oo.cell(2, 1), "failure in #{oo.class}"

cell = oo.sheet_for(oo.default_sheet).cells[[1, 1,]]
assert_equal 'TRUE', cell.formatted_value

cell = oo.sheet_for(oo.default_sheet).cells[[2, 1,]]
assert_equal 'FALSE', cell.formatted_value
else
assert_equal "true", oo.cell(1,1), "failure in #{oo.class}"
assert_equal "false", oo.cell(2,1), "failure in #{oo.class}"
end
end
end

def test_cell_multiline
with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excelx]) do |oo|
assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
Expand Down

0 comments on commit 13677da

Please sign in to comment.