Excel manipulation

hi all,

Below is the code for manipualting excel data.

================================================
require ‘win32ole’
excelPath = “C:\vbscript\sample.xls”
application = WIN32OLE.new(‘Excel.Application’)
application.DisplayAlerts = 0
application.Workbooks.open excelPath, false, true
currentWorkSheet = application.ActiveWorkbook.Worksheets(1)
sCell = currentWorksheet.Cells
usedColumnsCount = currentWorkSheet.UsedRange.Columns.Count
usedRowsCount = currentWorkSheet.UsedRange.Rows.Count
puts “Rows= #{usedColumnsCount} cols=#{usedRowsCount}”

For this above code i get this error

Sampler.rb:7: undifined local variable or method “currentWorkSheet” for
main:Object(NameError)

I dont the reason for this error?

capitaliZation

currentWorkSheet = application.ActiveWorkbook.Worksheets(1)
sCell = currentWorksheet.Cells

Second line should be currentWorkSheet and not currentWorksheet (or
rather first without capitalized S)
BTW, use rather current_worksheet for your variables (downcase and
underscores), it’s more “Ruby style”

Cheers,

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