aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2023-02-08 00:39:56 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2023-02-08 00:39:56 -0500
commitae103e148eb3c15606b816505492d870ef062ad3 (patch)
treeb7916225d76ac8d1db28feff7aa46a4ee672b3dc
parentf5fb17e5a64b215644bc104f099dad8c2f10c37d (diff)
downloadruby-roo-upstream.tar.bz2
ruby-roo-upstream.tar.xz
ruby-roo-upstream.tar.zst
New upstream version 2.10.0.upstream/2.10.0upstream
-rw-r--r--.github/workflows/pull-request.yml15
-rw-r--r--CHANGELOG.md9
-rw-r--r--README.md2
-rw-r--r--lib/roo/base.rb6
-rw-r--r--lib/roo/excelx/cell/number.rb10
-rwxr-xr-xlib/roo/excelx/sheet_doc.rb17
-rw-r--r--lib/roo/excelx/workbook.rb1
-rw-r--r--lib/roo/open_office.rb7
-rw-r--r--lib/roo/version.rb2
-rw-r--r--spec/lib/roo/base_spec.rb8
-rwxr-xr-xspec/lib/roo/excelx_spec.rb35
-rw-r--r--test/files/apostrophe.odsbin0 -> 8583 bytes
-rw-r--r--test/files/boolean-from-google-sheets.odsbin0 -> 8099 bytes
-rw-r--r--test/files/boolean-from-google-sheets.xlsxbin0 -> 4665 bytes
-rw-r--r--test/files/currency-euro.xlsxbin0 -> 499104 bytes
-rw-r--r--test/files/currency-uk.xlsxbin0 -> 499099 bytes
-rw-r--r--test/files/currency-us.xlsxbin0 -> 499043 bytes
-rw-r--r--test/files/frozen_string.odsbin0 -> 1219 bytes
-rw-r--r--test/files/implicit_coordinates.xlsxbin0 -> 4405 bytes
-rw-r--r--test/files/wrong_coordinates.xlsxbin0 -> 11327 bytes
-rw-r--r--test/roo/test_excelx.rb9
-rw-r--r--test/test_roo.rb30
22 files changed, 141 insertions, 10 deletions
diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml
new file mode 100644
index 0000000..9d94c4b
--- /dev/null
+++ b/.github/workflows/pull-request.yml
@@ -0,0 +1,15 @@
+name: Changelog
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
+
+jobs:
+ changelog:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: amoniacou/changelog-enforcer@v1.4.0
+ with:
+ changeLogPath: 'CHANGELOG.md'
+ skipLabel: 'Skip-Changelog'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eaa98ab..30a4704 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
## Unreleased
+### Changed/Added
+
+## [2.10.0] 2023-02-07
+
+### Changed/Added
+- 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)
+- Roo::Base#each_with_pagename returns Enumerator Object [576](https://github.com/roo-rb/roo/pull/576)
+
## [2.9.0] 2022-03-19
### Changed/Added
diff --git a/README.md b/README.md
index ceb54f6..021afb4 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Install as a gem
Or add it to your Gemfile
```ruby
-gem "roo", "~> 2.8.0"
+gem "roo", "~> 2.9.0"
```
## Usage
diff --git a/lib/roo/base.rb b/lib/roo/base.rb
index f4ac9a3..91c8d1c 100644
--- a/lib/roo/base.rb
+++ b/lib/roo/base.rb
@@ -250,8 +250,10 @@ class Roo::Base
# iterate through all worksheets of a document
def each_with_pagename
- sheets.each do |s|
- yield sheet(s, true)
+ Enumerator.new do |yielder|
+ sheets.each do |s|
+ yielder << sheet(s, true)
+ end
end
end
diff --git a/lib/roo/excelx/cell/number.rb b/lib/roo/excelx/cell/number.rb
index 7ea48b5..5cd9b55 100644
--- a/lib/roo/excelx/cell/number.rb
+++ b/lib/roo/excelx/cell/number.rb
@@ -66,6 +66,16 @@ module Roo
when '##0.0E+0' then '%.1E'
when "_-* #,##0.00\\ _€_-;\\-* #,##0.00\\ _€_-;_-* \"-\"??\\ _€_-;_-@_-" then number_format('%.2f', '-%.2f')
when '@' then proc { |number| number }
+ when /^(?:_\()?"([^"]*)"(?:\* )?([^_]+)/
+ proc do |number|
+ formatted_number = generate_formatter($2).call(number)
+ "#{$1}#{formatted_number}"
+ end
+ when /^_[- \(]\[\$([^-]*)[^#@]+([^_]+)/
+ proc do |number|
+ formatted_number = generate_formatter($2).call(number)
+ "#{$1}#{formatted_number}"
+ end
else
raise "Unknown format: #{format.inspect}"
end
diff --git a/lib/roo/excelx/sheet_doc.rb b/lib/roo/excelx/sheet_doc.rb
index adbb77a..7a09725 100755
--- a/lib/roo/excelx/sheet_doc.rb
+++ b/lib/roo/excelx/sheet_doc.rb
@@ -211,10 +211,19 @@ module Roo
extracted_cells = {}
empty_cell = @options[:empty_cell]
- doc.xpath('/worksheet/sheetData/row/c').each do |cell_xml|
- coordinate = ::Roo::Utils.extract_coordinate(cell_xml["r"])
- cell = cell_from_xml(cell_xml, hyperlinks(relationships)[coordinate], coordinate, empty_cell)
- extracted_cells[coordinate] = cell if cell
+ doc.xpath('/worksheet/sheetData/row').each.with_index(1) do |row_xml, ycoord|
+ row_xml.xpath('c').each.with_index(1) do |cell_xml, xcoord|
+ r = cell_xml['r']
+ coordinate =
+ if r.nil?
+ ::Roo::Excelx::Coordinate.new(ycoord, xcoord)
+ else
+ ::Roo::Utils.extract_coordinate(r)
+ end
+
+ cell = cell_from_xml(cell_xml, hyperlinks(relationships)[coordinate], coordinate, empty_cell)
+ extracted_cells[coordinate] = cell if cell
+ end
end
expand_merged_ranges(extracted_cells) if @options[:expand_merged_ranges]
diff --git a/lib/roo/excelx/workbook.rb b/lib/roo/excelx/workbook.rb
index c21bb1f..aba5720 100644
--- a/lib/roo/excelx/workbook.rb
+++ b/lib/roo/excelx/workbook.rb
@@ -32,6 +32,7 @@ module Roo
doc.xpath('//definedName').each_with_object({}) do |defined_name, hash|
# "Sheet1!$C$5"
sheet, coordinates = defined_name.text.split('!$', 2)
+ next unless coordinates
col, row = coordinates.split('$')
name = defined_name['name']
hash[name] = Label.new(name, sheet, row, col)
diff --git a/lib/roo/open_office.rb b/lib/roo/open_office.rb
index f172363..542c5b4 100644
--- a/lib/roo/open_office.rb
+++ b/lib/roo/open_office.rb
@@ -423,7 +423,10 @@ module Roo
@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
@@ -517,7 +520,7 @@ module Roo
str_v += child.content #.text
end
end
- str_v.gsub!(/&apos;/, "'") # special case not supported by unescapeHTML
+ str_v = str_v.gsub(/&apos;/, "'") # special case not supported by unescapeHTML
str_v = CGI.unescapeHTML(str_v)
end # == 'p'
end
diff --git a/lib/roo/version.rb b/lib/roo/version.rb
index d2bb2bf..0ad4acc 100644
--- a/lib/roo/version.rb
+++ b/lib/roo/version.rb
@@ -1,3 +1,3 @@
module Roo
- VERSION = "2.9.0"
+ VERSION = "2.10.0"
end
diff --git a/spec/lib/roo/base_spec.rb b/spec/lib/roo/base_spec.rb
index 76cefcc..9d44656 100644
--- a/spec/lib/roo/base_spec.rb
+++ b/spec/lib/roo/base_spec.rb
@@ -182,6 +182,14 @@ describe Roo::Base do
end
end
+ describe '#each_with_pagename' do
+ it 'should return an enumerator with all the rows' do
+ each_with_pagename = spreadsheet.each_with_pagename
+ expect(each_with_pagename).to be_a(Enumerator)
+ expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
+ end
+ end
+
describe '#each' do
it 'should return an enumerator with all the rows' do
each = spreadsheet.each
diff --git a/spec/lib/roo/excelx_spec.rb b/spec/lib/roo/excelx_spec.rb
index 7cc9b13..10b0caf 100755
--- a/spec/lib/roo/excelx_spec.rb
+++ b/spec/lib/roo/excelx_spec.rb
@@ -326,6 +326,30 @@ describe Roo::Excelx do
expect(subject.formatted_value(4, 1)).to eq '05010'
end
end
+
+ context 'contains US currency' do
+ let(:path) { 'test/files/currency-us.xlsx' }
+
+ it 'returns a zero-padded number' do
+ expect(subject.formatted_value(4, 1)).to eq '$20.51'
+ end
+ end
+
+ context 'contains euro currency' do
+ let(:path) { 'test/files/currency-euro.xlsx' }
+
+ it 'returns a zero-padded number' do
+ expect(subject.formatted_value(4, 1)).to eq '€20.51'
+ end
+ end
+
+ context 'contains uk currency' do
+ let(:path) { 'test/files/currency-uk.xlsx' }
+
+ it 'returns a zero-padded number' do
+ expect(subject.formatted_value(4, 1)).to eq '£20.51'
+ end
+ end
end
describe '#row' do
@@ -609,6 +633,17 @@ describe Roo::Excelx do
end
end
+ describe 'opening a file with filters' do
+ let(:path) { 'test/files/wrong_coordinates.xlsx' }
+ subject(:xlsx) do
+ Roo::Spreadsheet.open(path)
+ end
+
+ it 'should properly extract defined_names' do
+ expect(subject.sheet(0).workbook.defined_names.length).to eq(1)
+ end
+ end
+
describe 'images' do
let(:path) { 'test/files/images.xlsx' }
diff --git a/test/files/apostrophe.ods b/test/files/apostrophe.ods
new file mode 100644
index 0000000..9a4e4a6
--- /dev/null
+++ b/test/files/apostrophe.ods
Binary files differ
diff --git a/test/files/boolean-from-google-sheets.ods b/test/files/boolean-from-google-sheets.ods
new file mode 100644
index 0000000..246a5a8
--- /dev/null
+++ b/test/files/boolean-from-google-sheets.ods
Binary files differ
diff --git a/test/files/boolean-from-google-sheets.xlsx b/test/files/boolean-from-google-sheets.xlsx
new file mode 100644
index 0000000..7801156
--- /dev/null
+++ b/test/files/boolean-from-google-sheets.xlsx
Binary files differ
diff --git a/test/files/currency-euro.xlsx b/test/files/currency-euro.xlsx
new file mode 100644
index 0000000..c160836
--- /dev/null
+++ b/test/files/currency-euro.xlsx
Binary files differ
diff --git a/test/files/currency-uk.xlsx b/test/files/currency-uk.xlsx
new file mode 100644
index 0000000..8b709dd
--- /dev/null
+++ b/test/files/currency-uk.xlsx
Binary files differ
diff --git a/test/files/currency-us.xlsx b/test/files/currency-us.xlsx
new file mode 100644
index 0000000..a11dfa5
--- /dev/null
+++ b/test/files/currency-us.xlsx
Binary files differ
diff --git a/test/files/frozen_string.ods b/test/files/frozen_string.ods
new file mode 100644
index 0000000..55e0e1b
--- /dev/null
+++ b/test/files/frozen_string.ods
Binary files differ
diff --git a/test/files/implicit_coordinates.xlsx b/test/files/implicit_coordinates.xlsx
new file mode 100644
index 0000000..039d018
--- /dev/null
+++ b/test/files/implicit_coordinates.xlsx
Binary files differ
diff --git a/test/files/wrong_coordinates.xlsx b/test/files/wrong_coordinates.xlsx
new file mode 100644
index 0000000..0c6614e
--- /dev/null
+++ b/test/files/wrong_coordinates.xlsx
Binary files differ
diff --git a/test/roo/test_excelx.rb b/test/roo/test_excelx.rb
index 61161f0..c90cd8c 100644
--- a/test/roo/test_excelx.rb
+++ b/test/roo/test_excelx.rb
@@ -341,6 +341,15 @@ class TestRworkbookExcelx < Minitest::Test
assert_equal "Example richtext", xlsx.cell("b", 1)
end
+ def test_implicit_coordinates
+ xlsx = roo_class.new(File.join(TESTDIR, 'implicit_coordinates.xlsx'))
+
+ assert_equal 'Test', xlsx.cell('a', 1)
+ assert_equal 'A2', xlsx.cell('a', 2)
+ assert_equal 'B2', xlsx.cell(2, 2)
+ assert_equal 'C2', xlsx.cell('c', 2)
+ end
+
def roo_class
Roo::Excelx
end
diff --git a/test/test_roo.rb b/test/test_roo.rb
index dae4a41..bd1188d 100644
--- a/test/test_roo.rb
+++ b/test/test_roo.rb
@@ -274,6 +274,24 @@ class TestRoo < Minitest::Test
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)
@@ -282,6 +300,18 @@ class TestRoo < Minitest::Test
end
end
+ def test_apostrophe_replacement
+ with_each_spreadsheet(:name=>'apostrophe', :format=>[:openoffice]) do |oo|
+ assert_equal "'", oo.cell(1,1)
+ end
+ end
+
+ def test_frozen_string_usage
+ with_each_spreadsheet(:name=>'frozen_string', :format=>[:openoffice]) do |oo|
+ assert_equal "", oo.cell(1,1)
+ end
+ end
+
def test_row_whitespace
# auf dieses Dokument habe ich keinen Zugriff TODO:
# TODO: No access to document whitespace?