Suppose we need this sign:
http://i.stack.imgur.com/6mN0i.jpg
Additionally, you 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)'); 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(); Get the table:
http://i.stack.imgur.com/b5zod.jpg
Everything is good, but when choosing a filter:
i.stack.imgur.com/go3G6.png
The final line also falls under the filtering, and if you apply a filter for the price for example, the amount in the final line does not change ..
How to implement a label with filters and a string of totals?
SUBTOTALinstead ofSUMand will only consider filtered tutankhamun