0
我有一個下拉框顯示客戶端,當選擇客戶端並點擊導出按鈕時它會在ex-cell中生成數據但我想添加這些數據「爲了確保正確」的最後一行到Excel中產生的,但我不知道是什麼確切的最後一行,因爲每個客戶都有不同的數據量,任何一個可以指導我,如何在excel的最後一行打印數據
我的代碼
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'xxx';
$dbPassword = 'xxxx';
$dbDatabase = 'xxxx';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) ;
mysql_select_db ($dbDatabase, $db) ;
require_once 'Classes/PHPExcel.php';
$clientid=$_POST['clientid'];
$date = date('d/m/Y', time());
$sql_select= "SELECT supplierprice.country, supplierprice.networkname, supplierprice.mcc, supplierprice.mnc, `$clientid`.clientprice, client_list.currency
FROM supplierprice
INNER JOIN `$clientid` ON supplierprice.supp_price_id = `$clientid`.net_id
INNER JOIN client_list ON `$clientid`.clientid = client_list.clientid
WHERE supplierprice.networkname <> 'default' and `$clientid`.clientprice <> 0
ORDER BY supplierprice.country, supplierprice.networkname ASC";
$queryRes = mysql_query($sql_select);
// start creating excel
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();
// your data
$sheet->setCellValueByColumnAndRow(0,1,$_POST['clientid']);
$sheet->setCellValueByColumnAndRow(0,3,'Country');
$sheet->setCellValueByColumnAndRow(4,3,'Client Price');
$sheet->setCellValueByColumnAndRow(5,3,'Currency');
// start list
$offset = 4;
$total_cost = 0;
$total_sms = 0;
while($row = mysql_fetch_assoc($queryRes)){
$sheet->setCellValueByColumnAndRow(0,$offset,$row['country']);
$sheet->setCellValueByColumnAndRow(1,$offset,$row['networkname']);
$sheet->setCellValueByColumnAndRow(2,$offset,$row['mcc']);
$sheet->setCellValueByColumnAndRow(3,$offset,$row['mnc']);
$sheet->setCellValueByColumnAndRow(4,$offset,$row['clientprice']);
$sheet->setCellValueByColumnAndRow(5,$offset,$row['currency']);
$total_cost += $row['clienttotalprice'];
$total_sms += $row['client_inv_totalsms'];
$offset++;
}
//OUTPUT
header("Content-Type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename='export.xls'");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit();
?>