zdavatz / spreadsheet

The Ruby Spreadsheet by ywesee GmbH
http://spreadsheet.ch
GNU General Public License v3.0
1.13k stars 240 forks source link

When I manipulate an existing cell from an opened spreadsheet, the file I write it out to is corrupted #219

Closed parradox2nd closed 6 years ago

parradox2nd commented 6 years ago

When I open a spreadsheet, then write it out to a new file, all works well and I can open the file:

[3] pry(main)> book = Spreadsheet.open "#{$myRoot}/ics_data.xls"
=> #<Spreadsheet::Excel::Workbook:0x2f77794>
[4] pry(main)> obj_repo = book.worksheet 'obj_repo'
=> #<Spreadsheet::Excel::Worksheet:0x00000002f2e684 @row_addresse
 1], :orientation=>:portrait, :adjust_to=>100} @margins={:top=>1,
{} @merged_cells=[] @protected=false @password_hash=0 @visibility
ffset=57537 @guts={} @notes={} @rows[469]>
[5] pry(main)> book.write "#{$myRoot}/ics_data_test_write.xls"
=> 468992

When I make any type of manipulation, the resulting file cannot be opened:

[3] pry(main)> book = Spreadsheet.open "#{$myRoot}/ics_data.xls"
=> #<Spreadsheet::Excel::Workbook:0x318e8bc>
[4] pry(main)> obj_repo = book.worksheet 'obj_repo'
=> #<Spreadsheet::Excel::Worksheet:0x00000003163644 @row_addresses= @froze_top=
 1], :orientation=>:portrait, :adjust_to=>100} @margins={:top=>1, :left=>0.75,
{} @merged_cells=[] @protected=false @password_hash=0 @visibility=visible @chan
ffset=57537 @guts={} @notes={} @rows[469]>
[5] pry(main)> obj_repo.select{ |a| a[2].eql?("username") }[0][4] += ", test"
=> "fastapp login, portal login page, test"
[6] pry(main)> book.write "#{$myRoot}/ics_data_write_test.xls"
=> []

image

What am I doing wrong in how I am manipulating that specific cell in that specific row?

zdavatz commented 6 years ago

Please provide a real script. No irb. Who created the original file?