I had troubles getting correct csv export with our special german and french chars like äöü éè etc. to display correctly in output
So i changed following in code and it works for me perfectly, but as i am absolutely drupal beginner, I hope any of you professionals can review it.
file webform_report.inc
~line 865: required other delimiter for my excel2010 to recognize automatically
$output .= implode(',', $tmp) . "\n";
to new
$output .= implode(';', $tmp) . "\n";
~line 862-864: required to convert characters correctly
foreach($row as $cell) {
$tmp[] = _webform_report_format_csv_column(strip_tags($cell['data']));
}
to new
foreach($row as $cell) {
if (function_exists('mb_convert_encoding')) {
$tmp[] = _webform_report_format_csv_column(strip_tags(mb_convert_encoding($cell['data'], 'UTF-16LE', 'UTF-8')));
}
else {
$tmp[] = _webform_report_format_csv_column(strip_tags($cell['data']));
}
}
~line 857: same for header
$output .= implode(',', $tmp) . "\n";
to new
$output .= implode(';', $tmp) . "\n";
~line 854-856
foreach($headers as $header) {
$tmp[] .= _webform_report_format_csv_column($header['data']);
}
to new
foreach($headers as $header) {
if (function_exists('mb_convert_encoding')) {
$tmp[] .= _webform_report_format_csv_column(mb_convert_encoding($header['data'], 'UTF-16LE', 'UTF-8'));
}
else {
$tmp[] .= _webform_report_format_csv_column($header['data']);
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 945396.patch | 15.64 KB | jimbullington |
Comments
Comment #1
jimbullington commentedThank you for contributing this patch - it looks good. However, I do not have experience nor the test environment to review this - perhaps others more qualified will review it.
Also, I would like to see if we can come up with some sort of administrative setup for this behavior - instead of hard coding the delimiter.
Comment #2
sw3b commentedHey any news on this issue ! The patch does not work ! The special charaters does not follow in Excel on export.
Thanks !
Comment #3
sw3b commentedOK, we got a correction for you !
On line 1218
Replace:
$tmp[] .= _webform_report_format_csv_column($header['data']);
By:
$tmp[] .= _webform_report_format_csv_column(mb_convert_encoding($header['data'], 'UTF-16LE', 'UTF-8'));
On line 1233
Replace:
$data = strip_tags($cell['data']);
By:
$data = strip_tags(mb_convert_encoding($cell['data'], 'UTF-16LE', 'UTF-8'));
Comment #4
jimbullington commentedThank you for the export code. However, I think this needs to be an option (plain text, or excel) similar to what is done in webforms. I will try to come up with the option form in the next couple of days.
Comment #5
jimbullington commentedTry the attached patch.
Comment #6
sw3b commentedWow ! Nice work ! It work great !
I think you should put this in DEV !
Thanks !
Comment #7
jimbullington commentedCommitted to CVS - should be available in the next dev build.