Excel export-PHP source code

Source: Internet
Author: User
Excel export
 'Name', 'title' => 'title ') the key name is associated with the subelement key name of the following array $ data * @ param $ data array */public static function exportFile ($ fileName, $ title = '', $ firstRow = array (), $ data = array () {header ('content-Type: application/vnd. ms-execl '); header ('content-Disposition: attachment; filename = '. $ fileName. '.xls '); header ('pragma: no-cache'); header ('expires: 0'); if (! Empty ($ title) {echo self: excelExportIconv ($ title ). "\ t \ n";}/*** the first row is associated with the subsequent data by key name */if (! Empty ($ firstRow) & is_array ($ firstRow) {// output the first line of content foreach ($ firstRow as $ first) {echo self: excelExportIconv ($ first ). "\ t";} echo "\ n"; if (! Empty ($ data) & is_array ($ data) {foreach ($ data as $ item) {foreach ($ firstRow as $ _ key = >$ _ val) {if (isset ($ item [$ _ key]) {echo self: excelExportIconv ($ item [$ _ key]). "\ t";} else {echo self: excelExportIconv (''). "\ t" ;}} echo "\ n" ;}} else {if (! Empty ($ data) & is_array ($ data) {foreach ($ data as $ item) {foreach ($ item as $ val) {echo self :: excelExportIconv ($ val ). "\ t";} echo "\ n";} echo "\ n" ;}}}/ *** example: */$ fileName = 'example '; $ title = 'This is title'; $ firstRow = array ('id' => 'id', 'name' => 'name ', 'title' => 'title'); $ data = array ('id' => 1, 'name' => 'name 1 ', 'title' => 'Title 1'), array ('id' => 2, 'name' => 'name 2', 'title' => 'Title 2' ), Array ('id' => 3, 'name' => 'name 3', 'title' => 'Title 3 '), array ('id' => 4, 'name' => 'name 4', 'title' => 'Title 4'),); Excel_tool: exportFile ($ fileName, $ title, $ firstRow, $ data);?>

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.