开发者

How to delete a file in ruby which is still being used?

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 permissi开发者_如何学Pythonon denied error.

Any suggeestion to overcome this?


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜