title: Perl writing to Excel worksheet using OLE
body: <p>firstly thanks for reading this.  I have a small script that collects various txt files and drops them into an Excel worksheet, I previously used Spreadsheet::WriteExcel to do this, and all worked fine.  However as I developed the script it became more obvious that I should use Win::OLE to perform this function as I would prefer to use a template Excel file (with pre existing formulas) which I could add these txt files to as worksheets.</p>
  
  <p>I am struggling with the change from Spreadsheet::WriteExcel to Win::OLE with the paste function to place the text files into a spreadsheet.  Here's the code that did work (from the point of adding the txt file @ line >>>>  $wrksheet->write_col)</p>
  
  <pre><code>        ......
          my $workbook = Spreadsheet::WriteExcel-&gt;new("resultsbook.xls");
  
          (my $sheetname = $file) =~s/\.\w+//; 
          my $wrksheet = $workbook-&gt;add_worksheet($sheetname);
          $wrksheet-&gt;write_col( 0, 0, readfile($file)); # &lt;-- Old write line
      }
  }
  
  sub readfile {
      my @textfilecontent = ();
      open my $fh, '&lt;', shift() or die "can't open file:$!";
      while (&lt;$fh&gt;) {
          chomp;
          push @textfilecontent, [split(/\t/)];
      }
      return \@textfilecontent;
  }
  </code></pre>
  
  <p>But I have since changed to using OLE and I get as far as naming the Excel worksheet tabs but I am struggling to workout how to paste the extracted txt into a worksheet here (using the same subroutine above @ line >>>> $sheet->Cells(0,0)->{Value} = readfile($file);   )...</p>
  
  <pre><code>        my $sheet = $book-&gt;Worksheets-&gt;Add({After =&gt; $book-&gt;Worksheets(1)})
          $sheet-&gt;{Name} = $sheetname;    
  
          $sheet-&gt;Cells(0,0)-&gt;{Value} = readfile($file); # &lt;-- New write line
  
          ###$sheet-&gt;write_col( 0, 0, readfile($file));#### Old method
      }
  }
  
  sub readfile {
      my @textfilecontent = ();
      open my $fh, '&lt;', shift() or die "can't open file:$!";
      while (&lt;$fh&gt;) {
          chomp;
          push @textfilecontent, [split(/\t/)];
      }
      return \@textfilecontent;
  }
  </code></pre>
  
  <p>I get the following error whel I run this script...</p>
  
  <p>Win32::OLE(0.1711) error 0x800a03ec
      in METHOD/PROPERTYGET "Cells" at line...  </p>
  
  <p>Any pointers/advice would be greatly appreciated.</p>
  
  <p>Thanks,
  MikG</p>