I have the following code:
$excel = WIN32OLE.new('Excel.Application')
$excel.visible = true
puts 'Filepath?'
$filepath = $stdin.gets.chomp
$workbook = $excel.Workbooks.Open($filepath)
puts $workbook
puts 'Sheet?'
$worksheet = $workbook.Worksheets
$count = $worksheet.Count
for i in 1..$count do
$array = $workbook.Worksheets(i).Name
puts i.to_s + "." + " " + $array
end
It's a part of a Ruby script that I'm using to manage and edit Excel files. I went with 'win32ole' because the files I'm interacting with are fairly large and I find that it's much faster than something like 'roo'. So my code does what I need it to do and that's go out and get all the sheet names within a specified spreadsheet. However for some reason it adds these values before and after my results:
#<WIN32OLE:0x291a878>
Sheet?"
1. Sheet1
2. Sheet2
3. Sheet3
1..3
I have no idea where #<WIN32OLE:0x291a878> or 1..3 are coming from but any help to trim these out would be greatly appreciated. Thank you
puts $workbook. As for the1..3, nothing in the code you provided prints that.