I had a similar problem recently when I started reading directly from Excel sheets too. The problem was that the code below creates a 3-dimensional array, not a 2-dimensional one as expected.<br><br>That is, when I looked at the contents of 'data' in irb, it looked like the following:
<br><br>data = [[[a,1,..]], [[b,2,..]], [[c,3,..]], etc]<br><br>Try adding ".flatten" to your retrieval line:<br> data << worksheet.Range("a#{line}:u#{line}")['Value'].flatten<br><br>This worked for me. Now the 'data' array will be in an expected 2-dimensional format. That is, it should now look like:
<br><br>data = [[a,1.0,..], [b,2.0,..], [c,3.0,..], etc]<br>
<br>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:<br><br>puts data[2][1]<br>=> 3.0
<br><br>Hope this helps. Paul.<br><br><br><div><span class="gmail_quote">On 02/08/06, <b class="gmail_sendername">VIKASH KUMAR</b> <<a href="mailto:vikashkumar051@yahoo.co.in">vikashkumar051@yahoo.co.in</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div>Sir,</div> <div> </div> <div><font color="#0000ff">I am storing values from excel to a array name 'data
</font>', I am using below code for it. </div> <div> </div> <div> </div> <div>excel = WIN32OLE::new('excel.Application')</div> <div> workbook = excel.Workbooks.Open('E:\sam.xls')<br> worksheet = workbook.Worksheets(1)
<br> worksheet.Select <br> excel['Visible'] = true<br></div> <div>line = '2'<br><strong><font color="#0000ff">data = Array.new<br></font></strong>while worksheet.Range("a#{line}")['Value']<br>data <<
worksheet.Range("a#{line}:u#{line}")['Value']<br>data.each { |x| print x, "\n\n\n".chomp }<br>puts("\n")<br>line.succ!<br>end<br></div> <div><strong><font color="#0000ff">Now, I wants to access 3rd element stored in the above array name 'data'.
</font></strong> <strong><font color="#0000ff"> I am
facing problem in doing this. Please send me a solution for this.</font></strong></div> <div> </div> <div>Thanks in Advance</div></div><div><span class="sg"> <div> </div> <div>Vikash Kumar</div></span></div><div><span class="ad">
<p>
        
        
                </p><br></span></div></blockquote></div><br>