我有这个构建HTML表格,我想将其转换为Excel电子表格,但它恰好显示千位分隔符和2位小数,如PHP函数number_format指定的那样。简而言之就像Excel中的100.00我有100个
$OutputExcel = "
<h3 align='center'>$COMPANYNAME</h3>
<table class='tblNemoList' border='0' cellpadding='2' cellspacing='0' width='100%' style='-fs-table-paginate: paginate;'>
<caption align='left'><b>Detailed Horse Charges</b></caption>
<thead>
<tr>
<th align='left'>#</th>
<th align='left'>No</th>
<th align='left'>Horse Name</th>
<th align='left'>Description</th>
<th align='left'>Date</th>
<th align='left'>Amount</th>
</tr>
</thead>
";
$i = 0;
while($row = $xdb->fetch_object($rowHorseCharges))
{
//ini
$i++;
$OutputPDF .= "
<tr >
<td>$i</td>
<td>".$row->No."</td>
<td>".$row->strHorse."</td>
<td>".$row->Description."</td>
<td>".$row->Date."</td>
<td align='right'>".number_format($row->Amount,2,'.',',')."</td>
</tr>
";
$OutputExcel .= "
<tr >
<td align='left' >$i</td>
<td align='left' >".$row->No."</td>
<td align='left' >".$row->strHorse."</td>
<td align='left' >".$row->Description."</td>
<td align='left' >".$row->Date."</td>
<td align='right' >".number_format($row->Amount,2,'.',',')."</td>
</tr>
";
}
$OutputPDF .= "
<tr><td colspan='6' style='border-bottom:1px solid black;'></td></tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td align='right' ><b>Tota: ".number_format($rowTotal->Total,2,'.',',')."</b></td>
</tr>
</table>";
$OutputExcel .= "
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td align='right' ><b>Total: ".number_format($rowTotal->Total,2,'.',',')."</b></td>
</tr>
</table>
";
我正在使用此
进行转换 switch($Action){
case "Clear":
break;
case "Export Excel":
include_once("reports/". $_REQUEST[radReport] .".php");
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=". $strFilename .".xls"); //gets set inside the report.rpt.php
header("Pragma: no-cache");
header("Expires: 0");
echo $OutputExcel;
die;
break;
case "ExportPDF":
include_once("reports/". $_REQUEST[radReport] .".php");
ini_set('display_errors', '0');
header("Content-type: application/pdf");
require_once('includes/mpdf/mpdf.php');
$mpdf = new mPDF('utf-8', $format ,9,'Arial');
$mpdf->setHTMLHeader(getPDFHeader($COMPANYNAME));
$mpdf->setHTMLFooter(getPDFFooter());
if($orientation == 'P'){$mpdf->AddPage($orientation,'', '' ,'','',15,15,20,16,7,9);}else{$mpdf->AddPage($orientation,'', '' ,'','',30,30,30,30,18,12);}
$mpdf->WriteHTML($OutputPDF);
$mpdf->Output($strFilename."pdf", "I");
die;
break;
case "OpenPDF":
default:
$page->Content .= $Output
. js("d('". $_POST[radReport] ."').click(function())");
break;
}
答案 0 :(得分:0)
您需要在表格页面中添加CSS。像这样:
<style type='text/css'>
.num2d {
mso-number-format:"0\.00";
}
</style>
然后将其用作<td>
的类,如下所示:
<td class="num2d">34</td>
我自己没有做到这一点,但在此处找到了它:
http://cosicimiento.blogspot.nl/2008/11/styling-excel-cells-with-mso-number.html