Split up Excel row and assign cells to variables

S

saudaziz

Ok guys, so far i have the following. Right now as it is, it reads in
row by row and displays it perfectly. What i would like to do instead
is to grab each cell in a row and assign that cell to a particular
variable and keep on looping for each row until End of file... Is it
possible to modify "worksheet.Range("a#{line}:j#{line}")['Value']" in
the code below to achieve this?

def getExcelStuff
excel = WIN32OLE::new('excel.Application')
workbook =
excel.Workbooks.Open('C:\ruby\watir\watir-v1_4\examples\logging\xxx.xls')
worksheet = workbook.Worksheets(1)
worksheet.Select
excel['Visible'] = true

line = '1'
data = Array.new
while worksheet.Range("a#{line}")['Value']
data << worksheet.Range("a#{line}:j#{line}")['Value']
data.each { |x| print x, "\n\n\n".chomp }
line.succ!
end


end
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top