# Excel manipulation

**URL:** <https://www.ruby-forum.com/t/excel-manipulation/186918>\
**Category:** Ruby\
**Created:** [April 14, 2010, 11:25am UTC](https://www.ruby-forum.com/t/excel-manipulation/186918 "2010-04-14T11:25:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simbolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@simbolla](https://www.ruby-forum.com/u/simbolla)\
**Post date:** [April 14, 2010, 11:25am UTC](https://www.ruby-forum.com/t/excel-manipulation/186918/1 "2010-04-14T11:25:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![simbolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@simbolla](https://www.ruby-forum.com/u/simbolla)\
**Post date:** [April 14, 2010, 11:30am UTC](https://www.ruby-forum.com/t/excel-manipulation/186918/2 "2010-04-14T11:30:57Z")

</div>

capitaliZation

---

<div class="post-metadata">

**Author:** ![simbolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@simbolla](https://www.ruby-forum.com/u/simbolla)\
**Post date:** [April 14, 2010, 11:37am UTC](https://www.ruby-forum.com/t/excel-manipulation/186918/3 "2010-04-14T11:37:58Z")

</div>

> 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,
