E
E
entermix2015-10-01 19:58:58
PHP
entermix, 2015-10-01 19:58:58

How to properly format the total row in PHPExcel?

Let's say we need such a sign:
7867144.jpg
Additionally, we need filters in the header, I do everything like this:

$objPHPExcel = new PHPExcel();

        $objPHPExcel->setActiveSheetIndex(0);

        $active_sheet = $objPHPExcel->getActiveSheet();

        $active_sheet->setCellValue('A3', '№');
        $active_sheet->setCellValue('B3', 'Товар');
        $active_sheet->setCellValue('C3', 'Цена');

        $active_sheet->setAutoFilter('A3:C3');

        $active_sheet->setCellValue('A4', '1');
        $active_sheet->setCellValue('B4', 'Товар 1');
        $active_sheet->setCellValue('C4', '200');

        $active_sheet->setCellValue('A5', '2');
        $active_sheet->setCellValue('B5', 'Товар 2');
        $active_sheet->setCellValue('C5', '500');

        $active_sheet->setCellValue('A6', '3');
        $active_sheet->setCellValue('B6', 'Товар 3');
        $active_sheet->setCellValue('C6', '120');

        $active_sheet->setCellValue('A7', '4');
        $active_sheet->setCellValue('B7', 'Товар 4');
        $active_sheet->setCellValue('C7', '245');

        $active_sheet->setCellValue('A8', '5');
        $active_sheet->setCellValue('B8', 'Товар 5');
        $active_sheet->setCellValue('C8', '130');

        $active_sheet->setCellValue('A9', 'Итог');
        $active_sheet->setCellValue('C9', '=SUM(C4:C8)');

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

        header("Content-Type:application/vnd.ms-excel");
        header("Content-Disposition:attachment;filename=simple.xls");

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');

        exit();

We get the table:
7870219.jpg
Everything would be fine, but when choosing a filter: The
f1c73d673f80453dbded1f8563333d90.png
final row also falls under filtering, and if you apply a filter by price, for example, the amount in the final row does not change..
How to properly implement a table with filters and a row of totals?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2015-10-05
@entermix

You need to use the SUBTOTAL function:
en.stackoverflow.com/questions/455156/%D0%9A%D0%B0...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question