File: xls2csv

package info (click to toggle)
libspreadsheet-read-perl 0.54-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 624 kB
  • ctags: 51
  • sloc: perl: 2,868; lisp: 293; makefile: 11; xml: 1
file content (38 lines) | stat: -rwxr-xr-x 881 bytes parent folder | download
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
#!/pro/bin/perl

# xls2csv: Convert Microsoft Excel spreadsheet to CSV
#	   (m)'13 [24-10-2013] Copyright H.M.Brand 2008-2014

use strict;
use warnings;

sub usage
{
    my $err = shift and select STDERR;
    print "usage: $0 [ -o file.csv ] file.xls\n";
    @_ and print join "\n", @_, "";
    exit $err;
    } # usage

use Getopt::Long qw( :config bundling nopermute passthrough );
my $csv;
my $opt_f;
GetOptions (
    "help|?"	=> sub { usage 0; },
    "o|c=s"	=> \$csv,
    "f"		=> \$opt_f,
    ) or usage 1;

my $xls = shift or usage 1, "No input file";
-r $xls         or usage 1, "Input file unreadable";
-s $xls         or usage 1, "Input file empty";

$csv or ($csv = $xls) =~ s/\.xls$/.csv/i;
if (-f $csv) {
    $opt_f or die "$csv already exists\n";
    unlink $csv;
    }

print STDERR "Converting $xls to $csv ...\n";
open STDOUT, ">", $csv;
exec "xlscat", "-c", $xls;