views:

62

answers:

2

I am using spreadsheet gem to generate excel file. Now the problem with it is that when we modify an existing file it wont allow to save it with same name http://spreadsheet.rubyforge.org/GUIDE_txt.html and in the running script I cant delete and recreate the file beacause it is still being used. Doing so throws permission denied error.

Any suggeestion to overcome this?

A: 

can you work on a tmp copy of the file?

apeacox
+1  A: 

Follow the example provided in the documentation you linked. Use a scheme for creating an 'output' version of the document, then wrap up by replacing the original with the 'output' version.

book = Spreadsheet.open '/path/to/an/excel-file.xls'
sheet = book.worksheet 0
sheet.each do |row|
  row[0] *= 2
end
book.write '/path/to/output/excel-file.xls'
Sugerman
Thats the problem, it doesnt allow me to rename, delete the file being created coz of the locks obtained by the spreadsheet gem
Shubham