Totalize in Excel report in PHP

0

I have an Excel report that generates by my PHP application and I'm breaking my head for the following problem: I have an array that looks up the information in my mysql database. Then I put a totalizer, but I'd like to place the totalizer immedi- ately on the line after the rows of the array. For lack of knowledge, I ended up putting it in a line / column C100. I use the PHPExcel class.

How would you put it immediately after the array?

Follow my code

foreach(range('A','H') as $columnID)
{
    $objPHPExcel->getActiveSheet(0)->getColumnDimension($columnID)->setAutoSize(true);
}

//$objPHPExcel->getActiveSheet()->getColumnDimension('A2:H2')->setAutoSize(true);

$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Relatório Financeiro Zag Express')
            ->setCellValue('A2', 'Nome')
            ->setCellValue('B2', 'Forma de Pagamento')
            ->setCellValue('C2', 'Status')
            ->setCellValue('D2', 'Valor (R$)')
            ->setCellValue('E2', 'Valor Extra')
            ->setCellValue('F2', 'Distância (km)')
             ->setCellValue('G2', 'Data')
            ->setCellValue('H2', 'Motoboy');
// Initialise the Excel row number 
$rowCount = 3;  

 while($row = mysql_fetch_array($result)){
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 0, $rowCount, $row['usuario']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 1,$rowCount, $row['forma']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 2,$rowCount, $row['statu']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 3,$rowCount, $row['viagemValor']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 4, $rowCount, $row['extra']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 5, $rowCount, $row['km']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 6, $rowCount, $row['dtcriado']);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( 7, $rowCount, $row['entregadorNome']);
 $rowCount++;

}
$objPHPExcel->getActiveSheet()->setCellValue('C100', 'Valor Total');
$objPHPExcel->getActiveSheet()->setCellValue('D100', '=SUM(D3:D99)');
$objPHPExcel->getActiveSheet()
    ->getStyle('D2:D100')
    ->getNumberFormat()
    ->setFormatCode('R$ * 0.00'); ''
    
asked by anonymous 27.03.2018 / 03:07

0 answers