我已經在View上創建了表格,現在我想使用CodeIgniter將其報告給Excel(PHPExcel),我試圖找到一個簡單的報告系統,這裏是我的控制器上的腳本遠:如何使用CodeIgniter從HTML表格創建Excel電子表格
function excel(){
$data['bf']=$this->report->branch();
$tahun = $this->input->post('tahun');
$branch= $this->input->post('branch');
/*$data['data'] = $this->report->getdata($tahun);
$data['data2'] = $this->report->getdata($tahun);
// $data['bfb'] = $this->report->getdata($tahun,$branch); */
$data['show'] = $this->report->show();
$data['bal'] = $this->report->getbal($tahun);
$data['bdg'] = $this->report->getbdg($tahun);
$data['bgr'] = $this->report->getbgr($tahun);
$data['bjm'] = $this->report->getbjm($tahun);
$data['bkp'] = $this->report->getbkp($tahun);
$data['bks'] = $this->report->getbks($tahun);
$data['bnk'] = $this->report->getbnk($tahun);
$data['crb'] = $this->report->getcrb($tahun);
$data['jkt'] = $this->report->getjkt($tahun);
$data['jktm'] = $this->report->getjktm($tahun);
$data['jmb'] = $this->report->getjmb($tahun);
$data['knd'] = $this->report->getknd($tahun);
$data['lpg'] = $this->report->getlpg($tahun);
$data['mad'] = $this->report->getmad($tahun);
$data['mdn'] = $this->report->getmdn($tahun);
$data['mks'] = $this->report->getmks($tahun);
$data['mlg'] = $this->report->getmlg($tahun);
$data['pkb'] = $this->report->getpkb($tahun);
$data['plb'] = $this->report->getplb($tahun);
$data['pnt'] = $this->report->getpnt($tahun);
$html = $this->load->view('report/report', $data, true);
$tmpfile = time().'.html';
file_put_contents($tmpfile, $html);
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel5');
$objWriter->save('excelfile.xls');
unlink($tmpfile);
}
當我使用該腳本,,我不能下載它,請糾正我的劇本,感謝
你將文件保存到'在Web服務器上excelfile.xls' Excel導出....你再使用' readfile()'或類似的嘗試和下載? –
你爲什麼不簡單地設置適當的頭文件,然後保存到'php://輸出' –
你能給我舉例使用頭文件嗎? – Pandu44