When exporting an excel table, it is originally the content of a field, but it is exported to the second row // start to export
Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: attachment?filename=xueyuan_list_data.xls ");
Echo mb_convert_encoding ('note', 'gbk', 'utf-8'). "\ t ";
$ Xuhao = 1;
Foreach ($ arr_xueyuan_list as $ arr)
{
Echo "\ n ";
Echo $ xuhao. "\ t ";
Echo mb_convert_encoding ($ arr ['beizhu'], 'gbk', 'utf-8'). "\ t ";
$ Xuhao = $ xuhao + 1;
}
Because the data beizhu is textarea when it is submitted, the beizhu field contains a line break. During export, once the content contains a line break, the second row is displayed in another row of the excel table, but all the content in the beizhu field is displayed only in the "remarks" field of the excel table, what should I do?
Reply to discussion (solution)
$beizhu = mb_convert_encoding($arr['beizhu'],'GBK','UTF-8');$beizhu = '"' . preg_replace(("/[\r\n]+/", "\n", $beizhu) . '"';echo $beizhu . "\t";
Changing line breaks to line breaks (Linux documents are not required, but considering that the documents may come from Windows or Mac, there is no harm in doing so)
Then packaged in standard csv format (fields are enclosed in double quotation marks)
After testing, you do not have to replace the carriage return and line feed.
You only need to enclose the output string with double quotation marks.
Thank you.