Bugs: Browse | Submit New | Admin

[#25732] using the Row updater methods causes weird block errors (with file, I hope)

Date:
2009-04-29 17:15
Priority:
3
Submitted By:
someone else (someone23)
Assigned To:
Marc Hedlund (precipice)
Category:
None
State:
Closed
Summary:
using the Row updater methods causes weird block errors (with file, I hope)

Detailed description
Attaching the file didn't work previously, so I'm trying it again.

Running this code in irb with the given spreadsheet causes a LocalJumpError: no block given.

require 'rubygems'
require 'spreadsheet/excel'
rows_with_data = 0
book = Spreadsheet.open("test_sheet.xls")
book.worksheets.each do |worksheet|
  next if ["Overview"].include?(worksheet.name)
  worksheet.each do |row|
    number_of_empty_cells = row.size - row.delete_if {|o| o.blank?}.size
    if row.size > 0 # skip blank rows
      unless number_of_empty_cells < 4
        raise "ROW DATA: #{row.inspect}"
      end
      rows_with_data = rows_with_data + 1
    end
  end
end

rubygems 1.3.1
spreadsheet 0.6.3.1
OSX
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]

When I originally had this problem it was in a rails app and the "super" call inside the Row's delete_if was
using the initializer block from the environment.rb file of my rails app.  So, I move the "require 'spreadsheet'"
above that block, then I got the LocalJumpError.

This error also occurs with spreadsheets built with the spreadsheet gem.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-07-03 18:47
Sender: Hannes Wyss

Fixed in 0.6.4
http://rubyforge.org/forum/forum.php?forum_id=33463
Date: 2009-07-03 13:16
Sender: Hannes Wyss

Thanks for the report and the fix!

Committed into the current HEAD:
http://scm.ywesee.com/?p=spreadsheet;a=commit;h=0df081120a73327b3
e703f54ae2bcdb9ade612b7

I'll release an updated gem soon-ish.

cheers, 
Hannes
Date: 2009-05-05 02:42
Sender: someone else

Changing Spreadsheet::Row.updater to:

      def updater *keys
        keys.each do |key|
#           define_method key do |*args|
          class_eval <<-STR, __FILE__, __LINE__
          def #{key}(*args, &block)
            res = super
            @worksheet.row_updated @idx, self if @worksheet
            res
          end
          STR
        end
      end

instead of using define_method appears to fix this for me.

Also, you guys should really move to github.  It so much
easier to contribute there.

Attached Files:

Name Description Download
test_sheet.xls an openoffice create excel 97 xls Download

Changes:

Field Old Value Date By
status_idOpen2009-07-03 18:47hwyss
resolution_idNone2009-07-03 18:47hwyss
close_date2009-07-03 18:472009-07-03 18:47hwyss
assigned_toaevernon2009-05-05 03:45someone23
assigned_tonone2009-05-05 03:33someone23
File Added4508: test_sheet.xls2009-04-29 17:15someone23