温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php怎么导出中文内容excel文件类

发布时间:2021-08-03 18:42:54 来源:亿速云 阅读:165 作者:chen 栏目:开发技术

本篇内容介绍了“php怎么导出中文内容excel文件类”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

本文实例讲述了php导出中文内容excel文件类。分享给大家供大家参考。具体如下:

<?php  class toExcel{   public $link = null;   function __construct(){   }    /***************************************************************************   * $mapping:数组格式头信息$map=array('No','Name','Email','Age');   * $datalist:数据库查出来的结果集   * $fileName:Excel文件名称   * return:Excel格式文件   **************************************************************************/   public function toExcel($mapping,$datalist,$fileName) {    header("Content-type:application/vnd.ms-excel");    header("Content-Disposition:filename=".iconv('utf-8', 'gb2312', $fileName).".xls");    echo'<html xmlns:o="urn:schemas-microsoft-com:office:office"    xmlns:x="urn:schemas-microsoft-com:office:excel"    xmlns="[url=http://www.w3.org/TR/REC-html40]http://www.w3.org/TR/REC-html40[/url]">    <head>    <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">    <meta http-equiv=Content-Type content="text/html; charset=UTF-8">    <!--[if gte mso 9]><xml>    <x:ExcelWorkbook>    <x:ExcelWorksheets>    <x:ExcelWorksheet>    <x:Name></x:Name>    <x:WorksheetOptions>    <x:DisplayGridlines/>    </x:WorksheetOptions>    </x:ExcelWorksheet>    </x:ExcelWorksheets>    </x:ExcelWorkbook>    </xml><![endif]-->    </head>    <body link=blue vlink=purple leftmargin=0 topmargin=0>';    echo'<table border="0" cellspacing="0" cellpadding="0">';    echo'<tr>';    if(is_array($mapping)) {     foreach($mapping as $key=>$val)     echo"<td style='background-color:#09F;font-weight:bold;'>".$val."</td>";    }    echo'</tr>';    foreach($datalist as $k=>$v){     echo'<tr>';     foreach($v as $key=>$val){      if(is_numeric($val) && strlen($val)>=14){       echo"<td style='vnd.ms-excel.numberformat:@'>".$val."</td>"; //大于14位的数字转换成字符串输出(如身份证)      }else{       echo"<td>".$val."</td>";      }     }     echo'</tr>';    }    echo'</table>';    echo'</body>';    echo'</html>';   }  }  $map=array('No','Name','Email');  $datal=array(array(1, '管理员', 'admin@163.com'), array(2, 'member', 'member@163.com'));;  $csv=new toExcel;  $csv->toExcel($map,$datal,"dataexport");  ?>

方法二

<?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= "中文测试";  $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";  ?>

“php怎么导出中文内容excel文件类”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI