Add -A to make %F keys use first defined row as keys
--- /usr/local/bin/XLSperl 2010-12-06 22:33:57.000000000 -0500
+++ XLSperl 2010-12-07 00:20:55.000000000 -0500
@@ -40,7 +40,7 @@
MAIN: {
my %options;
Getopt::Long::Configure('bundling');
- GetOptions( \%options, qw/e=s l n p x a F=s w/,
+ GetOptions( \%options, qw/e=s l n p x a A F=s w/,
'm=s' => sub{ eval qq{use $_[1] ()}; die $@ if $@;},
'M=s' => sub{ my ($m,$a) = split /=/,$_[1],2;
if ($a) {
@@ -64,6 +64,7 @@
if ($options{n} or $options{p}) {
$eval_function = make_loop( perl => $eval_function,
autosplit => $options{a},
+ AutoSplit => $options{A},
splitregex => $options{F},
autoline => $options{l} );
}
@@ -120,19 +121,31 @@
sub loop_xls {
my %args = @_;
+
+ my @header;
+
foreach my $worksheet (@{$args{xls}->{Worksheet}}) {
$WS = $worksheet->{Name};
my ($row_min,$row_max) = $worksheet->RowRange();
my ($col_min,$col_max) = $worksheet->ColRange();
foreach my $row ($row_min .. $row_max) {
$ROW = $row + 1;
- if ($args{autosplit}) {
+ if ($args{autosplit} || $args{AutoSplit}) {
@F = map {$_ && $_->Value() || undef} @{$worksheet->{Cells}[$row]};
@F = map {$_ && chomp;$_} @F if ($args{autoline});
+
+ if( $args{AutoSplit} && !@header && grep {defined} @F ){
+ @header = @F;
+ }
- # Make the %F hash an alias for @F, i.e. $F{A} == $F[0]
+ # Make the %F hash an alias for @F
for (0 .. $#F) {
- alias($F[$_],$F{int2col($_)});
+ # $F{$header[0]} == $F[0]
+ if ( $args{AutoSplit}) {
+ alias($F[$_],$F{$header[$_]}); }
+ # $F{A} == $F[0]
+ else{
+ alias($F[$_],$F{int2col($_)}); }
}
undef $_; # What should $_ be if autosplitting an Excel file?