php导出中文内容excel文件类实例

(编辑:jimmy 日期: 2025/6/28 浏览:2)

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

<"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"); 
"htmlcode">
<"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程序设计有所帮助。

一句话新闻

微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。