Giter Site home page Giter Site logo

ci-phpexcel's Introduction

Codeigniter + PHPExcel

How to Generate Excel File in Codeigniter using PHPExcel

This code was originally written by [Webslesson.](https://www.webslesson.info/2017/04/generate-excel-file-in-codeigniter-using-phpexcel.html)

Versions

Application used for creating the system.

Developer Version #
CodeIgniter EllisLab 3.2.0
PHPExcel PHPOffice 1.8.1
PHP PHP 5.6

Steps

Steps:

  1. Download PhpExcel File on this link https://github.com/PHPOffice/PHPExcel
  2. Extract the file and open the ./Classes folder
  3. Inside the ./Classes/ folder copy ./PHPExcel folder and PHPExcel.php file
  4. Paste the file inside your codeigniter app ./application/libraries/ folder
  5. The next steps will be creating of php files..

Create files and folders

application/libraries/Excel.php

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

require_once('PHPExcel.php');

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

application/libraries/IOFactory.php

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

require_once('PHPExcel/IOFactory.php');

class IOFactory extends PHPExcel_IOFactory
{
	public function __construct()
	{
		parent::__construct();
	}
}

application/controllers/Excel_export.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Report extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		$this->load->library("excel");

	}
	public function index()
	{
		$object = new PHPExcel();
		$object->setActiveSheetIndex(0);

		$object->getActiveSheet()->setCellValueByColumnAndRow(0, 2, 'Sample Text');

		$object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel5');
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="Employee Data.xls"');
		$object_writer->save('php://output');
	}

}

:) Thanks!

ci-phpexcel's People

Watchers

 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.