我在使用PHPExcel将数据映射到新工作表时遇到了问题。
我想将数据映射到 A4 中的新工作表,但不知何故它无法正常工作。我试图将它映射到不同的列,如 F ,它工作正常。您能否告诉我如何在正确的列中映射数据?
这是我的代码:
$incentive = "select * from incentive";
$connect = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" .
mysql_errno());
//select database
$Db = @mysql_select_db($dbname, $connect)
or die("Couldn't select database:<br>" . mysql_error(). "<br>" .
mysql_errno());
//execute query
$resultincentive = @mysql_query($incentive,$connect)
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" .
mysql_errno());
error_reporting(E_ALL);
$objPHPExcel = new PHPExcel();
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Company Name:');
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'Sales Incentive for the
Month of:');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Date:');
$objPHPExcel->getActiveSheet()->setCellValue('A3', 'Date');
$objPHPExcel->getActiveSheet()->setCellValue('B3', 'Total Sales');
$objPHPExcel->getActiveSheet()->setCellValue('C3', 'Sales Net of Vat');
$objPHPExcel->getActiveSheet()->setCellValue('D3', 'Sales Quota');
$objPHPExcel->getActiveSheet()->setCellValue('E3', 'Incentive Amount');
$rowCount2 = 1;
while($rowincentive = mysql_fetch_array($resultincentive)){
$objPHPExcel->getActiveSheet()->setCellValue('A4'.$rowCount2,
$rowincentive['DATE']);
$rowCount2++;
}
// Rename 2nd sheet
$objPHPExcel->getActiveSheet()->setTitle('Incentive');
答案 0 :(得分:0)
很抱歉没有回答这个问题......由于我的日程繁忙,我发现了过去几周没有回答过这个问题......
我刚刚使用$ rowCount2
调整了它$rowCount2 = 4;
这给了我A4的专栏:)