【问题标题】:Exporting PHP output into Microsoft Excel将 PHP 输出导出到 Microsoft Excel
【发布时间】:2013-10-19 08:45:29
【问题描述】:

我正在尝试在 PHP 页面中转换名为“Update2”的表的内容。

这是转换器:

header("Content-type: application");
header("Content-Disposition: attachment; filename=myfilename.xls");

这是代码部分:

<?php
$output_sql="select * from update2 where update_com_ag=1 order by update_fullname ASC";
$output_query=mysql_query($output_sql,$con);
while($output=mysql_fetch_array($output_query)){?>
<tr>
    <td valign="top"><?php echo strtoupper($output['telephone_number']);?></td>
</tr>
<?php }?>

但是,假设电话号码是 1601000021056,excel 文件中的输出将是 1.601E+12。有什么解决方案可以解决这个问题吗?我尝试了几种方法,但仍然无法正常工作。

谢谢大家!!

【问题讨论】:

  • 为什么不用空格分隔电话号码和区号?

标签: php excel transfer


【解决方案1】:

转到 Excel,突出显示电话号码列。右键单击并转到设置单元格格式。转到数字选项卡。然后在左侧,您可以选择不同的格式。像带有 0 位小数的数字可能会这样做。

【讨论】:

    【解决方案2】:

    由于空间限制,Excel 程序以该格式显示。增加列宽,它会正确显示数字。

    【讨论】:

      【解决方案3】:

      在 excel 中,如果您在一个值前面加上一个单引号,它将将该值视为字符串,即使它是一个数字。不确定它是否适用于您的导出方法,但值得一试。

      <tr>
          <td valign="top">'<?php echo strtoupper($output['telephone_number']);?></td>
      </tr>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多