PHP Export Chinese content Excel file class instance, _php tutorial

Source: Internet
Author: User

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 " 
    "; } Echo ' 
   '; foreach ($datalist as $k = + $v) {echo ' 
   
     '; foreach ($v as $key = + $val) {if (Is_numeric ($val) && strlen ($val) >=14) {echo] 
    "; Numbers greater than 14 bits are converted to string output (such as ID)}else{echo " 
    "; }} Echo ' 
   '; } Echo ' 
  
". $val."
". $val."". $val."
'; 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 $ ...

  • Related Article

    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.