我正在做一个项目,我需要存储一个 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;
}
?>
最佳答案
MS Excel 不喜欢大数字。它建议,如果您不需要对数字进行任何数学运算,请将单元格类型更改为文本(类似于您使用 varchar 在 mysql 中存储数字的原因)。
解决方法可能是将文件作为 .csv 输出并下载,并在 Excel 中打开,并使用列的文本格式。
否则,我认为您应该能够使用 PHPExcel 进行此格式化
关于PHP 和 MYSQL : Convert 25 character long string to number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40316328/