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.