Home > Backend Development > PHP Tutorial > shimokita glory days PHP Smarty code to generate EXCEL documents

shimokita glory days PHP Smarty code to generate EXCEL documents

WBOY
Release: 2016-07-29 08:38:37
Original
1078 people have browsed it

However, according to my experiments, if you do not delete a place and the generated document is opened in excel, an error will be reported!
Delete all strings like this: ss:ExpandedColumnCount="5" and that's it!
Example:
Fill in some data and submit, an xls file will be generated.
There is still a small problem that I haven’t found out yet. This template can only have two pieces of data, not more. I’m dizzy. I haven’t found where to modify it yet.
In addition, I initially wrote formValidate.php and report.php together, but there was no result!
Write them separately and you will get the result!
report.php

Copy the code The code is as follows:


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$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");
This must be added, otherwise, an error will occur under IE.

The above introduces the code for shimokita glory days PHP Smarty to generate EXCEL documents, including the content of shimokita glory days. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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