Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Alright, I'll finish the Tutorial and get it up by the week-end.

Read my Scratch Pad for a complete discussion on getting data from and manipulating data in an excel worksheet using Win32::OLE.

Honestly, if you're going to be opening the workbooks anyway, there is no reason to use two scripts to accomplish this task, just iterate through the Sheets object of each workbook starting from the 1 position. Otherwise use the SaveAs function of the Worksheet object

use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # Die on Errors. ####################################### ## ::Warn = 2 throws the errors, but ## ## expects that the programmer deals ## ####################################### my $excelfile = 'c:\temp\win32\tabexample.xls'; my $excelout = 'c:\temp\win32\tabexample.tab'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{DisplayAlerts}=0; my $Book = $Excel->Workbooks->Open($excelfile); $Book->SaveAs({Filename =>$excelout, FileFormat => xlCurrentPlatformText});
C-.

Update: I thought I should make a slight clarification about iterating through the Worksheets set based on sheet count. I was trying to say that the Worksheets object is 1 based, not 0 based. If, indeed, you wanted to skip the first work sheet, you would start with 2.

my $sheetcnt = $Book->Worksheets->Count(); foreach (2..$sheetcnt){ print $Book->Worksheets($_)->{Name} ."\n"; my $sheet = $Book->Worksheets($_); ##Do something with the sheet object## }

In reply to Re: Excel to Perl by cacharbe
in thread Excel to Perl by sabersd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (8)
    As of 2014-12-18 04:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (41 votes), past polls