How to export the data in excel and how to upload PHPExcel file into controller using codeiginter?












1















I have written the code to export the data into an excel sheet, but the PHPExcel  libray is not loaded into the code.It shows some error while clicking the button"Export".


The error is:
enter image description here



 public function Arrear_Print(){

$data['page'] = 'export-excel';
$data['title'] = 'Export Excel data | TechArise';
$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$this->load->model('Export');
$data['PName'] = $this->Export->mobileList();
// load view file for output
//$this->load->view('header');
$this->load->view('TipUp_LoanArrear_Print', $data);
// $this->load->view('footer');
}
public function createXLS() {
// create file name
$fileName = 'mobile-'.time().'.xlsx';
// load excel library
$this->load->library('excel');
$mobiledata = $this->model->Export->mobileList();
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
// set Header
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'AcNo');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Mode');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Party Name');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Loan Date');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Loan Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Bal.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Coll.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('H1', 'Rec.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('I1', 'Phone.No');
// set Row
$rowCount = 2;
foreach ($mobiledata as $element)
{
$objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $element['TAcNo']);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $element['TMode']);
$objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $element['TName']);
$objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $element['TDate']);
$objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowCount, $element['TAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('F' . $rowCount, $element['total_sum']);
$objPHPExcel->getActiveSheet()->SetCellValue('G' . $rowCount, $element['RLAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('H' . $rowCount, $element['']);
$objPHPExcel->getActiveSheet()->SetCellValue('I' . $rowCount, $element['Phone']);
$rowCount++;
}

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($fileName);
// download file
header("Content-Type: application/vnd.ms-excel");
redirect(site_url().$fileName);
}


This is a controller code:



 <?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');


class Export extends CI_Model {
// get mobiles list
public function mobileList() {

$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$PName = $this->input->post('TName');
$SDate = $this->input->post('SDate');
$EDate = $this->input->post('EDate');

if($PName = $this->input->post('TName')){


$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` WHERE TName = '$PName' GROUP BY `TAcNo`ORDER BY `TAcNo` ASC");
return $query->result_array();


//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}

else {
$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` GROUP BY `TAcNo` ORDER BY `TAcNo` ASC");
return $query->result_array();
//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}


}
}
?>


This is model code:



enter image description here
This is input view page....While giving from and to date into the text box.It fetch the data between this date and show it in the view page correctly
enter image description here



This is fetched data and shown in the view page while clicking the "Export" button.The error is displaying that I have never uploaded the picture.



I have downloaded the phpexcel library file in the codeiginter website.



This is link....enter link description here



Please help me to solve this problem.










share|improve this question

























  • The error says that the PHPExcel.php file was missing, are you certain the file is there?

    – Hasta Dhana
    Jan 2 at 8:20













  • hope you find something here: stackoverflow.com/questions/44580289/….

    – Sovit Maharjan
    Jan 2 at 8:21











  • Yes i have set the path

    – Mootu Pattulu
    Jan 2 at 8:21











  • <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH . "/third_party/PHPExcel.php"; class Excel extends PHPExcel { public function __construct() { parent::__construct(); } } ?> This is excel.php file in the library

    – Mootu Pattulu
    Jan 2 at 8:22













  • within application/third_party folder, is the file there?

    – Hasta Dhana
    Jan 2 at 8:23
















1















I have written the code to export the data into an excel sheet, but the PHPExcel  libray is not loaded into the code.It shows some error while clicking the button"Export".


The error is:
enter image description here



 public function Arrear_Print(){

$data['page'] = 'export-excel';
$data['title'] = 'Export Excel data | TechArise';
$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$this->load->model('Export');
$data['PName'] = $this->Export->mobileList();
// load view file for output
//$this->load->view('header');
$this->load->view('TipUp_LoanArrear_Print', $data);
// $this->load->view('footer');
}
public function createXLS() {
// create file name
$fileName = 'mobile-'.time().'.xlsx';
// load excel library
$this->load->library('excel');
$mobiledata = $this->model->Export->mobileList();
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
// set Header
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'AcNo');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Mode');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Party Name');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Loan Date');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Loan Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Bal.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Coll.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('H1', 'Rec.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('I1', 'Phone.No');
// set Row
$rowCount = 2;
foreach ($mobiledata as $element)
{
$objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $element['TAcNo']);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $element['TMode']);
$objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $element['TName']);
$objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $element['TDate']);
$objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowCount, $element['TAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('F' . $rowCount, $element['total_sum']);
$objPHPExcel->getActiveSheet()->SetCellValue('G' . $rowCount, $element['RLAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('H' . $rowCount, $element['']);
$objPHPExcel->getActiveSheet()->SetCellValue('I' . $rowCount, $element['Phone']);
$rowCount++;
}

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($fileName);
// download file
header("Content-Type: application/vnd.ms-excel");
redirect(site_url().$fileName);
}


This is a controller code:



 <?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');


class Export extends CI_Model {
// get mobiles list
public function mobileList() {

$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$PName = $this->input->post('TName');
$SDate = $this->input->post('SDate');
$EDate = $this->input->post('EDate');

if($PName = $this->input->post('TName')){


$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` WHERE TName = '$PName' GROUP BY `TAcNo`ORDER BY `TAcNo` ASC");
return $query->result_array();


//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}

else {
$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` GROUP BY `TAcNo` ORDER BY `TAcNo` ASC");
return $query->result_array();
//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}


}
}
?>


This is model code:



enter image description here
This is input view page....While giving from and to date into the text box.It fetch the data between this date and show it in the view page correctly
enter image description here



This is fetched data and shown in the view page while clicking the "Export" button.The error is displaying that I have never uploaded the picture.



I have downloaded the phpexcel library file in the codeiginter website.



This is link....enter link description here



Please help me to solve this problem.










share|improve this question

























  • The error says that the PHPExcel.php file was missing, are you certain the file is there?

    – Hasta Dhana
    Jan 2 at 8:20













  • hope you find something here: stackoverflow.com/questions/44580289/….

    – Sovit Maharjan
    Jan 2 at 8:21











  • Yes i have set the path

    – Mootu Pattulu
    Jan 2 at 8:21











  • <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH . "/third_party/PHPExcel.php"; class Excel extends PHPExcel { public function __construct() { parent::__construct(); } } ?> This is excel.php file in the library

    – Mootu Pattulu
    Jan 2 at 8:22













  • within application/third_party folder, is the file there?

    – Hasta Dhana
    Jan 2 at 8:23














1












1








1








I have written the code to export the data into an excel sheet, but the PHPExcel  libray is not loaded into the code.It shows some error while clicking the button"Export".


The error is:
enter image description here



 public function Arrear_Print(){

$data['page'] = 'export-excel';
$data['title'] = 'Export Excel data | TechArise';
$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$this->load->model('Export');
$data['PName'] = $this->Export->mobileList();
// load view file for output
//$this->load->view('header');
$this->load->view('TipUp_LoanArrear_Print', $data);
// $this->load->view('footer');
}
public function createXLS() {
// create file name
$fileName = 'mobile-'.time().'.xlsx';
// load excel library
$this->load->library('excel');
$mobiledata = $this->model->Export->mobileList();
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
// set Header
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'AcNo');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Mode');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Party Name');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Loan Date');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Loan Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Bal.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Coll.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('H1', 'Rec.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('I1', 'Phone.No');
// set Row
$rowCount = 2;
foreach ($mobiledata as $element)
{
$objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $element['TAcNo']);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $element['TMode']);
$objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $element['TName']);
$objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $element['TDate']);
$objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowCount, $element['TAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('F' . $rowCount, $element['total_sum']);
$objPHPExcel->getActiveSheet()->SetCellValue('G' . $rowCount, $element['RLAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('H' . $rowCount, $element['']);
$objPHPExcel->getActiveSheet()->SetCellValue('I' . $rowCount, $element['Phone']);
$rowCount++;
}

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($fileName);
// download file
header("Content-Type: application/vnd.ms-excel");
redirect(site_url().$fileName);
}


This is a controller code:



 <?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');


class Export extends CI_Model {
// get mobiles list
public function mobileList() {

$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$PName = $this->input->post('TName');
$SDate = $this->input->post('SDate');
$EDate = $this->input->post('EDate');

if($PName = $this->input->post('TName')){


$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` WHERE TName = '$PName' GROUP BY `TAcNo`ORDER BY `TAcNo` ASC");
return $query->result_array();


//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}

else {
$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` GROUP BY `TAcNo` ORDER BY `TAcNo` ASC");
return $query->result_array();
//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}


}
}
?>


This is model code:



enter image description here
This is input view page....While giving from and to date into the text box.It fetch the data between this date and show it in the view page correctly
enter image description here



This is fetched data and shown in the view page while clicking the "Export" button.The error is displaying that I have never uploaded the picture.



I have downloaded the phpexcel library file in the codeiginter website.



This is link....enter link description here



Please help me to solve this problem.










share|improve this question
















I have written the code to export the data into an excel sheet, but the PHPExcel  libray is not loaded into the code.It shows some error while clicking the button"Export".


The error is:
enter image description here



 public function Arrear_Print(){

$data['page'] = 'export-excel';
$data['title'] = 'Export Excel data | TechArise';
$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$this->load->model('Export');
$data['PName'] = $this->Export->mobileList();
// load view file for output
//$this->load->view('header');
$this->load->view('TipUp_LoanArrear_Print', $data);
// $this->load->view('footer');
}
public function createXLS() {
// create file name
$fileName = 'mobile-'.time().'.xlsx';
// load excel library
$this->load->library('excel');
$mobiledata = $this->model->Export->mobileList();
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
// set Header
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'AcNo');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Mode');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Party Name');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Loan Date');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Loan Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Bal.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Coll.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('H1', 'Rec.Amt');
$objPHPExcel->getActiveSheet()->SetCellValue('I1', 'Phone.No');
// set Row
$rowCount = 2;
foreach ($mobiledata as $element)
{
$objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $element['TAcNo']);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $element['TMode']);
$objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $element['TName']);
$objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $element['TDate']);
$objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowCount, $element['TAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('F' . $rowCount, $element['total_sum']);
$objPHPExcel->getActiveSheet()->SetCellValue('G' . $rowCount, $element['RLAmt']);
$objPHPExcel->getActiveSheet()->SetCellValue('H' . $rowCount, $element['']);
$objPHPExcel->getActiveSheet()->SetCellValue('I' . $rowCount, $element['Phone']);
$rowCount++;
}

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($fileName);
// download file
header("Content-Type: application/vnd.ms-excel");
redirect(site_url().$fileName);
}


This is a controller code:



 <?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');


class Export extends CI_Model {
// get mobiles list
public function mobileList() {

$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$PName = $this->input->post('TName');
$SDate = $this->input->post('SDate');
$EDate = $this->input->post('EDate');

if($PName = $this->input->post('TName')){


$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` WHERE TName = '$PName' GROUP BY `TAcNo`ORDER BY `TAcNo` ASC");
return $query->result_array();


//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}

else {
$query = $this->db->query("SELECT `TAcNo`,`TMode`,`TDate`,`TAmt`,`TName`, COALESCE(SUM(`RLAmt`) ,0) AS `RLAmt`,`Phone` FROM `tipup_payment` LEFT OUTER JOIN `tipup_receipt` ON `tipup_receipt`.`TRAcNo` = `tipup_payment`.`TAcNo` AND `TDate` >= '$SDate' AND `TDate` <= '$EDate' LEFT OUTER JOIN `parmaster` ON `parmaster`.`PName` = `tipup_payment`.`TName` GROUP BY `TAcNo` ORDER BY `TAcNo` ASC");
return $query->result_array();
//$data['PName']=$query->result_array();
//$this->load->view('TipUp_LoanArrear_Print',$data,FALSE);
}


}
}
?>


This is model code:



enter image description here
This is input view page....While giving from and to date into the text box.It fetch the data between this date and show it in the view page correctly
enter image description here



This is fetched data and shown in the view page while clicking the "Export" button.The error is displaying that I have never uploaded the picture.



I have downloaded the phpexcel library file in the codeiginter website.



This is link....enter link description here



Please help me to solve this problem.







php excel codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 8:14









Julia

519




519










asked Jan 2 at 8:08









Mootu PattuluMootu Pattulu

187




187













  • The error says that the PHPExcel.php file was missing, are you certain the file is there?

    – Hasta Dhana
    Jan 2 at 8:20













  • hope you find something here: stackoverflow.com/questions/44580289/….

    – Sovit Maharjan
    Jan 2 at 8:21











  • Yes i have set the path

    – Mootu Pattulu
    Jan 2 at 8:21











  • <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH . "/third_party/PHPExcel.php"; class Excel extends PHPExcel { public function __construct() { parent::__construct(); } } ?> This is excel.php file in the library

    – Mootu Pattulu
    Jan 2 at 8:22













  • within application/third_party folder, is the file there?

    – Hasta Dhana
    Jan 2 at 8:23



















  • The error says that the PHPExcel.php file was missing, are you certain the file is there?

    – Hasta Dhana
    Jan 2 at 8:20













  • hope you find something here: stackoverflow.com/questions/44580289/….

    – Sovit Maharjan
    Jan 2 at 8:21











  • Yes i have set the path

    – Mootu Pattulu
    Jan 2 at 8:21











  • <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH . "/third_party/PHPExcel.php"; class Excel extends PHPExcel { public function __construct() { parent::__construct(); } } ?> This is excel.php file in the library

    – Mootu Pattulu
    Jan 2 at 8:22













  • within application/third_party folder, is the file there?

    – Hasta Dhana
    Jan 2 at 8:23

















The error says that the PHPExcel.php file was missing, are you certain the file is there?

– Hasta Dhana
Jan 2 at 8:20







The error says that the PHPExcel.php file was missing, are you certain the file is there?

– Hasta Dhana
Jan 2 at 8:20















hope you find something here: stackoverflow.com/questions/44580289/….

– Sovit Maharjan
Jan 2 at 8:21





hope you find something here: stackoverflow.com/questions/44580289/….

– Sovit Maharjan
Jan 2 at 8:21













Yes i have set the path

– Mootu Pattulu
Jan 2 at 8:21





Yes i have set the path

– Mootu Pattulu
Jan 2 at 8:21













<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH . "/third_party/PHPExcel.php"; class Excel extends PHPExcel { public function __construct() { parent::__construct(); } } ?> This is excel.php file in the library

– Mootu Pattulu
Jan 2 at 8:22







<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH . "/third_party/PHPExcel.php"; class Excel extends PHPExcel { public function __construct() { parent::__construct(); } } ?> This is excel.php file in the library

– Mootu Pattulu
Jan 2 at 8:22















within application/third_party folder, is the file there?

– Hasta Dhana
Jan 2 at 8:23





within application/third_party folder, is the file there?

– Hasta Dhana
Jan 2 at 8:23












1 Answer
1






active

oldest

votes


















1














There's many ways to solve your problem. It all comes down to how (and where) your PHPExcel files are placed and invoked as from the error message we can assume that PHP is looking for the PHPExcel files in a different location than where they actually are.



YMMV, but this is my installation.



To output a XLS file I get the data arrays from my model (always use return $query->result_array(); instead of return $query->result(); in your model unless you want to convert the returned object to array later) and do:



    $this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle($report);

$titles = array_keys($data[0]);
$this->excel->getActiveSheet()->fromArray($titles, NULL, 'A1');
$this->excel->getActiveSheet()->fromArray($data, NULL, 'A2');

$filename='output.xls';

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');


Note that I'm calling $this->excel which comes from application/libraries/Excel.php where this code lives:



<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/third_party/phpexcel/PHPExcel.php";

class Excel extends PHPExcel {
public function __construct() {
parent::__construct();
}
}
?>


The core PHPExcel files are, as you can see from the require located on application/third_party/phpexcel/PHPExcel.php (always remember to respect case as routes are case-sensitive). On the same level where PHPExcel.php is, I have placed the directory with the core PHPExcel files -including autoloader.php-, named PHPExcel.



It's pretty straight-forward and has worked perfectly for me on several projects using CI 3.1.x






share|improve this answer
























  • Thank you sir But I have done it........:) and i got answer

    – Mootu Pattulu
    Jan 2 at 12:49













  • But I have another problem :(

    – Mootu Pattulu
    Jan 2 at 12:50











  • can you elaborate a little bit further? by re-reading your question, it seems that you're still having trouble to invoke the PHPExcel library correctly.

    – Javier Larroulet
    Jan 2 at 17:27











  • No sir i have load the PHP excel library correctly

    – Mootu Pattulu
    Jan 3 at 6:03











  • You should edit the question then... So far, it still states your problem is related to some variant of PHPExcel not found. What problem do you have now?

    – Javier Larroulet
    Jan 3 at 10:43











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003092%2fhow-to-export-the-data-in-excel-and-how-to-upload-phpexcel-file-into-controller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














There's many ways to solve your problem. It all comes down to how (and where) your PHPExcel files are placed and invoked as from the error message we can assume that PHP is looking for the PHPExcel files in a different location than where they actually are.



YMMV, but this is my installation.



To output a XLS file I get the data arrays from my model (always use return $query->result_array(); instead of return $query->result(); in your model unless you want to convert the returned object to array later) and do:



    $this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle($report);

$titles = array_keys($data[0]);
$this->excel->getActiveSheet()->fromArray($titles, NULL, 'A1');
$this->excel->getActiveSheet()->fromArray($data, NULL, 'A2');

$filename='output.xls';

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');


Note that I'm calling $this->excel which comes from application/libraries/Excel.php where this code lives:



<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/third_party/phpexcel/PHPExcel.php";

class Excel extends PHPExcel {
public function __construct() {
parent::__construct();
}
}
?>


The core PHPExcel files are, as you can see from the require located on application/third_party/phpexcel/PHPExcel.php (always remember to respect case as routes are case-sensitive). On the same level where PHPExcel.php is, I have placed the directory with the core PHPExcel files -including autoloader.php-, named PHPExcel.



It's pretty straight-forward and has worked perfectly for me on several projects using CI 3.1.x






share|improve this answer
























  • Thank you sir But I have done it........:) and i got answer

    – Mootu Pattulu
    Jan 2 at 12:49













  • But I have another problem :(

    – Mootu Pattulu
    Jan 2 at 12:50











  • can you elaborate a little bit further? by re-reading your question, it seems that you're still having trouble to invoke the PHPExcel library correctly.

    – Javier Larroulet
    Jan 2 at 17:27











  • No sir i have load the PHP excel library correctly

    – Mootu Pattulu
    Jan 3 at 6:03











  • You should edit the question then... So far, it still states your problem is related to some variant of PHPExcel not found. What problem do you have now?

    – Javier Larroulet
    Jan 3 at 10:43
















1














There's many ways to solve your problem. It all comes down to how (and where) your PHPExcel files are placed and invoked as from the error message we can assume that PHP is looking for the PHPExcel files in a different location than where they actually are.



YMMV, but this is my installation.



To output a XLS file I get the data arrays from my model (always use return $query->result_array(); instead of return $query->result(); in your model unless you want to convert the returned object to array later) and do:



    $this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle($report);

$titles = array_keys($data[0]);
$this->excel->getActiveSheet()->fromArray($titles, NULL, 'A1');
$this->excel->getActiveSheet()->fromArray($data, NULL, 'A2');

$filename='output.xls';

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');


Note that I'm calling $this->excel which comes from application/libraries/Excel.php where this code lives:



<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/third_party/phpexcel/PHPExcel.php";

class Excel extends PHPExcel {
public function __construct() {
parent::__construct();
}
}
?>


The core PHPExcel files are, as you can see from the require located on application/third_party/phpexcel/PHPExcel.php (always remember to respect case as routes are case-sensitive). On the same level where PHPExcel.php is, I have placed the directory with the core PHPExcel files -including autoloader.php-, named PHPExcel.



It's pretty straight-forward and has worked perfectly for me on several projects using CI 3.1.x






share|improve this answer
























  • Thank you sir But I have done it........:) and i got answer

    – Mootu Pattulu
    Jan 2 at 12:49













  • But I have another problem :(

    – Mootu Pattulu
    Jan 2 at 12:50











  • can you elaborate a little bit further? by re-reading your question, it seems that you're still having trouble to invoke the PHPExcel library correctly.

    – Javier Larroulet
    Jan 2 at 17:27











  • No sir i have load the PHP excel library correctly

    – Mootu Pattulu
    Jan 3 at 6:03











  • You should edit the question then... So far, it still states your problem is related to some variant of PHPExcel not found. What problem do you have now?

    – Javier Larroulet
    Jan 3 at 10:43














1












1








1







There's many ways to solve your problem. It all comes down to how (and where) your PHPExcel files are placed and invoked as from the error message we can assume that PHP is looking for the PHPExcel files in a different location than where they actually are.



YMMV, but this is my installation.



To output a XLS file I get the data arrays from my model (always use return $query->result_array(); instead of return $query->result(); in your model unless you want to convert the returned object to array later) and do:



    $this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle($report);

$titles = array_keys($data[0]);
$this->excel->getActiveSheet()->fromArray($titles, NULL, 'A1');
$this->excel->getActiveSheet()->fromArray($data, NULL, 'A2');

$filename='output.xls';

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');


Note that I'm calling $this->excel which comes from application/libraries/Excel.php where this code lives:



<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/third_party/phpexcel/PHPExcel.php";

class Excel extends PHPExcel {
public function __construct() {
parent::__construct();
}
}
?>


The core PHPExcel files are, as you can see from the require located on application/third_party/phpexcel/PHPExcel.php (always remember to respect case as routes are case-sensitive). On the same level where PHPExcel.php is, I have placed the directory with the core PHPExcel files -including autoloader.php-, named PHPExcel.



It's pretty straight-forward and has worked perfectly for me on several projects using CI 3.1.x






share|improve this answer













There's many ways to solve your problem. It all comes down to how (and where) your PHPExcel files are placed and invoked as from the error message we can assume that PHP is looking for the PHPExcel files in a different location than where they actually are.



YMMV, but this is my installation.



To output a XLS file I get the data arrays from my model (always use return $query->result_array(); instead of return $query->result(); in your model unless you want to convert the returned object to array later) and do:



    $this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle($report);

$titles = array_keys($data[0]);
$this->excel->getActiveSheet()->fromArray($titles, NULL, 'A1');
$this->excel->getActiveSheet()->fromArray($data, NULL, 'A2');

$filename='output.xls';

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');


Note that I'm calling $this->excel which comes from application/libraries/Excel.php where this code lives:



<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/third_party/phpexcel/PHPExcel.php";

class Excel extends PHPExcel {
public function __construct() {
parent::__construct();
}
}
?>


The core PHPExcel files are, as you can see from the require located on application/third_party/phpexcel/PHPExcel.php (always remember to respect case as routes are case-sensitive). On the same level where PHPExcel.php is, I have placed the directory with the core PHPExcel files -including autoloader.php-, named PHPExcel.



It's pretty straight-forward and has worked perfectly for me on several projects using CI 3.1.x







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 12:44









Javier LarrouletJavier Larroulet

1,4911421




1,4911421













  • Thank you sir But I have done it........:) and i got answer

    – Mootu Pattulu
    Jan 2 at 12:49













  • But I have another problem :(

    – Mootu Pattulu
    Jan 2 at 12:50











  • can you elaborate a little bit further? by re-reading your question, it seems that you're still having trouble to invoke the PHPExcel library correctly.

    – Javier Larroulet
    Jan 2 at 17:27











  • No sir i have load the PHP excel library correctly

    – Mootu Pattulu
    Jan 3 at 6:03











  • You should edit the question then... So far, it still states your problem is related to some variant of PHPExcel not found. What problem do you have now?

    – Javier Larroulet
    Jan 3 at 10:43



















  • Thank you sir But I have done it........:) and i got answer

    – Mootu Pattulu
    Jan 2 at 12:49













  • But I have another problem :(

    – Mootu Pattulu
    Jan 2 at 12:50











  • can you elaborate a little bit further? by re-reading your question, it seems that you're still having trouble to invoke the PHPExcel library correctly.

    – Javier Larroulet
    Jan 2 at 17:27











  • No sir i have load the PHP excel library correctly

    – Mootu Pattulu
    Jan 3 at 6:03











  • You should edit the question then... So far, it still states your problem is related to some variant of PHPExcel not found. What problem do you have now?

    – Javier Larroulet
    Jan 3 at 10:43

















Thank you sir But I have done it........:) and i got answer

– Mootu Pattulu
Jan 2 at 12:49







Thank you sir But I have done it........:) and i got answer

– Mootu Pattulu
Jan 2 at 12:49















But I have another problem :(

– Mootu Pattulu
Jan 2 at 12:50





But I have another problem :(

– Mootu Pattulu
Jan 2 at 12:50













can you elaborate a little bit further? by re-reading your question, it seems that you're still having trouble to invoke the PHPExcel library correctly.

– Javier Larroulet
Jan 2 at 17:27





can you elaborate a little bit further? by re-reading your question, it seems that you're still having trouble to invoke the PHPExcel library correctly.

– Javier Larroulet
Jan 2 at 17:27













No sir i have load the PHP excel library correctly

– Mootu Pattulu
Jan 3 at 6:03





No sir i have load the PHP excel library correctly

– Mootu Pattulu
Jan 3 at 6:03













You should edit the question then... So far, it still states your problem is related to some variant of PHPExcel not found. What problem do you have now?

– Javier Larroulet
Jan 3 at 10:43





You should edit the question then... So far, it still states your problem is related to some variant of PHPExcel not found. What problem do you have now?

– Javier Larroulet
Jan 3 at 10:43




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003092%2fhow-to-export-the-data-in-excel-and-how-to-upload-phpexcel-file-into-controller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas