Bug 33635: Add BOM to report exports as CSV

When you export a report as CSV excel will not recognise that it's
encoding is utf-8 unless there is a correct Byte Order Mark prepended to
the file.

This patch adds such a BOM to the output file allowing Excel to treat
the file correctly.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2024-09-18 05:42:41 +01:00
parent 996c9d9fdc
commit 0d25a2bacf
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -646,6 +646,10 @@ elsif ($op eq 'export'){
if ( $format eq 'csv' ) {
my $delimiter = C4::Context->csv_delimiter;
$type = 'application/csv';
# Add BOM for UTF-8 encoded CSV
$content .= "\xEF\xBB\xBF";
my $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter});
$csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag();
if ( $csv->combine( header_cell_values($sth) ) ) {