PHP smarty generates the Excel document code

Source: Internet
Author: User

However, according to my test, if you do not delete a place, the generated document will be opened in Excel and an error will be reported!

Delete all strings like this: SS: expandedcolumncount = "5!

Example:

Enter the data and submit it. An xls file is generated.

Another small problem has not been found. This template can only have two pieces of data. If there is more data, it will not work. Dizzy. I still have no idea where to modify it.

In addition, I first wrote formvalidate. php and report. php together, and the result was no result!
Write separately, and the result will be displayed!

Report. phpCopyCodeThe Code is as follows: <? 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. 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; filenameappsreport.xls ");
$ GMT-> display ('report ');
}
?>

header ("cache-control: Public");
This must be added. Otherwise, an error occurs 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.