0

I've made table on View ,now i want to report it to Excel (PHPExcel) using CodeIgniter,im trying to find a simple reporting system,here's my script on controller so far :

  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);

    }

when i use that script,,i can't download it, pls correct my script , Thanks

7
  • You're saving the file to excelfile.xls on the web server.... are you then using readfile() or similar to try and download? Commented Sep 7, 2015 at 8:09
  • Why don't you simply set the appropriate headers, and then save to php://output Commented Sep 7, 2015 at 8:10
  • can you give me example using headers pls ?? Commented Sep 7, 2015 at 8:22
  • pls correct my script,,,i need your help ...when i press the button to download,,nothing happens,, Commented Sep 7, 2015 at 8:33
  • There's plenty of examples showing this in the /Examples folder of PHPExcel Commented Sep 7, 2015 at 8:55

2 Answers 2

1

Take a look at my demo project i did excel export in Codeigniter https://github.com/eboominathan/Basic-CRUD-in-Codeigniter

Sign up to request clarification or add additional context in comments.

1 Comment

what the password of admin ??
0

like this ??

function excel(){

   $CI->load->library('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);
  $filename = 'Report Data Actual vs Target Branch '.date('Y-m-d').'.xls';                        //save our workbook as this file name
   header('Content-Type: application/vnd.ms-excel'); //mime type
   header('Content-Disposition: attachment;filename="' . $filename . '"'); //tell browser what's the file name
   header('Cache-Control: max-age=0'); //no cache
   //save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
   //if you want to save it as .XLSX Excel 2007 format
   $objWriter = PHPExcel_IOFactory::createWriter($CI->excel, 'Excel5');
   //force user to download the Excel file without writing it to server's HD
   $objWriter->save('php://output');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.