parseexcel, how to select a worksheet using the name

M

Mario Ruiz

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.
 
J

Jacob Helwig

Hi,
I know it's possible to select a worksheet using its number =C2=A0but I d= on't
know how to select it using the worksheet name. is it possible?

workbook =3D Spreadsheet::parseExcel.parse(file)
worksheet =3D workbook.worksheet(2)

thanks.

Replace 2 with the name of the worksheet.

worksheet =3D workbook.worksheet('worksheet name')
 
M

Mario Ruiz

That was the first thing I tried...
the error i get: can't convert String into Integer
 
G

Greg Halsey

Mario said:
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.
 
G

Greg Halsey

Mario said:
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.
 
M

Mario Ruiz

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top