当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP Smarty生成EXCEL文档的代码

PHP Smarty生成EXCEL文档的代码

2019年05月10日  | 移动技术网IT编程  | 我要评论
不过,跟据我的试验,如果你不删除一个地方,生成的文档用 excel 打开,是会报错的!

删除所有像这样的串: ss:expandedcolumncount="5" 就行了!

示例:

随便填点数据,然后提交,会生成一份 xls 文件。

还有一个小问题没有找出来,这个模板,只能有两笔数据,多了也不行,晕,还没有找到要修改哪里呢。

另外,我开始是把 formvalidate.php 和 report.php合在一起写的,结果是没有结果!
分开写,就有结果了!

report.php
复制代码 代码如下:

<?php
include '../common.inc.php';

$token = $_post['token'];

if(gtoken::istoken($token,'report')){
$names = $_post['name'];
$birthdays = $_post['birthday'];
$phones = $_post['phone'];
$sexs = $_post['sex'];
$emails = $_post['email'];
$scoreas = $_post['scorea'];
$scorebs = $_post['scoreb'];
$scorecs = $_post['scorec'];

$list = array();
$score = array();

for($i=0;$i<sizeof($names);$i++){
$arr = array(
'name' => $names[$i],
'sexs' => $sexs[$i],
'birthday' => $birthdays[$i],
'email' => $emails[$i],
'phone' => $phones[$i]
);
array_push($list,$arr);
unset($arr);

$arr = array(
'name' => $names[$i],
'scorea' => $scoreas[$i],
'scoreb' => $scorebs[$i],
'scorec' => $scorecs[$i]
);
array_push($score,$arr);
unset($arr);
}

include '../lib/smarty/smarty.class.php';
$gmt = gsmarty::getinstance('test');
$gmt->assign_by_ref("list",$list);
$gmt->assign_by_ref('score',$score);

header("cache-control: public");
header('content-type:application/vnd.ms-excel');
header("content-disposition:attachment; filename=report.xls");
$gmt->display('report');
}
?>

header("cache-control: public");
这一定要加,不然的话,在ie下会发生错误。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网