PHP Export Chinese content Excel file class instance,
The example in this article describes the PHP export Chinese content Excel file class. Share to everyone for your reference. Specific as follows:
<?php class toexcel{public $link = null; function __construct () {}/*************************************************************************** * $ Mapping: Array header information $map=array (' No ', ' Name ', ' Email ', ' age '); * $datalist: Result set found in database * $fileName: Excel file name * return:excel format file **************************************************** /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." | "; Numbers greater than 14 bits are converted to string output (such as ID)}else{echo "
". $val." | "; }} Echo '
'; } Echo '
'; Echo'; Echo'; }} $map =array (' No ', ' Name ', ' Email '); $datal =array (Array (1, ' admin ', ' admin@163.com '), Array (2, ' member ', ' member@163.com '));; $csv =new Toexcel; $csv->toexcel ($map, $datal, "dataexport");?>
Method Two
<?php header ("content-type:application/vnd.ms-execl"); Header ("content-disposition:attachment; Filename=myexcel.xls "); Header ("Pragma:no-cache"); Header ("expires:0"); /*first line*/$data 1 = "Chinese test"; $data 1=mb_convert_encoding ($data 1, "GB2312", "UTF-8"); echo $data 1. " \ t "; echo "World". " \ t "; echo "\t\n"; /*start of second line*/echo "This was second line". " \ t "; echo "Hi,pretty girl". " \ t "; echo "\t\n";?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1027495.html www.bkjia.com true http://www.bkjia.com/PHPjc/1027495.html techarticle PHP export Chinese content Excel file class instance, this article describes the PHP export Chinese content Excel file class. Share to everyone for your reference. The following: PHP class toexcel{public $ ...