Php exports Chinese content excel file class instance, _ PHP Tutorial

Source: Internet
Author: User
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"
    ";} Echo'
   '; Foreach ($ datalist as $ k => $ v) {echo'
   
    
'; Foreach ($ v as $ key => $ val) {if (is_numeric ($ val) & strlen ($ val) >=14) {echo"
    "; // Convert a number greater than 14 characters into a string output (such as ID card)} else {echo"
    ";}} Echo'
   ';} Echo'
  
". $ Val ."
". $ Val ."". $ Val ."
'; 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 $...

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.