0 レビュー
1 回答
mysql-レポートをPHPからExcelにエクスポートするときにコンマの後に表示される2つの数字だけを設定するにはどうすればよいですか?
現在、このコードを使用してPHPをExcelにエクスポートしています。すべてが順調で、コードは機能しています。しかし、不思議なことに、コンマの後に2つの数字だけを設定する方法を知りたいですか?たとえば、「パーセント」の場合、結果は「63.3333」または「72.3456」のようになります。 Excelでレポートを開いたときにコンマの2桁後にするにはどうすればよいですか?
$queabsdetail = "SELECT archieve AS archieve, SUM(barang_in) AS income, SUM(bijih_out+htm_out+pth_out) AS outcome, SUM((bijih_out+htm_out+pth_out)-barang_in) AS efficiency, SUM(barang_in/(bijih_out+htm_out+pth_out))*100 AS percent FROM items GROUP BY archieve";
$exequeabsdetail = mysql_query($queabsdetail);
while($res = mysql_fetch_array($exequeabsdetail)){
$data['id_transaction'][] = $res['id_transaction'];
$data['archieve'][] = $res['archieve'];
$data['income'][] = $res['income'];
$data['outcome'][] = $res['outcome'];
$data['efficiency'][] = $res['efficiency'];
$data['percent'][] = $res['percent'];
}
$jm = sizeof($data['id_transaction']);
header("Pragma: public" );
header("Expires: 0" );
header("Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header("Content-Type: application/force-download" );
header("Content-Type: application/octet-stream" );
header("Content-Type: application/download" );;
header("Content-Disposition: attachment;filename=archieve_report.xls " );
header("Content-Transfer-Encoding: binary " );
xlsBOF();
xlsWriteLabel(0,3,"Archive Report" );
xlsWriteLabel(2,0,"Number" );
xlsWriteLabel(2,1,"Archieve" );
xlsWriteLabel(2,2,"Income Items" );
xlsWriteLabel(2,3,"Outcome Items" );
xlsWriteLabel(2,4,"Efficiency" );
xlsWriteLabel(2,5,"Percent" );
$xlsRow = 3;
for ($y=0; $y<$jm; $y++) {
++$i;
xlsWriteNumber($xlsRow,0,"$i" );
xlsWriteLabel($xlsRow,1,$data['archieve'][$y]);
xlsWriteLabel($xlsRow,2,$data['income'][$y]);
xlsWriteLabel($xlsRow,3,$data['outcome'][$y]);
xlsWriteLabel($xlsRow,4,$data['eficciency'][$y]);
xlsWriteLabel($xlsRow,5,$data['percent'][$y]);
$xlsRow++;
}
試してみました:
number_format($data['percent'],2);
しかし、データのエクスポートには機能しないようです。しかし、PHPで使用すると機能します。では、どのようにトリックしますか?
わからない
0
レビュー
答え :
解決策:
もっと良い方法があるかもしれませんが、これはすばやく汚れた状態で機能するはずです:
xlsWriteLabel($xlsRow,5,round($data['percent'][$y]));
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。