怎么解决从php导出的excel文件打开时弹出文件格式不一致问题(还有无边框显示问题,见“问题补充”)
代码:<?php$filename="excel.xls";//定义一个excel文件header("Content-Type:application/vnd.ms-ex...
代码:
<?php
$filename="excel.xls";//定义一个excel文件
header("Content-Type: application/vnd.ms-execl");
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
include "config.php";
mysql_select_db('umi_statistic',$conn);
$id=$_GET['id'];
$arr=mysql_query("select * from user_title where id='$id'",$conn);
$result=mysql_fetch_array($arr);
$table_name=$result['table_name'];
$n=$result['table_num'];
$sql=mysql_query("select * from $table_name");
echo "<table style='font-size:16px;'>";
while($row=mysql_fetch_array($sql))
{
echo"<tr>";
for($i=1;$i<=$n;$i++)
{
echo "<td>$row[$i]</td>";
//echo iconv("utf-8", "gb2312", $row[$i])."\t";
}
echo "</tr>";
}
echo"</table>";
mysql_free_result($sql);
mysql_free_result($arr);
mysql_close($conn);
弹出提示:
背景全白色:
我想要这种效果:即表格边框能正常显示
已经在网上找过资料,没找到合适的方法。phpExcel有点复杂,想偷懒用上面的方法实现,望帮忙解决~ 展开
<?php
$filename="excel.xls";//定义一个excel文件
header("Content-Type: application/vnd.ms-execl");
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
include "config.php";
mysql_select_db('umi_statistic',$conn);
$id=$_GET['id'];
$arr=mysql_query("select * from user_title where id='$id'",$conn);
$result=mysql_fetch_array($arr);
$table_name=$result['table_name'];
$n=$result['table_num'];
$sql=mysql_query("select * from $table_name");
echo "<table style='font-size:16px;'>";
while($row=mysql_fetch_array($sql))
{
echo"<tr>";
for($i=1;$i<=$n;$i++)
{
echo "<td>$row[$i]</td>";
//echo iconv("utf-8", "gb2312", $row[$i])."\t";
}
echo "</tr>";
}
echo"</table>";
mysql_free_result($sql);
mysql_free_result($arr);
mysql_close($conn);
弹出提示:
背景全白色:
我想要这种效果:即表格边框能正常显示
已经在网上找过资料,没找到合适的方法。phpExcel有点复杂,想偷懒用上面的方法实现,望帮忙解决~ 展开
2个回答
展开全部
没有你的数据,做了个测试,可以导出,但是还会报你说的错误,但是不影响内容,应该是导出的文件并不是excel格式的,只是命名成excel文件而已吧。下面代码可以解决边框问题:
<?php
$filename="excel.xls";//定义一个excel文件
header("Content-Type: application/vnd.ms-execl");
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
$testArr = array("test1"=>array('test','test','test'),"test2"=>array('test2','test2','test2'));
foreach($testArr as $val){
foreach( $val as $v ){
echo $v."\t";
}
echo "\n";
}
?>
<?php
$filename="excel.xls";//定义一个excel文件
header("Content-Type: application/vnd.ms-execl");
header("Content-Type: application/vnd.ms-excel; charset=gb2312");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
$testArr = array("test1"=>array('test','test','test'),"test2"=>array('test2','test2','test2'));
foreach($testArr as $val){
foreach( $val as $v ){
echo $v."\t";
}
echo "\n";
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询