and EZ way to convert XLS file to CSV?

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default and EZ way to convert XLS file to CSV?

    OK, I'm painted into a corner by Bill G again.. This time with XL, yet
    another package NIH by Microsoft but still controlled by them...

    If I bop into OpenOffice I can read in an XLS and export it as a CSV.
    I looked in cpan and news but didn't see a straightforward way to do
    the same thing with a Perl module. I saw XL-Parse but the readme
    implied it didn't have a quick-conversion capability.

    Something, perhaps, like

    my @csv = DreamXLModule::Convert($XLFilePath, 'csv');

    Thanks!
    Gx
    Sara Guest

  2. Similar Questions and Discussions

    1. Convert .flv file
      I need to make a .flv file available to mobile device. We are creating our file with Flash Communication server. So im trying to convert the...
    2. convert a file from pdf version 1.4 to 1.3.Originally an Indesign file
      is it possible to convert a file from pdf version 1.4 to 1.3. Originally it was an Indesign file. Many thanks in advance
    3. Best way to convert 3gpp file into a flv file?
      Hi Whats the best way to convert a 3gpp file into a flv file? I assume that flv is a common file type which would work on most browsers? Is...
    4. What is the best way to convert an InDesign file to an Illustrator file??
      When I try exporting as an eps, all the images have been broken up into non colored pieces and the fonts are screwed up? I just want everything to...
    5. convert an flv file
      Hello all, Does anyone know a way to convert flv video files to another standar format? (AVI, MPEG, WMV)? I'm actually interested more in the...
  3. #2

    Default Re: and EZ way to convert XLS file to CSV?

    Sara wrote:
    > OK, I'm painted into a corner by Bill G again.. This time with XL, yet
    > another package NIH by Microsoft but still controlled by them...
    >
    > If I bop into OpenOffice I can read in an XLS and export it as a CSV.
    > I looked in cpan and news but didn't see a straightforward way to do
    > the same thing with a Perl module. I saw XL-Parse but the readme
    > implied it didn't have a quick-conversion capability.
    >
    > Something, perhaps, like
    >
    > my @csv = DreamXLModule::Convert($XLFilePath, 'csv');
    >
    > Thanks!
    > Gx
    Not seen one, sorry. You could write your own without too much trouble,
    using Spreadsheet::ParseExcel, something like this:

    --

    #!/usr/bin/perl -w
    use strict;
    use Spreadsheet::ParseExcel;
    my ($file) = (@ARGV);
    my $dest = $file;
    my $xls = Spreadsheet::ParseExcel::Workbook->Parse("$file");
    foreach my $sheet (@{$xls->{Worksheet}}) {
    my $name = $sheet->{Name};
    my $dest =~ s/\.xls$/_sheet$name\.cvs/;
    open OUT, ">$dest" or die "Can't write to $dest: $!\n";
    my ($col, $row);
    for ($row = $sheet->{MinRow};
    defined $sheet->{MaxRow} && $row <= $sheet->{MaxRow};
    $row++) {
    for ($col = $sheet->{MinCol};
    defined $sheet->{MaxCol} && $col <= $sheet->{MaxCol};
    $col++){
    my $cell = $sheet->{Cells}[$row][$col]->Value;
    print OUT "$cell,";
    }
    print OUT "\n";
    }
    close OUT;
    }

    --

    It should write every sheet to a different file, in the form
    <filename>_<sheetname>.cvs
    Not tested, but it may work. Gives you the idea, anyway.

    Two things, though - this module throws up lots of warnings, so you may wish
    to switch them off once you get it working.
    Also, this won't be quick (from recent experience, I'd guess about 15mins
    for an xls with 12 sheets, each around 150x400. That's on a P3/700mhz with
    128mb RAM & Linux, just to give you an idea)!

    Hopefully this'll give you a good start on writing it, anyway. It may just
    need a check to make sure the cell's not empty.

    Regards,

    Garry


    Garry Short Guest

  4. #3

    Default Re: and EZ way to convert XLS file to CSV?

    On 10 Jul 2003 06:25:45 -0700, [email]genericax@hotmail.com[/email] (Sara) wrote:
    >OK, I'm painted into a corner by Bill G again.. This time with XL, yet
    >another package NIH by Microsoft but still controlled by them...
    >
    >If I bop into OpenOffice I can read in an XLS and export it as a CSV.
    >I looked in cpan and news but didn't see a straightforward way to do
    >the same thing with a Perl module. I saw XL-Parse but the readme
    >implied it didn't have a quick-conversion capability.
    Are you talking about Excel, by any chance?

    use Spreadsheet::ParseExcel;
    Helgi Briem Guest

  5. #4

    Default Re: and EZ way to convert XLS file to CSV?

    [email]genericax@hotmail.com[/email] (Sara) wrote in news:776e0325.0307100525.37b06a42
    @posting.google.com:
    > OK, I'm painted into a corner by Bill G again.. This time with XL, yet
    I do not know what XL is but I'll assume you are talking about Excel.
    > another package NIH by Microsoft but still controlled by them...
    NIH?
    > If I bop into OpenOffice I can read in an XLS and export it as a CSV.
    > I looked in cpan and news but didn't see a straightforward way to do
    > the same thing with a Perl module. I saw XL-Parse but the readme
    > implied it didn't have a quick-conversion capability.
    I do not know about modules, but some time ago, I wrote a very
    rudimentary method to save each sheet in a bunch of Excel files in text
    format. If you are on a Win32 system with Excel installed, you could use
    that method. See:

    [url]http://www.people.cornell.edu/pages/asu1/notes/perl-excel.html[/url]

    Sinan
    --
    A. Sinan Unur
    [email]asu1@c-o-r-n-e-l-l.edu[/email]
    Remove dashes for address
    Spam bait: mailto:uce@ftc.gov
    A. Sinan Unur Guest

  6. #5

    Default Re: and EZ way to convert XLS file to CSV?

    "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns93B49CBD9408Easu1cornelledu@132.236.56.8> ...
    > [email]genericax@hotmail.com[/email] (Sara) wrote in news:776e0325.0307100525.37b06a42
    > @posting.google.com:
    >
    > > OK, I'm painted into a corner by Bill G again.. This time with XL, yet
    >
    > I do not know what XL is but I'll assume you are talking about Excel.
    Yes sorry I'm not fluent in Microsoft-ese...

    >
    > > another package NIH by Microsoft but still controlled by them...
    >
    > NIH?
    Not Invented Here
    _ _ _
    >
    > > If I bop into OpenOffice I can read in an XLS and export it as a CSV.
    > > I looked in cpan and news but didn't see a straightforward way to do
    > > the same thing with a Perl module. I saw XL-Parse but the readme
    > > implied it didn't have a quick-conversion capability.
    >
    > I do not know about modules, but some time ago, I wrote a very
    > rudimentary method to save each sheet in a bunch of Excel files in text
    > format. If you are on a Win32 system with Excel installed, you could use
    > that method. See:
    >
    > [url]http://www.people.cornell.edu/pages/asu1/notes/perl-excel.html[/url]
    Hmm I see- and I appreciate the tip and offer. Luckily for me I'm not
    on a Billy-G platform, I have either Solaris or Linux at my diposal.

    Regards, and have a nice weekend!
    Gx



    >
    > Sinan
    Sara Guest

  7. #6

    Default Re: and EZ way to convert XLS file to CSV?

    Garry Short <g4rry_short@zw4llet.com> wrote in message news:<bejstc$msb$1$8302bc10@news.demon.co.uk>...
    > Sara wrote:
    >
    > > OK, I'm painted into a corner by Bill G again.. This time with XL, yet
    > > another package NIH by Microsoft but still controlled by them...
    > >
    > > If I bop into OpenOffice I can read in an XLS and export it as a CSV.
    > > I looked in cpan and news but didn't see a straightforward way to do
    > > the same thing with a Perl module. I saw XL-Parse but the readme
    > > implied it didn't have a quick-conversion capability.
    > >
    > > Something, perhaps, like
    > >
    > > my @csv = DreamXLModule::Convert($XLFilePath, 'csv');
    > >
    > > Thanks!
    > > Gx
    >
    > Not seen one, sorry. You could write your own without too much trouble,
    > using Spreadsheet::ParseExcel, something like this:
    >
    > --
    >
    > #!/usr/bin/perl -w
    > use strict;
    > use Spreadsheet::ParseExcel;
    > my ($file) = (@ARGV);
    > my $dest = $file;
    > my $xls = Spreadsheet::ParseExcel::Workbook->Parse("$file");
    > foreach my $sheet (@{$xls->{Worksheet}}) {
    > my $name = $sheet->{Name};
    > my $dest =~ s/\.xls$/_sheet$name\.cvs/;
    > open OUT, ">$dest" or die "Can't write to $dest: $!\n";
    > my ($col, $row);
    > for ($row = $sheet->{MinRow};
    > defined $sheet->{MaxRow} && $row <= $sheet->{MaxRow};
    > $row++) {
    > for ($col = $sheet->{MinCol};
    > defined $sheet->{MaxCol} && $col <= $sheet->{MaxCol};
    > $col++){
    > my $cell = $sheet->{Cells}[$row][$col]->Value;
    > print OUT "$cell,";
    > }
    > print OUT "\n";
    > }
    > close OUT;
    > }
    >
    > --
    >
    > It should write every sheet to a different file, in the form
    > <filename>_<sheetname>.cvs
    > Not tested, but it may work. Gives you the idea, anyway.
    >
    > Two things, though - this module throws up lots of warnings, so you may wish
    > to switch them off once you get it working.
    > Also, this won't be quick (from recent experience, I'd guess about 15mins
    > for an xls with 12 sheets, each around 150x400. That's on a P3/700mhz with
    > 128mb RAM & Linux, just to give you an idea)!
    >
    > Hopefully this'll give you a good start on writing it, anyway. It may just
    > need a check to make sure the cell's not empty.
    >
    > Regards,
    >
    > Garry
    Garry:

    MOST APPRECIATED dude- you didn't have to go to all of that trouble! I
    figured with this probably being a very common conversion, that there
    would be a ton of modules out there. But your solution should work
    fine- I'm gonna give it a go here shortly once I get the module
    insalled.

    That's amazing that it could run 15 minutes. This is a 1GHz with like
    512MB RAM running Redhat 8; I hope I can get these converted faster
    than that! But if not then we'll just have to live with it- heck a 15
    minute coffeebreak 3-4 times a day sounds OK to me no?

    Regards, and have a nice summer weekend...

    -Gx
    Sara Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139