From: Bernd Bleßmann Date: Fri, 23 Sep 2016 13:31:21 +0000 (+0200) Subject: ReportGenerator: CSV-Export: Encoding als Option angeben können. X-Git-Tag: release-3.5.4~2023 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d9ab23fa13ade3503b0a95cdafaa4bc755d94dba;p=kivitendo-erp.git ReportGenerator: CSV-Export: Encoding als Option angeben können. Default bleibt UTF-8. --- 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