您的位置:手机购彩平台 > 手机购彩平台-编程 > '工长电话'

'工长电话'

2019-09-27 05:56

<?php
header('Content-Type: application/vnd.ms-excel');

header("Accept-Ranges:bytes");
header('Content-Disposition: attachment; filename=demo.xls');
header('Pragma: no-cache');
header('Expires: 0');

$title = array(
  'chief_id' => '工长ID',
  'name' => '工长姓名',
  'mobile' => '工长电话',
  'Invitation' => '是否受邀',
  'sign' => '签到情况',
  'sign_time' => '签到时间',
  'imei' => '设备信息'
);
$sign_in_list= Array
(
[0] => Array
(
[chief_id] => 5
[name] => 测试临时表2
[mobile] => 13520037563
[Invitation] => 是
[sign] => √
[sign_time] => 1478576359
[imei] => 测试1
)
)

Array_unshift($sign_in_list, $title);

方法一

echo iconv('utf-8', 'gbk', implode("t", $title)), "n";
foreach ($sign_listas $value) {
echo iconv('utf-8', 'gbk', implode("t", $value)), "n";
}

方法二

echo '<head>
   <!--[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>';    //不加head标签 导出excel后没有网格线
echo "<table>";
foreach ($sign_in_list as $key=>$value) {
    echo "<tr>";
    echo "<td>".iconv('utf-8', 'gbk', $value['chief_id'])."</td>";
    echo "<td>".iconv('utf-8', 'gbk', $value['name'])."</td>"."t";
    echo "<td>".iconv('utf-8', 'gbk', $value['mobile'])."</td>"."t";
    echo "<td>".iconv('utf-8', 'gbk', $value['Invitation'])."</td>"."t";
    echo "<td>".iconv('utf-8', 'gbk', $value['sign'])."</td>"."t";
    echo "<td>".iconv('utf-8', 'gbk', $value['sign_time'])."</td>"."t";
    echo "<td>".iconv('utf-8', 'gbk', $value['imei'])."</td>"."t";
    echo "</tr>";
    echo "n";
    //echo iconv('utf-8', 'gbk', implode("t", $value)), "n";
}
echo "</table>";
/*
1) 文本:vnd.ms-excel.numberformat:@
2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
3) 数字:vnd.ms-excel.numberformat:#,##0.00
4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
5) 百分比:vnd.ms-excel.numberformat: #0.00%
用法<td style='vnd.ms-excel.numberformat:@'>".$printable."</td> 主要解决数据格式问题
上述两种都是最简单的PHP导出excel方法 都会有瑕疵 
第一种 如果像手机号一类的文本数据 会显示科学计数法 如果用鼠标拉伸表格长度会完全显示
两种方法生成的excel文件再打开的时候都会提示
目前还没解决  哪位大神有好的解决办法可以交流
*/

?>

本文由手机购彩平台发布于手机购彩平台-编程,转载请注明出处:'工长电话'

关键词: