Excel Worksheet to CSV

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poojapo
    New Member
    • Feb 2007
    • 6

    Excel Worksheet to CSV

    hi,

    Refering to thread: Open and create new Excel file with Perl and win32::OLE

    Can you please give a code to save an excel sheet with a different extension?

    my $Excel = Win32::OLE-> new ('Excel.Applica tion', 'Quit') or die ("Can't create object: ", Win32::OLE->LastError()) ;
    $Excel->{DisplayAlerts }=0;

    my $excelfile = 'C:\PERL\bin\IN BOUND.xls';

    my $Book = $Excel->Workbooks->Open($excelfil e)or die ("Can't open Workbook: ", Win32::OLE->LastError()) ;


    my $Sheet = $Book->Worksheets("EL EMENT");

    now i need to save the excel sheet ,ELEMENT to ELEMENT.csv as a different file into a different folder.how do i do this?
  • poojapo
    New Member
    • Feb 2007
    • 6

    #2
    export excelsheet as a .csv file

    hi,



    I wish to know if there is a way in perl using Win32::OLE to export a specific Excel Worksheet (not the entire workbook) from a workbook as a .csv file?



    Can you give me the sample code for the same?

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      Greetings,

      No sample code will be provided by me. However, this task is easily accomplished. Simply use the following two modules. The first one parses a Excel spreadsheet. The second one gives you functions for creating a CSV file.

      cpan Spreadsheet::Pa rseExcel
      cpan Text::CSV

      There are examples provide in the documentation for both of these modules.

      Good Luck,
      - Miller

      Comment

      • poojapo
        New Member
        • Feb 2007
        • 6

        #4
        I need to know if it can be accomplished using Win32::OLE

        Comment

        • miller
          Recognized Expert Top Contributor
          • Oct 2006
          • 1086

          #5
          It might be possible to solely use Win32::OLE, but I have no experience with that module so I can't say for sure. I'm guessing that you're hoping for the equivalent of a Save-As CSV, but I honestly don't think that you're going to find that.

          At the very least, if you can access the data of a worksheet via this module, then you could pair it with the Text::CSV module that I refered to previous. Or if you're rousing for a bruising, then you could just do it all manually. But I would definitely advise against that.

          - Miller

          Comment

          • bbobbo
            New Member
            • Sep 2007
            • 1

            #6
            Originally posted by poojapo
            hi,

            Refering to thread: Open and create new Excel file with Perl and win32::OLE

            Can you please give a code to save an excel sheet with a different extension?

            my $Excel = Win32::OLE-> new ('Excel.Applica tion', 'Quit') or die ("Can't create object: ", Win32::OLE->LastError()) ;
            $Excel->{DisplayAlerts }=0;

            my $excelfile = 'C:\PERL\bin\IN BOUND.xls';

            my $Book = $Excel->Workbooks->Open($excelfil e)or die ("Can't open Workbook: ", Win32::OLE->LastError()) ;


            my $Sheet = $Book->Worksheets("EL EMENT");

            now i need to save the excel sheet ,ELEMENT to ELEMENT.csv as a different file into a different folder.how do i do this?
            this thread is long dormant, but for anyone stumbling across it, here's the answer:

            $Sheet->SaveAs("NEWFIL ENAME.CSV", xlCSV);

            Comment

            Working...