我在数据库中有新行的数据。
例如:
Testing Habit
Testing Habit Testing Habit
Testing Habit Testing Habit Testing Habit
我想在csv下载文件中显示带空格的数据,而不是新行。
现在我正在使用PHPExcel库下载csv文件。
这是我的代码:
$output_file_name = "myfile";
$output_file = $output_file_name . ".csv";
$output_file = mb_convert_encoding($output_file, "SJIS", "UTF-8");
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();
$sheet->setCellValue("A1", '"'.str_replace(chr(10), ' ', $info['ModelName']['habits']).'"');
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename="'.$output_file.'"');
header('Cache-Control: max-age=0');
header("Pragma: no-cache");
header("Expires: 0");
$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
$objWriter->setDelimiter(',');
$objWriter->setEnclosure('');
$objWriter->setLineEnding("\r\n");
$objWriter->setSheetIndex(0);
$objWriter->setUseBOM(true);
$objWriter->save('php://output');
如何删除换行符?