Home >Backend Development >PHP Tutorial >php导出excel中,若数据库一列内容中存在换行,则在excel中对应换成多行,如何解决?

php导出excel中,若数据库一列内容中存在换行,则在excel中对应换成多行,如何解决?

WBOY
WBOYOriginal
2016-06-23 13:33:101448browse

php导出excel中,若数据库一列内容中存在换行,则在excel中对应换成多行,如何解决?
代码如下:

<?php //验证是否已登录include 'remember_password.php';	header("Accept-Ranges: bytes");	header("Content-type: application/vnd.ms-excel");	header("Content-Disposition: attachment; filename=".$filename);	include("connect.php");	$sql="select * from specific_step";	$query = mysql_query($sql);	echo "序号\t业务名称\t操作步骤\t备注\t录入人\t录入日期";	while($row = mysql_fetch_array($query)){		echo "\n";		echo $row['serial_number']."\t".$row['name']."\t".$row['step']."\t".$row['other']."\t".$row['input_name'].		"\t".$row['input_date'];	}?>


回复讨论(解决方案)

测试例

header("Accept-Ranges: bytes");header("Content-type: application/vnd.ms-excel");header("Content-Disposition: attachment; filename=".@$filename);$ar = array(  "abcd123",  "再来一段换行再换行");echo "序号\t备注\n";foreach($ar as $k=>$v) {  echo "$k\t\"$v\"\n";}

测试例

header("Accept-Ranges: bytes");header("Content-type: application/vnd.ms-excel");header("Content-Disposition: attachment; filename=".@$filename);$ar = array(  "abcd123",  "再来一段换行再换行");echo "序号\t备注\n";foreach($ar as $k=>$v) {  echo "$k\t\"$v\"\n";}



用于从数据库中倒数还是不好用呢?你的代码都是双引号吗

测试例

header("Accept-Ranges: bytes");header("Content-type: application/vnd.ms-excel");header("Content-Disposition: attachment; filename=".@$filename);$ar = array(  "abcd123",  "再来一段换行再换行");echo "序号\t备注\n";foreach($ar as $k=>$v) {  echo "$k\t\"$v\"\n";}



不好意思,刚才字符输入错了,你的很好用,谢谢。
Statement:
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