首页 > 解决方案 > 大整数在excel中以科学计数法显示

问题描述

我正在使用下面的 php 将 mysql 数据导出到 excel 表中。

<?php
header("Content-Type: application/xls");    
header("Content-Disposition: attachment; filename=$filename.xls");  
header("Pragma: no-cache"); 
header("Expires: 0");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <th class="excel_style">Order Type</th>
    <th class="excel_style">Order Number</th>
    <th class="excel_style">EAN</th>
    <th class="excel_style">Article #</th>
</tr>
<?php
// mysqli query comes here
while($result = mysqli_fetch_assoc($res)){?>
<td><?php echo $result['order_type'] ;?></td>
<td><?php echo $result['order_number'];?></td>
<td><?php echo $result['EAN'];?></td>
<td><?php echo $result['article_number'];?></td>
</tr>
<?php } ?>
</table>

一切正常,但在 EAN 和文章 # 列中生成 excel 报告后,值显示为科学计数法,如下所示。 4.04623E+12 but the original value is - 4046228026756. 因此,当用户打开 Excel 工作表时,相关列应显示为原始值。我怎样才能做到这一点?任何帮助将不胜感激。

有没有办法告诉excel单元格的数据类型是String类型。像下面的一些东西
$excel1->setActiveSheetIndex(0)->setCellValueExplicit('C'.$k, $row['EAN'],PHPExcel_Cell_DataType::TYPE_STRING)

标签: phpmysqlexcel

解决方案


推荐阅读