PHP和MYSQL:将25个字符的长字符串转换为数字

时间:2016-10-29 05:30:37

标签: php mysql excel

我正在研究一个项目,我需要存储一个25位数字。当我尝试使用BIGINT数据格式时,会显示超出范围。然后我使用 VARCHAR 数据类型存储它。但我还需要将其导出到MS-EXCEL表格中。 当我导出它时,Excel只显示13-14个更高的数字,剩下的更低的数字将四舍五入到使其 0

我的源代码如下:

<?php
$conn = mysqli_connect("localhost", "root", "", "dis");

$output='';

$sql= "SELECT `polid`, `inscompanyid`, polno FROM `policies` order by polid desc";
$res = mysqli_query($conn, $sql)  or die(mysqli_error($conn));
if(!$res || mysqli_num_rows($res)){
    $output .='
        <table class="table" border="1">
            <tr>
                <th>asdf</th>
                <th>qwer</th>
                <th>zcxv</th>
            </tr>
    '; 
    while($row=mysqli_fetch_assoc($res))
    {
        $output.='
            <tr>
                <td>'.$row["polid"].'</td>
                <td>'.$row["inscompanyid"].'</td>
                <td>'.$row["polno"].'</td>
            </tr>
        ';
    }
    $output.='</table';
    //header("Content-Type: application/xls");
    //header("Content-Disposition: attachment; filename=download.xls");
    echo $output;
}

?>

1 个答案:

答案 0 :(得分:0)

根据此链接http://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_other/when-i-am-entering-16-digit-number-in-excel-its/7f50828d-77b4-4ad2-8ea7-0411d0236bd0

MS excel不喜欢大数字。它建议如果您不需要对数字进行任何数学运算,那么您将单元格的类型更改为文本(类似于使用varchar将数字存储在mysql中的原因)。

可能的解决方法是将文件作为.csv输出和下载,并在Excel中打开,并为列提供文本格式。

否则,我认为您应该能够使用PHPExcel进行格式化