title: Problems parsing Excel 2010 .xlsx file with Win32::OLE in Perl
body: <p>I have an excel file (.xlsx) connected to a "data source" with a .iqy file. I used Perl to to open the excel file and refresh the data. Initially, my code worked. However, I needed to change what .iqy file my spreadsheet was linked to, and doing this seems to have broken my Perl script (despite not actually changing anything inside the script itself). Now it fails when I call</p>
  
  <pre><code>my $LastRow = $Sheet-&gt;UsedRange-&gt;Find({What=&gt;"*",
      SearchDirection=&gt;xlPrevious,
      SearchOrder=&gt;xlByRows})-&gt;{Row};
  </code></pre>
  
  <p>and cmd output reads: "Can't use an undefined value as a HASH reference at sharing.pl line 20." I've tried debugging this, but I don't know enough about the guts of the Win32::OLE module to know how to even catch where or why the problem happens in the debugger. The source code for my script is:</p>
  
  <pre><code>#!/usr/bin/perl
  use Win32::OLE;
  use Win32::OLE qw(in with);
  use Win32::OLE::Variant;
  use Win32::OLE::Const 'Microsoft Excel';
  
  $Excel = Win32::OLE-&gt;GetActiveObject('Excel.Application') ||
         Win32::OLE-&gt;new('Excel.Application');
  $Excel-&gt;{'Visible'} = 0;        #0 is hidden, 1 is visible
  $Excel-&gt;{DisplayAlerts}=0;  #0 is hide alerts
  
  # Open File and Worksheet
  my $Book = $Excel-&gt;Workbooks-&gt;Open ('C:\shareP\sp.xlsx'); # open Excel file
  $Sheet = $Book-&gt;Worksheets(1);
  
  # Refresh Data (ActiveWorkbook.RefreshAll)
  $Book-&gt;RefreshAll();
  
  # Find Last Column and Row
  my $LastRow = $Sheet-&gt;UsedRange-&gt;Find({What=&gt;"*",
      SearchDirection=&gt;xlPrevious,
      SearchOrder=&gt;xlByRows})-&gt;{Row};
  
  my $LastCol = $Sheet-&gt;UsedRange-&gt;Find({What=&gt;"*", 
                SearchDirection=&gt;xlPrevious,
                SearchOrder=&gt;xlByColumns})-&gt;{Column};
  ####### EDIT: I initially didn't post this portion because it stops
  #       before reaching it unless I make $LastCol and $LastRow constants
  my @hasher;
  my $c = "a";
  for (my $cn=1; $cn &lt;= $LastCol; $cn++){
      for (my $r=2; $r &lt;= $LastRow; $r++){
  # stops here with same error if I make $LastCol and $LastRow constants
          $hasher[$r-2]{ $Sheet-&gt;Range($c.'1')-&gt;{Value} } = $Sheet-&gt;Range($c.$r)-&gt;{Value};
      }
  $c++;
  }
  ####### end of EDIT
  # Save as Excel
  $Book-&gt;Save();  
  $Book-&gt;Close();
  $Excel-&gt;Quit();  
  </code></pre>
  
  <p>Thank you in advance for any and all advice. I'm really stuck on this one.</p>