Parseexcel, how to select a worksheet using the name

Hi,
I know it’s possible to select a worksheet using its number but I don’t
know how to select it using the worksheet name. is it possible?

workbook = Spreadsheet::ParseExcel.parse(file)
worksheet = workbook.worksheet(2)

thanks.

On Thu, Oct 15, 2009 at 07:53, Mario R. removed_e[email protected] wrote:

Hi,
I know it’s possible to select a worksheet using its number  but I don’t
know how to select it using the worksheet name. is it possible?

workbook = Spreadsheet::ParseExcel.parse(file)
worksheet = workbook.worksheet(2)

thanks.

Replace 2 with the name of the worksheet.

worksheet = workbook.worksheet(‘worksheet name’)

That was the first thing I tried…
the error i get: can’t convert String into Integer

Any help???

So it’s not possible using parseexcel.

Thanks a lot.

Mario R. wrote:

Any help???

require ‘rubygems’
require ‘spreadsheet’
file=‘c:/download/test.xls’
workbook=Spreadsheet.open file

worksheet = workbook.worksheet(1)
p worksheet.inspect

<Spreadsheet::Excel::Worksheet:0x000000015fafa4 @name=Sheet2 …

worksheet = workbook.worksheet(‘Sheet2’)

p worksheet.inspect
#<Spreadsheet::Excel::Worksheet:0x000000015fafa4 @name=Sheet2 …

Start with GUIDE.TXT located

C:\Ruby\lib\ruby\gems\1.8\gems\spreadsheet-0.6.4.1

hope it helped.

Mario R. wrote:

So it’s not possible using parseexcel.

Thanks a lot.
It it is possible. Take a look at the documentation. Here is a quick
example:

require ‘rubygems’
require ‘parseexcel’
file=‘c:/download/test.xls’
workbook = Spreadsheet::ParseExcel.parse(file)
worksheet = workbook.worksheet(1)
puts 'worksheet by number is ’ + worksheet.name
worksheet = workbook.worksheet(‘Sheet2’)
puts 'worksheet by name is ’ + worksheet.name

[DEPRECATED] By requiring ‘parseexcel’, ‘parseexcel/parseexcel’ and/or
‘parseexcel/parser’ you are loading a Compatibility layer
which
provides a drop-in replacement for the ParseExcel library.
This
code makes the reading of Spreadsheet documents less
efficient and
will be removed in Spreadsheet version 1.0.0

worksheet by number is Sheet2
worksheet by name is Sheet2

Pretty much the same as the response by Jacob.

Take a look at your error “can’t convert String into Integer”.
Hope it helps.

Yes that’s what I was trying but it doesn’t work… “can’t convert
String into Integer”

Running your example what I get is:
undefined method `name’ for
#Spreadsheet::ParseExcel::Worksheet:0x3d03ccc (NoMethodError)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs