'phpexcel filter not working when export to excel

I want to export to excel but filter search doesn't work when I select range date and export the result is all data before filtering,

public function download_excel()
{
    $objPHPExcel = new PHPExcel();
    $arr_bulan = $this->arr_bulan;
    $tanggalSekarang = date('d') . ' ' . $arr_bulan[date('n')] . ' ' . date('Y');
    $startRow = 5;
    $objPHPExcel->setActiveSheetIndex(0)->setTitle('Total');

    $no = 1;
    $total = array(
        'target' => 0,
        'bulan_ini' => 0,
        'bulan_lalu' => 0,
        'sekarang' => 0,
        'denda' => 0
    );
    // HEADER
    $objPHPExcel->getActiveSheet()->setCellValue("A1", 'REKAP DETAIL PENERIMAAN PAJAK')
        ->setCellValue('A3', 'NO')
        ->setCellValue('B3', 'KODE REKENING')
        ->setCellValue('C3', 'JENIS PAJAK')
        ->setCellValue('D3', 'URAIAN JENIS PAJAK')
        ->setCellValue('E3', 'JUMLAH PENERIMAAN (Rp)')
        ->setCellValue('E4', 'S/D PERIODE LALU')
        ->setCellValue('F4', 'PERIODE INI')
        ->setCellValue('G4', 'S/D PERIODE INI') // HEADER END
        ->setCellValue('H3', 'DENDA'); // HEADER END
    // QUERY
    $perbulan = $this->get_bulan_lalu();
    $result = $this->get_target_pajak(true);
    while ($row = mysqli_fetch_assoc($result)) {
        $bulan_ini = (isset($perbulan[date('n')][(int)$row['ID_JENIS_PAJAK']]) ? $perbulan[date('n')][(int)$row['ID_JENIS_PAJAK']] : 0);
        $bulan_lalu = (isset($perbulan[date('n', strtotime('-1 month'))][(int)$row['ID_JENIS_PAJAK']]) ? $perbulan[date('n', strtotime('-1 month'))][(int)$row['ID_JENIS_PAJAK']] : 0);
        

        $objPHPExcel->getActiveSheet()->setCellValue("A{$startRow}", $no)
            ->setCellValue("B{$startRow}", $row['KODE_REKENING'])
            ->setCellValue("C{$startRow}", $row['JENIS_PAJAK'])
            ->setCellValue("D{$startRow}", $row['nmrek'])
            ->setCellValue("E{$startRow}", $bulan_lalu)
            ->setCellValue("F{$startRow}", $row['TOTAL_PENDAPATAN'])
            ->setCellValue("G{$startRow}", $row['TOTAL_PENDAPATAN'])
            ->setCellValue("H{$startRow}", $row['TOTAL_DENDA']);


        
        $no++;
        $startRow++;

        $total['bulan_ini'] += $bulan_ini;
        $total['bulan_lalu'] += $bulan_lalu;
        $total['sekarang'] += $row['TOTAL_PENDAPATAN'];
        $total['denda'] += $row['TOTAL_DENDA'];

        
    }

    $objPHPExcel->getActiveSheet()->setCellValue("A{$startRow}", 'TOTAL')
        ->setCellValue("E{$startRow}",$total['bulan_lalu'])
        ->setCellValue("F{$startRow}", $total['sekarang'])
        ->setCellValue("G{$startRow}", $total['sekarang'])
        ->setCellValue("H{$startRow}", $total['denda']);

    // END QUERY

I have checked query in database and result is fine but when I download to excel filtering doesn't work how I can export with filter it's I choose?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source