Php exports an excel file class instance of Chinese content ,. An example of the php excel file class for exporting Chinese content. this example describes how to export Chinese content from php excel files. Share it with you for your reference. The details are as follows: phpclasstoExcel {public $ php exports the Chinese content excel file class instance,
An example of this article describes how to export Chinese content in php excel files. Share it with you for your reference. The details are as follows:
<? Php class toExcel {public $ link = null; function _ construct () {}/************************************* ************************************* $ mapping: array format header information $ map = array ('no', 'name', 'Email ', 'age'); * $ datalist: result set found by the database * $ fileName: excel file name * return: ************************************* * ***********************************/public function toExcel ($ mapping, $ datalist, $ fileName) {header ("Content-type: application/vnd. ms-excel "); header (" Content-Disposition: filename = ". iconv ('utf-8', 'gb2312 ', $ fileName ). ". xls "); echo'
'; Echo'
'; Echo'
'; If (is_array ($ mapping) {foreach ($ mapping as $ key => $ val) echo"
| ". $ Val ." | ";} Echo'
'; Foreach ($ datalist as $ k => $ v) {echo'
'; Foreach ($ v as $ key => $ val) {if (is_numeric ($ val) & strlen ($ val) >=14) {echo"
| ". $ Val ." | "; // Convert a number greater than 14 characters into a string output (such as ID card)} else {echo"
". $ Val ." | ";}} Echo'
';} Echo'
'; Echo''; Echo'';}}$ Map = array ('no', 'name', 'Email'); $ datal = array (1, 'admin ', 'admin @ 163.com '), array (2, 'Member', 'Member @ 163.com '); $ csv = new toExcel; $ csv-> toExcel ($ map, $ datal, "dataexport");?>
Method 2
<? Php header ("Content-Type: application/vnd. ms-execl "); header (" Content-Disposition: attachment; filename=myExcel.xls "); header (" Pragma: no-cache "); header (" Expires: 0 "); /* first line */$ data1 = "Chinese test"; $ data1 = mb_convert_encoding ($ data1, "GB2312", "UTF-8"); echo $ data1. "\ t "; echo "world ". "\ t"; echo "\ t \ n";/* start of second line */echo "this is second line ". "\ t"; echo "Hi, pretty girl ". "\ t"; echo "\ t \ n "; ?>
I hope this article will help you with php programming.
Example: This article describes how to export Chinese content to an excel file in php. Share it with you for your reference. Php class toExcel {public $...