Git Product home page Git Product logo

ci_office_excel's Introduction

ci_office_excel

This is a library for codeigniter to read and generate excel document.

How to use

First

$this->load->library('excel');

Read

$objLoad = PHPExcel_IOFactory::load('example.xls');
$array_data = array();
foreach ($objLoad->getWorksheetIterator() as $worksheet) {
	$worksheetTitle     = $worksheet->getTitle();
	$highestRow         = $worksheet->getHighestRow(); // e.g. 10
	$highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
	$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

	for ($row = 2; $row <= $highestRow; ++ $row) {
		for ($col = 0; $col < $highestColumnIndex; ++ $col) {
		  $cell = $worksheet->getCellByColumnAndRow($col, $row);
		  $val = $cell->getValue();
		  $array_data[$row][$col] = $val;
		}
	}
}

Generate

$i=2;
$this->load->library('excel');
$filename='example.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

// Set Header on table
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle('Phone Book');
$this->excel->getActiveSheet()->setCellValue('A1', 'id');
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

$this->excel->getActiveSheet()->setCellValue('B1', 'name');
$this->excel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

$this->excel->getActiveSheet()->setCellValue('C1', 'number');
$this->excel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

// write on table
$this->excel->getActiveSheet()->setCellValue('A2', '1');
$this->excel->getActiveSheet()->setCellValue('B2', 'George Lovato');
$this->excel->getActiveSheet()->setCellValue('C2', '21000187');

$this->excel->getProperties()->setCreator("author");
$this->excel->getProperties()->setLastModifiedBy("author");
$this->excel->getProperties()->setTitle($filename);
$this->excel->getProperties()->setSubject("Phone Book");
$this->excel->getProperties()->setDescription(base_url());
$this->excel->getProperties()->setCategory("Phone Book");

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

ci_office_excel's People

Contributors

remithzu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.