Hi Perl Monks,

I am a new Perl user and am trying to save a Excel file as a tab delimeted text file. When I run the following script it creates a .csv or .txt file (depending on the output file name), but it is still in a binary format.

+ + #should save C:\\work\\perl_WinOle\\sym_text_testdoc.xls as # a text or csv formatted document. # creates a file with .txt or csv extension, but # document is not a tab or comma delimeted text file.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

use Win32; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; #$file = "C:\\work\\perl_WinOle\\test.csv"; $OutFile = "C:\\work\\perl_WinOle\\sym_text_testdoc.txt"; my $Excel = Win32::OLE->new('Excel.Application', 'Quit'); my $xl = Win32::OLE::Const->Load($Excel); $Excel->{'Visible'} = 1; # if you want to see what's going on my $Book = $Excel->Workbooks->Open( "C:\\work\\perl_WinOle\\sym_text_t +estdoc.xls" ); $Book->Activate(); $Book->SaveAs($OutFile); $Book->Close;

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxx

I found this snippet of code that saves a Word document as a text file: $document->SaveAs($txt, wdFormatText);

I assume that Excel would be somthing like: $book->SaveAs($txt, excelFormatText); excelFormatText probably should be something different. Does anyone know how to save an Excel file as a text delimeted text file?

Sorry about the format of my message, my question I entered does have spaces and lines for clarity, don't know why they don't exist in the examle posted message

Thanks, Steveb94553

20080601 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips


In reply to Saving Excel file in Tab delimeted text or .csv by steveb94553

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.