Skip to content

Commit

Permalink
Fixed issue: Better Excel compatibility for multiline response fields
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Feb 2, 2018
1 parent 7b91558 commit 1174354
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions application/helpers/admin/export/CsvWriter.php
Expand Up @@ -34,12 +34,9 @@ function __construct()
public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
{
parent::init($survey, $sLanguageCode, $oOptions);

$this->csvFilename = "results-survey".$survey->id.".csv";

if ($oOptions->output == 'file') {
$this->file = fopen($this->filename, 'w');
fwrite($this->file,"\xEF\xBB\xBF"); // Write UTF-8 Byte Order Mark (BOM)
}

}
Expand All @@ -51,6 +48,9 @@ protected function outputRecord($headers, $values, FormattingOptions $oOptions)
if ($oOptions->output == 'display') {
header("Content-Disposition: attachment; filename=".$this->csvFilename);
header("Content-type: text/comma-separated-values; charset=UTF-8");
echo chr(239) . chr(187) . chr(191);
} else {
fwrite($this->file, chr(239) . chr(187) . chr(191)); // Write UTF-8 Byte Order Mark (BOM)
}

// If we don't want headers in our csv, for example in exports like r/spss etc. we suppress the header by setting this switch in the init
Expand Down Expand Up @@ -85,9 +85,9 @@ protected function outputRecord($headers, $values, FormattingOptions $oOptions)
public function close()
{
// Output white line at the end, better for R import
echo "\n";
echo "\r\n";
if (!is_null($this->file)) {
fwrite($this->file, "\n");
fwrite($this->file, "\r\n");
fclose($this->file);
}
}
Expand Down

1 comment on commit 1174354

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe time to use fputcsv for csv generation :)

Please sign in to comment.