This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

CloudwaysCDN — a powerful solution that offers superior performance and satisfied global audience for your business. Read More

How to Create and Edit Excel Spreadsheets in PHP

Updated on  February 21, 2018

3 Min Read
Reading Time: 3 minutes

PHP is highly enriched with features of a good scripting language. It provides numerous libraries for specific purposes. PHP provides a library to deal with Excel files. It is called PHP Excel library. It enables you to read and write spreadsheets in various formats including csv, xls, ods, and xlsx. You will need to ensure that you have PHP’s upgraded version not older than PHP 5.2 . Moreover, you should have installed extensions php_qd2, php_xml and php_zip.

excel sheets in php

You might also like: How To Host PHP On DigitalOcean

How To Create Spreadsheet in PHP?

Spreadsheet creation is a very common use case in PHP development. It is used to export data to an Excel spreadsheet. Below is the code for creating an excel spreadsheet using the PHP Excel library.


You might also like: How To Import And Export CSV Files Using PHP And MySQL

Alternate Approach:

Alternatively, spreadsheet can be downloaded rather than saving it to the server. You may use the following code:

How To Edit an Existing Spreadsheet in PHP?

The editing process is rather similar to the spreadsheet creation process. Use the following code to do this:

How To Prepare Spreadsheets for Printing?

To get a spreadsheet ready, you should set size, margins and paper orientation.


The PHPExcel library is very useful for calculations and charts. It is often used to store data in Excel sheets or to import data from Excel spreadsheets via PHP website. Got any questions about what we discussed? Leave a comment and I’ll get back to you!

Apart from knowing tricks such as working on spreadsheets in PHP, any smart PHP developer knows the importance of an excellent hosting solution for the web apps he/she creates. The Cloudways Managed PHP Hosting Platform gives you ultra-fast performance thanks to its optimized hosting stack. Launch your free trial today to venture into the future of PHP hosting.

Share your opinion in the comment section. COMMENT NOW

Create PHP websites without the worry of server management.

Deploy your PHP app on optimized PHP hosting servers.

About The Author

Ahmed Khan

Ahmed was a PHP community expert at Cloudways – A Managed PHP Hosting Cloud Platform. He is a software engineer with extensive knowledge in PHP and SEO. He loves watching Game of Thrones is his free time. Follow Ahmed on Twitter to stay updated with his works. You can email him at

Stay Connected:

Get Our Newsletter
Be the first to get the latest updates and tutorials.