Welcome Guest, Not a member yet? Register   Sign In
PHP Excel CodeIgniter
#1

(This post was last modified: 12-12-2017, 07:20 AM by ciadmin.)

hello, programmers.

Would you help me in this problem?

I am using PHPExcel to generate excel files.

Now my query looks like this.

MODEL:
Code:
class ReportModel extends CI_Model
{
 public function getReport() {
     $this->db->select('a.LnCode as Line Code, c.MachDesc as Machine');
     $this->db->from('tbl_Audit_H as a');
     $this->db->join('tbl_Audit_D as b', 'a.ChkNum = b.ChkNum');
     $this->db->join('tbl_Machines as c', 'a.MachCode = c.MachCode');
   $result = $this->db->get();

   return $result->result_array();
 }

 public function getMachine() {
     $result =  $this->db->get('tbl_Machines');
     return $result->result_array();
 }
}



CONTROLLER:
Code:
 public function getReport() {
   $machines = $this->reportmodel->getMachine();
   $results = $this->reportmodel->getReport();
   $objPHPExcel = new PHPExcel();
   /* Cache Results */
   $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;
   PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
   
   foreach ($machines as $machine) {
     // Create a new worksheet called “My Data”
     $myWorkSheet = new PHPExcel_Worksheet($objPHPExcel, $machine['MachDesc']);
     // Attach the “My Data” worksheet as the first worksheet in the PHPExcel object
     $objPHPExcel->addSheet($myWorkSheet);
     $objPHPExcel->setActiveSheetIndexByName($machine['MachDesc']);
     $activeSheet = $machine['MachDesc'];


   }
   $sheetIndex = $objPHPExcel->getIndex($objPHPExcel->getSheetByName('Worksheet'));
   $objPHPExcel->removeSheetByIndex($sheetIndex);
   
   header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
   header('Content-Disposition: attachment;filename="myfile.xlsx"');
   header('Cache-Control: max-age=0');
   $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
   $objWriter->save('php://output');

 }


Now I have attached an excel file. That is how the client wants the report to look like.

So basically the report create a sheet per machine.

It fills each sheet with the data related to that machine. 

It groups the result per line number, then per product then per date.

Please see the attached file. Thanks so much. I hope I explain myself well. If you have question for clarification please let me know. Thanks!

Attached Files
.xlsx   Checklist(With Findings) Summary.xlsx (Size: 27.31 KB / Downloads: 137)
Reply


Messages In This Thread
PHP Excel CodeIgniter - by danangeloalcanar - 12-07-2017, 12:47 AM
RE: PHP EXCEL CODIGNITER - by ivantcholakov - 12-09-2017, 09:15 PM
RE: PHP EXCEL CODIGNITER - by qury - 12-12-2017, 06:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB