Php 如何打印excel最后一行的数据

Php 如何打印excel最后一行的数据,php,excel,Php,Excel,我有一个下拉框,它显示客户端,当选择客户端并单击导出按钮时,它将在ex单元格中生成数据,但我想将此数据“确保正确”添加到生成的excel的最后一行,但我不知道确切的最后一行是什么,因为每个客户端的数据量不同,有谁能指导我 我的代码 <?php $dbHost = 'localhost'; // usually localhost $dbUsername = 'xxx'; $dbPassword = 'xxxx'; $dbDatabase = 'xxxx'; $db = mysql_conn

我有一个下拉框,它显示客户端,当选择客户端并单击导出按钮时,它将在ex单元格中生成数据,但我想将此数据“确保正确”添加到生成的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();
?>

工作表中的最后一行数据可以通过调用

$lastRow = $sheet->getHighestRow();