jbrunoxd
jbrunoxd

Reputation: 222

PHPExcel add "sep=;" at the start of CSV file

Is there any function on PHPExcel that defines the separator at the start of a CSV file? i know that adding "sep=;" at the start of the file make Excel understand that the separator is a semicolon, but i cant find any function that does this on PHPExcel, not even a way before saving the archive, cause i put it directly at php://output to download it directly.

here's a sample of what im doing now:

$exportName = $className.'_'.date('d/m/Y H:i');
$objWriter = \PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'CSV');
$objWriter->setDelimiter(';');
$objWriter->setUseBOM(true);
$contentType = 'Content-Type: text/csv; charset=utf-8' 
header($contentType);
header('Content-Disposition: attachment;filename="'.$exportName.'.'.$this->type.'"');
$objWriter->save('php://output');

Upvotes: 1

Views: 678

Answers (1)

Yusuf Mukharom
Yusuf Mukharom

Reputation: 11

Try adding setIncludeSeparatorLine work like a charm

$writer = new Csv($spreadsheet);
$writer->setDelimiter(';');
$writer->setEnclosure('"');
$writer->setLineEnding("\r\n");
$writer->setIncludeSeparatorLine(true);

Upvotes: 1

Related Questions