Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Hannes Wyss
RE: Updating Excel file [ reply ]  
2010-02-22 15:05
I recommend you write the modified data into a temporary file, and then rename that to the original filename.

By: W N
Updating Excel file [ reply ]  
2010-02-02 19:32
I am trying to change an existing Excel file.
First by opening the Excel file and determining the number of rows by reading the file. Then
I want to insert some new data into the same
file. The file GUIDE.TXT says, its not advisable
to do so. Is there another way of changing
an existing Excel file ??

require 'spreadsheet'
# open test.xls
book = Spreadsheet.open 'test.xls'
sheet = book.worksheet 0
rowcount = 0
sheet.each do |row|
rowcount += 1
end
# now insert new data
(0..10).each do |i|
sheet.row(i).push "Testing"
sheet.row(i).push "Excel"
end
book.write "test.xls" # <<<<< Error