How to generate Excel using PhpSpreadsheet in CodeIgniter

In this post, I would like to show using of PhpSpreadsheet library within your CodeIgniter 3 project. PhpSpreadsheet is a pure PHP library for reading and writing spreadsheet files.

Here is my another post, you might be interested in – How to use PHPExcel with CodeIgniter?

How to generate Excel using PhpSpreadsheet in CodeIgniter

Here are the steps to generate Excel in the CodeIgniter 3 application with PhpSpreadsheet:

Step 1: Download and install CodeIgniter.

Step 2: Run the below composer command to download phpspreadsheet the library from your project folder. It will create a new folder called “vendor” and it will download phpoffice/phpspreadsheet library into it.

Here is my the directory structure after installing phpoffice/phpspreadsheet

Step 3: Open application/config/config.php file and set your vendor directory path

Step 4: Use phpspreadsheet library inside in your controller, here is the sample:

For more information, here is the official documentation page of – phpspreadsheet documentation

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Subscribe
Notify of
guest
14 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
MNAlviansyah
MNAlviansyah
2 years ago

can you make tutorial about import ?

arjun
2 years ago
Reply to  MNAlviansyah

Sure I will do in this week

Simone Zanaboni
Simone Zanaboni
2 years ago

Hi Arjun,
with your code I have problems when I try to open the file with Excel through the ‘Open with / Save’ menu.
I had to substitute the line:
header(‘Content-Type: application/vnd.ms-excel’);
with:
header(‘Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’);

Louis Ergi Al-xavieri
Louis Ergi Al-xavieri
2 years ago

i can’t download it.even i has been subscribe to you

arjun
2 years ago

Sorry I about it I will check and fix.

Davi Sousa
Davi Sousa
2 years ago

I GET THIS ERROR IN THE FILE DOWNLOADED
An uncaught Exception was encountered
Type: Error

Message: Class ‘PhpOfficePhpSpreadsheetSpreadsheet’ not found

Filename: C:laragonwwwsitprogbdapplicationcontrollersWelcome.php
Line Number: 11

Backtrace:

File: C:laragonwwwsitprogbd7d91e3-7a16-40e5-852c-a29107d38299index.php
Line: 315
Function: require_once

Hoi Ying Lee
Hoi Ying Lee
2 years ago

Thanks, It helps a lot

felipe
felipe
2 years ago

Hi Arjun, I tried to follow your tutorial and I’m getting an response error. I created a thread on stackoverflow about it, but no success:

https://stackoverflow.com/questions/54671184/getting-err-invalid-response-with-codeigniter-and-phpspreadsheet?noredirect=1#comment96132334_54671184

Can you help me?

Baptiste Robichon
Baptiste Robichon
1 year ago

Good article thanks !!

bxbx
bxbx
1 year ago

super

arun dhiman
arun dhiman
2 months ago

hii how can i use this spreadsheet

arun dhiman
arun dhiman
2 months ago
Reply to  Arjun

actually m working in hmvc in codeigniter where i can make sub modules so how can i use

DMCA.com Protection Status
14
0
Would love your thoughts, please comment.x
()
x