PHP Smarty Code _php instance for generating Excel documents

Source: Internet
Author: User
However, according to my experiment, if you do not delete a place, the resulting document opened in Excel, it will be an error!

Delete all strings like this: ss:expandedcolumncount= "5" on the line!

Example:

Just fill in some data, then submit, will generate an XLS file.

There is a small problem did not find out, this template, can only have two data, many also not, Halo, has not found to change where it.

In addition, I began to put formvalidate.php and report.php together to write, the result is no result!
Separate write, there will be results!

report.php
Copy Code code as follows:

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

$token = $_post[' token '];

if (Gtoken::istoken ($token, ' ') ') {
$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 (' the ');
}
?>

Header ("Cache-control:public");
This must be added, otherwise, there will be an error in IE.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.