From d9ab23fa13ade3503b0a95cdafaa4bc755d94dba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 23 Sep 2016 15:31:21 +0200 Subject: [PATCH 1/1] =?utf8?q?ReportGenerator:=20CSV-Export:=20Encoding=20?= =?utf8?q?als=20Option=20angeben=20k=C3=B6nnen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Default bleibt UTF-8. --- SL/ReportGenerator.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 451e9c002..2e12a2acc 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -47,6 +47,7 @@ sub new { 'escape_char' => '"', 'eol_style' => 'Unix', 'headers' => 1, + 'encoding' => 'UTF-8', }, }; $self->{export} = { @@ -703,10 +704,10 @@ sub _print_content { } sub _handle_quoting_and_encoding { - my ($self, $text, $do_unquote) = @_; + my ($self, $text, $do_unquote, $encoding) = @_; $text = $main::locale->unquote_special_chars('HTML', $text) if $do_unquote; - $text = Encode::encode('UTF-8', $text); + $text = Encode::encode($encoding || 'UTF-8', $text); return $text; } @@ -745,7 +746,7 @@ sub _generate_csv_content { if ($opts->{headers}) { if (!$self->{custom_headers}) { - $csv->print($stdout, [ map { $self->_handle_quoting_and_encoding($self->{columns}->{$_}->{text}, 1) } @visible_columns ]); + $csv->print($stdout, [ map { $self->_handle_quoting_and_encoding($self->{columns}->{$_}->{text}, 1, $opts->{encoding}) } @visible_columns ]); } else { foreach my $row (@{ $self->{custom_headers} }) { @@ -753,7 +754,7 @@ sub _generate_csv_content { foreach my $col (@{ $row }) { my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1; - push @{ $fields }, ($self->_handle_quoting_and_encoding($col->{text}, 1)) x $num_output; + push @{ $fields }, ($self->_handle_quoting_and_encoding($col->{text}, 1, $opts->{encoding})) x $num_output; } $csv->print($stdout, $fields); @@ -775,7 +776,7 @@ sub _generate_csv_content { my $num_output = ($row->{$col}{colspan} && ($row->{$col}->{colspan} > 1)) ? $row->{$col}->{colspan} : 1; $skip_next = $num_output - 1; - push @data, join($eol, map { s/\r?\n/$eol/g; $self->_handle_quoting_and_encoding($_, 0) } @{ $row->{$col}->{data} }); + push @data, join($eol, map { s/\r?\n/$eol/g; $self->_handle_quoting_and_encoding($_, 0, $opts->{encoding}) } @{ $row->{$col}->{data} }); push @data, ('') x $skip_next if ($skip_next); } @@ -1026,6 +1027,10 @@ End of line style. Default is Unix. Include headers? Default is yes. +=item encoding + +Character encoding. Default is UTF-8. + =back =head1 SEE ALO -- 2.20.1