开发者

Problem with writing a file to excel with spreadsheet

开发者 https://www.devze.com 2022-12-29 07:29 出处:网络
I am trying to write excel file by using ruby 1.9spreadsheet version 0.6.4.1 on windows. Everything is going ok,

I am trying to write excel file by using ruby 1.9 spreadsheet version 0.6.4.1 on windows. Everything is going ok, until I get to the book.writ开发者_开发百科e statement when I write book.write "c:/spreadsheet/excel-file.xls I keep getting the following error No such file or directory - c:/spreadsheet/excel-file.xls when i am runing it from the ruby console i get the error errono::EINVAL invalid argument. when i check in the path i see that a file was created but althought i write to it its empty

Can anyone tell me what should I do?

Thanks


Don't use windows!

According to http://pullmonkey.com/2008/02/19/errno-einval-invalid-argument/

STDOUT is nonexistent if you run mongrel as a service under windows, and errono::EINVAL is the result.


We had the same problem.

require 'rubygems'
require 'logger'
require 'spreadsheet'
require 'stringio'

workbook = Spreadsheet::Workbook.new
worksheet = workbook.create_worksheet
worksheet[0, 0] = "Hello, World!"

ostream = StringIO.new    

workbook.write (ostream)

ostream.rewind

File.open("aFile.xls","wb") do |f|
  f.write(ostream.read)
end

puts "Done!"


We decided that using libraries for excel is brittle. We use CSV with extension ".xls". Why? Because Excel doesn't show that nasty import box. It just opens it like a regular file. Users won't notice the difference.

0

精彩评论

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

关注公众号