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?
--
Posted via http://www.ruby-forum.com/.

capitaliZation

···

On 14/04/2010, at 9:25 PM, Simbolla Simbolla wrote:

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?
--
Posted via http://www.ruby-forum.com/\.

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

Second line should be currentWorkSheet and not currentWork*s*heet (or
rather first without capitalized S)
BTW, use rather current_worksheet for your variables (downcase and
underscores), it's more "Ruby style"

Cheers,

···

--
JJ Fleck
PCSI1 Lycée Kléber