Skip to content

Instantly share code, notes, and snippets.

@taka2
Created September 7, 2008 18:00
Show Gist options
  • Save taka2/9290 to your computer and use it in GitHub Desktop.
Save taka2/9290 to your computer and use it in GitHub Desktop.
require 'java'
require 'poi-3.1-FINAL-20080629.jar'
class RubyOutputStream < java.io.OutputStream
def initialize(io)
super()
@io = io
end
def write(b)
if b.is_a?(Fixnum)
if b < 0
b = b + 256
end
@io.print(b.chr)
else
(0...b.length).each do |index|
write(b[index])
end
end
end
def close
@io.close
end
end
io = File.open("test.xls", "w")
rio = RubyOutputStream.new(io)
wb = org.apache.poi.hssf.usermodel.HSSFWorkbook.new
wb.createSheet("First")
wb.write(rio)
rio.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment