Bugs: Browse | Submit New | Admin

[#22892] Data may be lost - error

Date:
2008-11-19 15:08
Priority:
3
Submitted By:
Chris Lowis (chrislo)
Assigned To:
Nobody (None)
Category:
None
State:
Closed
Summary:
Data may be lost - error

Detailed description
Trying to use spreadsheet with excel and fastercsv I am getting "Data may be lost" errors. This seems to be
triggered when writing data resulting from String#to_f. An example program follows and test data is attached :

require 'yaml'
require 'faster_csv'
require 'ruby-debug'

include Spreadsheet

workbook = Workbook.new
worksheet = workbook.create_worksheet()

file = './test_data.yaml'

a = open(file) {|f| YAML.load(f)}

FasterCSV.parse(a['data'], :col_sep=>' ').each_with_index do |row_data,row_idx|
  row_data.each_with_index do |cell_data,col_idx|
    worksheet[row_idx,col_idx]=cell_data.to_f
  end
end

workbook.write './test.xls'

Add A Comment: Notepad

Please login


Followup

Message
Date: 2011-08-04 11:39
Sender: Zeno R.R. Davatz

If this problem still exists please report it here:

http://groups.google.com/group/rubyspreadsheet

Best
Zeno
Date: 2008-12-12 10:39
Sender: Chris Lowis

Fantastic, works perfectly here! Many thanks for all your
hard work fixing this bug, it's really appreciated. Let me
know if I can help testing anything in the future,

Chris 
Date: 2008-12-11 18:01
Sender: Hannes Wyss

Should be Fixed in 0.6.2

let me know if it works for you,

thanks
Hannes
Date: 2008-12-10 13:33
Sender: Hannes Wyss

Fixed (tested in Excel-Reader)
in http://spreadsheet.rubyforge.org/git?p=spreadsheet.git;a=commi
t;h=84dce81b743830c91ec2270ffda6d3a8a737fdd9

I'll post a new release in a couple of bugfixes...

cheer
Hannes
Date: 2008-12-06 01:14
Sender: Emmanuel Q

I'm having a similar problem. Here's the code:

require 'spreadsheet'
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
sheet.row(0).replace [1, 3.4]
book.write 'file.xls'

Environment:
Mac OS X 10.5.4
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
spreadsheet (0.6.1.9)
Date: 2008-11-24 09:59
Sender: Chris Lowis

I just found your test_new.xls - I'm afraid it gives the
same error here, when opened by my Excel 2003.
Date: 2008-11-24 09:58
Sender: Chris Lowis

Hannes, 

I downloaded your git tarball and installed the gem with
rake install_gem

It seems to have improved most of the fields but there are
still some errors, and excel still gives the "data lost"
error.

I've attached the newly generated .xls file
(test_241108.xls) for you to look at. 

Thank you ! 
Date: 2008-11-21 17:46
Sender: Hannes Wyss

Chris, please try the newest sources from git:
http://spreadsheet.rubyforge.org/git?p=spreadsheet.git;a=snapshot
;h=612faa9fe4052cf041dea3409d26c7e68b302180;sf=tgz

Any better?

Alternatively: look at test_new.xls - this was written on a 64bit
Linux system using your code and the newest spreadsheet-source.
Does Excel like this better?
Date: 2008-11-20 16:45
Sender: Chris Lowis

Ok, here is the opened and re-saved test.xls (called
test_saved.xls)

Thanks ! 

Chris 
Date: 2008-11-20 16:40
Sender: Hannes Wyss

Just saw your Screenshots.

Obviously Excel does not like the way I store Floats. I'll have
to get back to you on this,

cheers
Hannes
Date: 2008-11-20 16:36
Sender: Hannes Wyss

Ah, now I understand. 

Please do the following for me: open the file in Excel (you should
get the Error-message), then save as a new file. Open that again
to make sure the Error is gone and attach it here.

I'll compare the two files to figure out which Opcode Excel is
missing. Openoffice 3.0 opens your file without complaint...

tia

Hannes
Date: 2008-11-20 16:25
Sender: Chris Lowis

Hannes, 

That's strange. I should say the error message is from Excel
(2003) when the file test.xls is opened. I've attached a
couple of screenshots to illustrate. 

Running your code produces no errors, if I add
puts.cell_data.to_f all the data looks correct in the
console. I think something is being corrupted in the process
of writing to the excel file. 

Also, I didn't have such an error with a previous version of
the gem, although that was running under the cygwin
environment not the native one-click installer. 

Thank you for helping with this, 

Chris
Date: 2008-11-20 16:03
Sender: Hannes Wyss

Chris,

I can't reproduce this - and as far as I can see, your test.xls
contains all the data.

In any case the error message "data may be lost" does
not originate from any code I've written. please try the
following:

require 'yaml'
require 'faster_csv'
require 'ruby-debug'

file = './test_data.yaml'

a = open(file) {|f| YAML.load(f)}

FasterCSV.parse(a['data'], :col_sep=>' ').each_with_index
do |row_data,row_idx|
  row_data.each_with_index do |cell_data,col_idx|
    cell_data.to_f
  end
end

You should probably also remove the "require 'spreadsheet'"
that must be there somewhere..

Do you get the same error message? 
If not: can I see the Backtrace?

tia

cheers
Hannes
Date: 2008-11-19 15:11
Sender: Chris Lowis

Further information: 

ruby 1.8.6 (2008-08-11 patchlevel 287) [i36-mswin32]  (one
click installer)

XP SP3
spreadsheet (0.6.1.8)


Attached Files:

Name Description Download
shot2.jpg Download
test_saved.xls Download
test.xls Download
shot1.jpg Download
test_data.yaml Download
test.xls test_new.xls Download
test_241108.xls Generated with the 0.6.1.9 version of spreadsheet Download

Changes:

Field Old Value Date By
close_date2011-08-04 11:392011-08-04 11:39zdavatz
close_date2008-12-12 10:392008-12-12 10:39chrislo
status_idOpen2008-12-11 18:01hwyss
close_date2008-12-11 18:012008-12-11 18:01hwyss
File Added4180: test_241108.xls2008-11-24 09:58chrislo
File Added4174: test.xls2008-11-21 17:46hwyss
File Added4166: test_saved.xls2008-11-20 16:45chrislo
summary"Data may be lost" error2008-11-20 16:36hwyss
File Added4165: shot2.jpg2008-11-20 16:26chrislo
summary"Data may be lost" error2008-11-20 16:26chrislo
summary"Data may be lost" error2008-11-20 16:26chrislo
File Added4164: shot1.jpg2008-11-20 16:26chrislo
summary"Data may be lost" error2008-11-20 16:26chrislo
summary"Data may be lost" error2008-11-20 16:25chrislo
summary"Data may be lost" error2008-11-19 15:11chrislo
File Added4157: test.xls2008-11-19 15:08chrislo
summary"Data may be lost" error2008-11-19 15:08chrislo
File Added4156: test_data.yaml2008-11-19 15:08chrislo