PHPSmarty: code _ php instance for generating EXCEL documents

Source: Internet
Author: User
Tags smarty template
PHP and Smarty generate EXCEL document 1. First, generate a template in EXCEL (office2003) and save it as an xml table. 2. Modify the xml file to form a smarty template. 3. Then, bind the variable and output it. 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. php

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; filenameappsreport.xls ");
$ Gmt-> display ('report ');
}
?>


Header ("Cache-Control: public ");
This must be added. Otherwise, an error will occur 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.