X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=txt2xls;h=6ac3a94e3b1978476f706dfd31d0add84d76ec39;hb=1886c7247cb16ed68a78cd5550b152689a465999;hp=f6efa3a6300c5112418ba65b964372b89284f317;hpb=c2be9416877fb4459cacacb4ab197d455d3c70b5;p=bin.git diff --git a/txt2xls b/txt2xls index f6efa3a..6ac3a94 100755 --- a/txt2xls +++ b/txt2xls @@ -132,6 +132,11 @@ elsif ($options{ssv}) { $sep_char = ' '; } +if (not @{$options{remove_name}}) { + $options{remove_name} = ['.+\/', + ]; +} + my %wb_formats = (); my $csv = Text::CSV->new({sep_char=>$sep_char}); my $wb = Spreadsheet::WriteExcel->new(\*STDOUT); @@ -142,12 +147,12 @@ for my $file (@ARGV) { $file = "STDIN"; } else { - $fh = IO::File->new($file,'r') or + open($fh,'<:encoding(utf8)',$file) or die "Unable to open $file for reading: $!"; } my $ws_name = $file; foreach my $remove (@{$options{remove_name}}) { - $ws_name =~ s{\Q$remove\E}{}g; + $ws_name =~ s{$remove}{}g; } $ws_name =~ s{\.[^\.]+$}{}g; $ws_name =~ s/_+/ /g; @@ -165,7 +170,7 @@ for my $file (@ARGV) { while (<$fh>) { chomp; # parse the line - die "Unable to parse line $. of $file" unless $csv->parse($_); + die "Unable to parse line $. of $file: ".$csv->error_diag() unless $csv->parse($_); my @row = $csv->fields(); if ($row==1 and not $r_mode_autodetected) { @header_row = @row; @@ -187,7 +192,8 @@ for my $file (@ARGV) { my $t_ws_name = $ws_name; my $maxlen = 31-length('.'.$overflow); $t_ws_name =~ s{^(.{0,$maxlen}).*$}{$1}; - $ws = $wb->add_worksheet($ws_name.'.'.$overflow); + $ws = $wb->add_worksheet($t_ws_name.'.'.$overflow); + $overflow++; $row=1; output_row(\@header_row,$row,$ws,$wb,\%wb_formats,\%options); $row++;