views:

45

answers:

1

I am using Spreadsheet for ruby for creating excel files. Now I want that a excel must be created when it doesnt exist. So I wrote this -:

require 'rubygems'
require 'spreadsheet'
include Spreadsheet

workbook = Spreadsheet.open "data__#{$KEYWORD}.xlsx" rescue Excel.new("data__#{$KEYWORD}.xlsx")

But Always keeps throwing this error -

undefined method `new' for Spreadsheet::Excel:Module (NoMethodError)
+3  A: 

Looks like you want to use Spreadsheet::Excel::Workbook.new. As the error you get points out, Spreadsheet::Excel is a module, and not instantiable.

Check the documentation.

michaelmichael