1. Products
  2.   Spreadsheet
  3.   PHP
  4.   Simple Excel-PHP
 
  

Open Source PHP Library for Working with Spreadsheet

Create, Read, Parse & Convert b/t MS Excel XML, CSV, TSV, HTML & JSON File Formats via Open Source PHP API.

What is Simple Excel-PHP?

Simple Excel-PHP is a lightweight open source PHP library with a simplistic approach to reading, writing, parsing, & convert Microsoft Excel file formats. Developers can use this spreadsheet library to easily convert between popular file formats like XML CSV, TSV HTML & JSON formats.

Simple Excel-PHP provides support for several important features such as parsing HTML tables, parsing Microsoft Excel CSV, TSV & XLSX Spreadsheet, creating a new workbook or worksheet, writing spreadsheet &HTML tables as well as writing TSV Spreadsheet, Excel XLSX and Excel 2003 XML Spreadsheet files.

Previous Next

Getting Started with Simple Excel-PHP

The recommended way to install SimpleExcel-PHP into your project is by using the composer. Please include this package in your composer.json.

Install Simple-Excel-PHP via

 "require" : {
   "faisalman/simple-excel-php" : "0.3.*" } 

You can also clone the project with Git by running

Create New Excel Workbook via Free PHP Library

Simple Excel-PHP library enables software developers to create a new Microsoft Excel XLSX Spreadsheet with ease. To create a new file first instantiate new objects and add some data to the writer. After that save the file with a specified name and location of your choice. Developers can also easily add sheets to an existing instance of Workbook. You can assign a name to the sheet. The following example shows how software developers can generate a new Excel spreadsheet file inside PHP applications via PHP commands.

How to Create New Excel Spreadsheet inside PHP Apps?

 use SimpleExcel\SimpleExcel

$excel = new SimpleExcel('CSV');
$excel->parser->loadFile('test.csv');

echo $excel->parser->getCell(1, 1);

$excel->convertTo('JSON');
$excel->writer->addRow(array('add', 'another', 'row'));
$excel->writer->saveFile('example');

Convert CSV File to Excel 2003 XML

This spreadsheet library allows software developers to Convert CSV Files to Excel 2003 XML file format with just a few lines of code. First of all, you need to load a CSV file from the server to be parsed and transfer data from parser to writer and change the writer type to XML. After that save the file with the specified name and specified target. Here is a very useful example that shows how SimpleExcel library can used to create a new worksheet, add rows and columns to it and save it as an XML file

How to Create a Worksheet and Save It as XML File inside PHP Apps?

use SimpleExcel\SimpleExcel;
use SimpleExcel\Spreadsheet\Worksheet;

$worksheet = new Worksheet();                                       // Define a new worksheet
$worksheet->insertRecord(array('ID', 'Nama Kota', 'Kode'));

$excel = new SimpleExcel();
$excel->insertWorksheet($worksheet);                                // Insert defined worksheet to excel document
$excel->insertWorksheet(new Worksheet());                           // Insert a new blank worksheet
$excel->getWorksheet(2)->insertRecord(array('1', '2', '3'));        // Insert a new row to that blank worksheet

$excel->exportFile('/home/faisalman/Downloads/test.xml', 'XML');    // Write document as XML file

Parse Excel 2003 XML File

This free Excel library enables software developers to parse Excel 2003 XML files inside their own PHP applications. To parse the XML file first you need to load the file from the server. After that, you can get a complete array of the table. You can also get data from a specific row or cell of the table with ease. The following example shows how software developers can parse and get specific content from a CSV file inside PHP applications.

How Get Specific Content from CSV File inside PHP Apps?

use SimpleExcel\SimpleExcel;

$excel = new SimpleExcel();
$excel->loadFile('/home/faisalman/Downloads/test.csv', 'CSV');  // Load CSV file

print_r($excel->getWorksheet(1));                   // get array of all cells from worksheet 1
print_r($excel->getWorksheet(1)->getColumn(2));     // get array of cells in column 2 from worksheet 1
print_r($excel->getWorksheet(1)->getRecord(3));        // get array of cells in row 3 from worksheet 1
print_r($excel->getWorksheet(1)->getCell(1, 2));    // get specific cell in row 1 column 2 from worksheet 1

 English