页面加载时,我正在使用PHP在服务器中创建csv。我正在将数据附加到$output,以便在页面加载期间创建csv。 我有一列的帐户号类似于(6280720003789856)。它在我的网页中看起来是正确的,但是当我将数据下载为 CSV 时,它会自动更改为 (6.28072E+15)。我怎样才能阻止这种情况改变。
代码如下
<?php
$date_from = $_REQUEST['date_from'];
$date_to = $_REQUEST['date_to'];
$procedure = "call contract_compliance_givecentral_test1('".$date_from."','".$date_to."')";
$conn2 = new MyConnection;
$conn2->Connect();
$rs2 = $conn2->ExecSQL($procedure);
$output = '';
$givecentral_contract = "Documents/givecentral_contract.csv";
$filename = $givecentral_contract;
$fp = @fopen($filename, "w+");
$totalRows_rsnf_count = mysqli_num_rows($rs2);
if ($totalRows_rsnf_count > 0)
{
// Show if recordset not empty
?>
<div class="container" style="padding-left: 25px!important;padding-right: 25px!important;" id="printable_area">
<div class="head">Contract Compliance - Givecentral
<ul class="dashboard-icon">
<li><a title="Export to Excel" target="_blank" href="<?php echo
$givecentral_contract ?>">
</a>
</li>
</ul>
</div>
<div id="loader">
<b>Please Wait</b><img src="images/ajax-loader.gif" />
</div>
<table class="data_table table table-striped display" id="example">
<thead>
<tr>
<?php
$amount1=0;
$fields = mysqli_fetch_fields($rs2);
foreach ($fields as $val)
{
echo '<th>'.$val->name.'</th>';
$output .='"'.$val->name;
$output .= '",';
}
$output .="'n";
?>
</tr>
</thead>
<tbody>
<?php
while($row2 = $rs2->fetch_object())
{
?>
<tr class="data_tr">
<?php
foreach($fields as $val)
{
$col_name = $val->name;
?>
<?php
if($col_name == "Account No")
{
?>
<td style="text-align:right!important; width: 20px!important">
<?php
echo $format="$".number_format(round($row2->$col_name),2);
$output .='"'.$format;
$output .= '",';
?>
</td>
<?php
}
else if(($col_name == "Charged Fee")||($col_name == "Expected Fee")))
{
-------
-------
}
?>
<?php
}
$output .="'n";
}
?>
</tr>
</tbody>
</table>
<input type="hidden" name="report_name" value="givecentral_contract"/>
</div>
<?php
} // Show if recordset not empty
else
{
$type = "warning";
$message = "<b>No records found</b>";
include ("includes/announce.inc.php");
}
?>
如果你想
在PHP中分解它,那么使用number_format
函数。
如果这是Excel中的问题,则select column -> right click -> format cells -> number tab
并将格式从general
设置为number