Shimokita glory days PHP smarty code to generate Excel documents

Source: Internet
Author: User
However, according to my experiment, if you do not delete a place, the generated document opened with Excel, will be error!
Delete all the strings like this: ss:expandedcolumncount= "5" on the line!
Example:
Fill in the data, then submit, generate an XLS file.
There is a small problem not to find out, this template, can only have two data, more also not, dizzy, have not found to modify where it.
In addition, I started to put formvalidate.php and report.php together to write, the result is no result!
Write separately, there is the result!
report.php

Copy the Code code 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 describes the Shimokita glory days PHP Smarty generated Excel document code, including the Shimokita glory days content, I hope to be interested in PHP tutorial friends helpful.

  • 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.