简体   繁体   中英

PHPExcel not download or no process at all

i'm trying to export from mysql to excel using PHPExcel, i create a button to start exporting proses. It's loading but return with blank white page, i check every line from the code and didn't found any problem. Calling data from table is normal, check it with echo . so i think there is a problem with exporting process, here is the code

require_once 'PHPExcel/PHPExcel.php';
$excel=new PHPExcel();
$excel->getProperties()->setCreator('Flora Sitinjak')
->setLastModified('Flora Sitinjak')
->setTittle('Laporan Pendapatan')
->setSubject('Pendapatan')
->setDescription('Laporan Semua Pendapatan')
->setKeywords('Data Pendapatan');

$exp=$excel->setActiveSheetIndex(0);
$exp->setCellValue('A1', "Tanggal");
$exp->setCellValue('B1', "EKS");
$exp->setCellValue('C1', "BIS");
$exp->setCellValue('D1', "EKO");
$exp->setCellValue('E1', "L.EKO");
$exp->setCellValue('F1', "Total");

$line=2;

$x=0;
for($i=1;$i<=$tgl[11];$i++){

$exp->setCellValue("A".$line, $i);

    $carTL=count($arTL);
    $gTGLO=substr($arTL[$x],-2);
        if(empty($gTGLO)){
            $x=0;
        }else{
            if($i==$gTGLO){
                if(($x+1)>=$carTL){
                    $x=$carTL-1;
                    $exp->setCellValue("B".$line, $arLUEKS[$x]);
                    $exp->setCellValue("C".$line, $arLUBIS[$x]);
                    $exp->setCellValue("D".$line, $arUEKO[$x]);
                    $exp->setCellValue("E".$line, $arLEKO[$x]);
                    $exp->setCellValue("F".$line, $arTot[$x]);
                }else{
                    $exp->setCellValue("B".$line, $arLUEKS[$x]);
                    $exp->setCellValue("C".$line, $arLUBIS[$x]);
                    $exp->setCellValue("D".$line, $arUEKO[$x]);
                    $exp->setCellValue("E".$line, $arLEKO[$x]);
                    $exp->setCellValue("F".$line, $arTot[$x]);
                    $x++;
                }
            }else{
                $exp->setCellValue("B".$line, '-');
                $exp->setCellValue("C".$line, '-');
                $exp->setCellValue("D".$line, '-');
                $exp->setCellValue("E".$line, '-');
                $exp->setCellValue("F".$line, '-');
            }
        }   
$line++;
}

$excel->getActiveSheet()->setTitle('Laporan');
$excel->setActiveSheetIndex(0);

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="Data Laporan Pendapatan.xlsx');
header('Cache-Control: max-age=0');

$write=PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$write->save('php://output');

Every array like $arLUEKS[$x] is called from database and works, checked with echo

The output is a table with shows data a month from 1 to 31, if the data doesn't exist then it show a -

Anyone can solve this? please help me

I do not know what exactly could be wrong but here are some helpful things you can do that can help you identify your problem .

  1. Turn on error reporting by adding these two to the top of your script

    ini_set("display_errors",1); error_reporting(E_ALL);

This may point you to the cause. Maybe the script is timing out or something

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM