导出excel表时本来是一个字段里的内容,导出来时却到了第二行

WBOY
Release: 2016-06-23 13:33:59
Original
1244 people have browsed it

//开始导出
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=xueyuan_list_data.xls");

echo mb_convert_encoding('备注','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;
}

由于数据beizhu在提交时是textarea,所以beizhu这个字段中会含有换行符,导出时,一旦内容里有换行的,那么第二行就会显示到excel表的另一行去,但我想要的是beizhu这个字段里的所有内容只显示在excel表里的“备注”这一格里,请问应该怎么办?


回复讨论(解决方案)

$beizhu = mb_convert_encoding($arr['beizhu'],'GBK','UTF-8');$beizhu = '"' . preg_replace(("/[\r\n]+/", "\n", $beizhu) . '"';echo $beizhu . "\t";
Copy after login


即将 回车换行符都换成换行符(Linux 的文档不需要,但考虑到文档可能来自 Windows 或者 Mac,做一下没坏处)
然后用标准的 csv 格式(字段应用双引号括起)包装起来

测试了一下,不必替换回车换行
只需将输出串用双引号包裹起来就可以了

可以了谢谢。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!