Skip to content

Instantly share code, notes, and snippets.

@brahimmachkouri
Created January 24, 2016 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brahimmachkouri/82d7c53d30a8062c5a46 to your computer and use it in GitHub Desktop.
Save brahimmachkouri/82d7c53d30a8062c5a46 to your computer and use it in GitHub Desktop.
PHPExcel : Enregistrement CSV en ISO-8859-1, avec tabulation comme séparateur, pas de délimiteur, et retour à la ligne façon Windows.
// enregistrement du fichier
$objWriter = PHPExcel_IOFactory::createWriter($objWorksheet, 'CSV');
$objWriter->setEnclosure("");
$objWriter->setDelimiter("\t");
$objWriter->setLineEnding("\r\n"); // cr lf (Windows)
ob_start();
$objWriter->save('php://output');
$excelOutput = ob_get_clean();
// conversion en iso-8859-1, car PHPExcel genere de l'utf-8
$f = mb_convert_encoding($excelOutput, 'iso-8859-1');
$f = trim($f)."\r\n";
file_put_contents('export.txt',$f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment