That is, when I looked at the contents of 'data' in irb, it looked like the following:
data = "" [[b,2,..]], [[c,3,..]], etc]
Try adding ".flatten" to your retrieval line:
data << worksheet.Range("a#{line}:u#{line}")['Value'].flatten
This worked for me. Now the 'data' array will be in an expected 2-dimensional format. That is, it should now look like:
data = "" [b,2.0,..], [c,3.0,..], etc]
Incidentally, since this is a 2-dimensional array I don't know what you mean by 'access 3rd element'. If you want to print the 2nd value in the 3rd row, you might do something like:
puts data[2][1]
=> 3.0
Hope this helps. Paul.
On 02/08/06, VIKASH KUMAR <[EMAIL PROTECTED]> wrote:
Sir,I am storing values from excel to a array name 'data ', I am using below code for it.excel = WIN32OLE::new('excel.Application')workbook = excel.Workbooks.Open('E:\sam.xls')
worksheet = workbook.Worksheets(1)
worksheet.Select
excel['Visible'] = trueline = '2'
data = "">while worksheet.Range("a#{line}")['Value']
data << worksheet.Range("a#{line}:u#{line}")['Value']
data.each { |x| print x, "\n\n\n".chomp }
puts("\n")
line.succ!
endNow, I wants to access 3rd element stored in the above array name 'data'. I am facing problem in doing this. Please send me a solution for this.Thanks in AdvanceVikash Kumar
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
