%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once FCPATH."application/third_party/PHPExcel.php"; class Excel extends PHPExcel { public function __construct() { parent::__construct(); } /** Write **/ function column_range($lower, $upper) { ++$upper; $return=array(); for ($i = $lower; $i !== $upper; ++$i) { array_push($return, $i); } return $return; } function set_cell_width_auto(){ foreach($this->column_range('A', $this->getActiveSheet()->getHighestDataColumn()) as $col) { $this->getActiveSheet()->getColumnDimension($col)->setAutoSize(true); } } function set_cell_width($width_arr){ foreach($this->column_range('A', $this->getActiveSheet()->getHighestDataColumn()) as $col) { $this->getActiveSheet()->getColumnDimension($col)->setWidth($width_arr[$col]); } } function excel_download($filename){ //$filename = $filename.'.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, 'Excel5'); $objWriter->save('php://output'); } function set_sheet_info($title=''){ $this->setActiveSheetIndex(0); $this->getActiveSheet()->setTitle($title); } function set_page_heading($title='', $cell='A', $cellno='1'){ $this->getActiveSheet()->setCellValue($cell.$cellno, $str); $this->getActiveSheet()->getStyle($cell.$cellno)->getFont()->setSize(15)->setBold(TRUE); $this->getActiveSheet()->mergeCells("{$cell}{$cellno}:K{$cellno}"); } function set_table_heading($thead, $cell='A', $cellno='1'){ $this->getActiveSheet()->fromArray($thead, null, $cell.$cellno); $highestCol=$this->getActiveSheet()->getHighestColumn(); $this->getActiveSheet()->getStyle("{$cell}{$cellno}:{$highestCol}{$cellno}")->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('e3e3e3'); $this->getActiveSheet()->getStyle("{$cell}{$cellno}:{$highestCol}{$cellno}")->getFont()->setBold(TRUE); } function set_table_data($data, $cell='A2'){ $this->getActiveSheet()->fromArray($data, null, $cell); } /** Read **/ function read($file){ try { $inputFileType=PHPExcel_IOFactory::identify($file); $objReader=PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel=$objReader->load($file); } catch(Exception $e) { die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); } $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); $rows=array(); for($row = 1; $row <= $highestRow; $row++){ $r=$sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row); $rows[]=isset($r[0])?$r[0]:array(); } return $rows; } } /** -:How to Use:- //Write $this->load->library('excel'); $this->excel->set_sheet_info('Sheet1'); $this->excel->set_table_heading($cols); $this->excel->set_table_data($dataAr); $this->excel->set_cell_width_auto(); $this->excel->excel_download("filename.xlsx"); //Read $this->load->library('excel'); $rows=$this->excel->read("filename.xlsx"); **/