fix affichage totaux dans export Excel
This commit is contained in:
parent
f9b7126cc5
commit
4828686162
@ -153,10 +153,11 @@ foreach(range('P','Z') as $col) {
|
|||||||
foreach(range('A','B') as $col) {
|
foreach(range('A','B') as $col) {
|
||||||
$spreadsheet->getActiveSheet()->setCellValue('A'.$col.($highestRow+2), '=SUM(A'.$col.'2:A'.$col.($highestRow).')');
|
$spreadsheet->getActiveSheet()->setCellValue('A'.$col.($highestRow+2), '=SUM(A'.$col.'2:A'.$col.($highestRow).')');
|
||||||
}
|
}
|
||||||
// Do AA and AB
|
|
||||||
// $spreadsheet->getActiveSheet()->setCellValue('AA'.($highestRow+2), '=SUM(AA2:AA'.($highestRow).')');
|
|
||||||
|
|
||||||
// Format the total
|
// Format the total
|
||||||
$spreadsheet->getActiveSheet()->getStyle($coord.':AA'.($highestRow+2))->getFill()
|
$spreadsheet->getActiveSheet()->getStyle($coord.':AB'.($highestRow+2))->getFill()
|
||||||
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
||||||
->getStartColor()->setARGB('AAAAAAAA');
|
->getStartColor()->setARGB('AAAAAAAA');
|
||||||
|
|
||||||
@ -168,6 +169,7 @@ if ($result = $mysqli->query($query)) {
|
|||||||
|
|
||||||
$line = 1;
|
$line = 1;
|
||||||
/* fetch associative array */
|
/* fetch associative array */
|
||||||
|
$prevSheet = null;
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$ser = $row['formdata'];
|
$ser = $row['formdata'];
|
||||||
$seru = unserialize($ser);
|
$seru = unserialize($ser);
|
||||||
@ -196,10 +198,10 @@ if ($result = $mysqli->query($query)) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if($prevName!=$fr[$sortName]) {
|
if($prevName!=$fr[$sortName]) {
|
||||||
$keys = array_keys ( $header );
|
$keys = array_keys ( $header );
|
||||||
// Create new worksheet
|
// Create new worksheet
|
||||||
if($prevSheet) {
|
if($prevSheet) {
|
||||||
// Add totals
|
// Add totals
|
||||||
// //
|
// //
|
||||||
$highestRow = $prevSheet->getHighestRow();
|
$highestRow = $prevSheet->getHighestRow();
|
||||||
$coord = 'O' . ($highestRow+2);
|
$coord = 'O' . ($highestRow+2);
|
||||||
@ -207,22 +209,28 @@ if ($result = $mysqli->query($query)) {
|
|||||||
foreach(range('P','Z') as $col) {
|
foreach(range('P','Z') as $col) {
|
||||||
$prevSheet->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')');
|
$prevSheet->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')');
|
||||||
}
|
}
|
||||||
// Do AA
|
// Do AA and AB
|
||||||
foreach(range('A','B') as $col) {
|
foreach(range('A','B') as $col) {
|
||||||
$prevSheet->setCellValue('A'.$col.($highestRow+2), '=SUM(A'.$col.'2:A'.$col.($highestRow).')');
|
$prevSheet->setCellValue('A'.$col.($highestRow+2), '=SUM(A'.$col.'2:A'.$col.($highestRow).')');
|
||||||
}
|
}
|
||||||
|
|
||||||
// $prevSheet->setCellValue('AA'.($highestRow+2), '=SUM(AA2:AA'.($highestRow).')');
|
|
||||||
// Format the total
|
// Format the total
|
||||||
$prevSheet->getStyle($coord.':AA'.($highestRow+2))->getFill()
|
$prevSheet->getStyle($coord.':AB'.($highestRow+2))->getFill()
|
||||||
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
||||||
->getStartColor()->setARGB('BBBBBBBB');
|
->getStartColor()->setARGB('BBBBBBBB');
|
||||||
|
|
||||||
}
|
}
|
||||||
$prevSheet = $spreadsheet->getActiveSheet();
|
$prevSheet = $spreadsheet->getActiveSheet();
|
||||||
$myWorkSheet = $spreadsheet->createSheet();
|
$prevSheet = $myWorkSheet;
|
||||||
|
$myWorkSheet = $spreadsheet->createSheet();
|
||||||
$myWorkSheet->setTitle($fr[$sortName]);
|
$myWorkSheet->setTitle($fr[$sortName]);
|
||||||
$myWorkSheet
|
foreach (range('A','Z') as $col) {
|
||||||
|
$myWorkSheet->getColumnDimension($col)->setAutoSize(true);
|
||||||
|
}
|
||||||
|
foreach (range('A','E') as $col) {
|
||||||
|
$myWorkSheet->getColumnDimension('A'.$col)->setAutoSize(true);
|
||||||
|
}
|
||||||
|
$myWorkSheet
|
||||||
->fromArray(
|
->fromArray(
|
||||||
$keys, // The data to set
|
$keys, // The data to set
|
||||||
NULL, // Array values with this value will not be set
|
NULL, // Array values with this value will not be set
|
||||||
@ -231,8 +239,9 @@ if ($result = $mysqli->query($query)) {
|
|||||||
);
|
);
|
||||||
$myWorkSheet->getStyle('1')->getFont()->setBold(true);
|
$myWorkSheet->getStyle('1')->getFont()->setBold(true);
|
||||||
$line=2;
|
$line=2;
|
||||||
$prevName = $fr[$sortName];
|
|
||||||
}
|
$prevName = $fr[$sortName];
|
||||||
|
}
|
||||||
|
|
||||||
$myWorkSheet
|
$myWorkSheet
|
||||||
->fromArray(
|
->fromArray(
|
||||||
@ -262,10 +271,12 @@ $spreadsheet->getActiveSheet()->setCellValue($coord, 'TOTAL');
|
|||||||
foreach(range('P','Z') as $col) {
|
foreach(range('P','Z') as $col) {
|
||||||
$spreadsheet->getActiveSheet()->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')');
|
$spreadsheet->getActiveSheet()->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')');
|
||||||
}
|
}
|
||||||
// Do AA
|
foreach(range('A','B') as $col) {
|
||||||
$spreadsheet->getActiveSheet()->setCellValue('AA'.($highestRow+2), '=SUM(AA2:AA'.($highestRow).')');
|
$spreadsheet->getActiveSheet()->setCellValue('A'.$col.($highestRow+2), '=SUM(A'.$col.'2:A'.$col.($highestRow).')');
|
||||||
|
}
|
||||||
|
|
||||||
// Format the total
|
// Format the total
|
||||||
$spreadsheet->getActiveSheet()->getStyle($coord.':AA'.($highestRow+2))->getFill()
|
$spreadsheet->getActiveSheet()->getStyle($coord.':AB'.($highestRow+2))->getFill()
|
||||||
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
||||||
->getStartColor()->setARGB('AAAAAAAA');
|
->getStartColor()->setARGB('AAAAAAAA');
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user