PHP Convert Excel to JSON: Convert data from Excel spreadsheet to JSON format

Recommend this page to a friend!

  Author  
Picture of Karl Holz
Name: Karl Holz <contact>
Classes: 14 packages by
Country: Canada Canada
Age: 39
All time rank: 50119 in Canada Canada
Week rank: 34 1 in Canada Canada
Innovation award
Innovation award
Nominee: 9x


  Detailed description   Download .zip .tar.gz   Install with Composer  
This class can convert data from Excel spreadsheet to JSON format.

It uses XSL stylesheets to parse Excel XML formats (xlsx and xlsm) and extract data from the spreadsheet cells.

The class can convert the extracted spreadsheet data into JSON format.

The converted JSON data is served for download.

Details
{startverticalbanner}
# Excel2JSON is an Excel XML parser to JSON document 

This class will allow you to use your excel workbook data in your Javascript/jQuery and other web applications. 
It's really simple to use, you can instantiate the class with the excel file you want to read, the file must 
be ooxml, normally with an xlsx or xlsm file extention MS Excel 2007.

I have done some work of updating the current class and added a configuration generator so that you can add name to cell
mapping.  The configuration is in INI format and will be based on the Excel file name; eg test.xslt will make test.ini.
The sheet name will be in the [] and each cell will be listed bellow

    [SheetName]
    A2="fname"
    B2="lname"
    ; commented out map
    ;C2="mname"

Check out the index.php to see the debug output

### Won't work with excel (xls) docs exported with:
 - Apache Open office (excel 2003 XML save as clashes)
 - Numbers 
 - Libre Office (excel 2003 XML save as clashes)
 
I made test.xlsx with Oxygen XML, and edited it with LibreOffice. it is the test excel file provided with this class
   
***
To see this class in action, view one of the test php docs on your webserver and view it's code
***
Note: if you get an error with the JSON output, set_excel with a second argument as seen bellow

    $e->set_excel($file, 'false');

other wise use 

    $e->set_excel($file);

***

value dump - test.php => dumps class values 

### Show how to use excel data without JSON print out  
- $e->filter_cells()
- $e->filter_data()

***

### Sheets test - print_sheets.php => on by default if worksheet not found or set.  

Prints out a JSON document of a list of excel workbook sheets

    require_once 'excelMap.class.php';
    $e=new excel2JSON();
    //$e->set_excel($file);
    $e->set_excel($file, 'false');
    $e->print_sheets();

***

### Data test - print_sheet_data.php

Prints out a JSON document of excel worksheet cell data in detail

    require_once 'excelMap.class.php';
    $e=new excel2JSON();
    //$e->set_excel($file);
    $e->set_excel($file, 'false');
    $e->load_sheet($sheet);
    $e->load_sheet_data();
    $e->print_sheet_data();

***

### Cell test - print_sheet_cells.php

Prints out a JSON document of excel worksheet cell and their values 

    require_once 'excelMap.class.php';
    $e=new excel2JSON();
    //$e->set_excel($file);
    $e->set_excel($file, 'false');
    $e->load_sheet($sheet);
    $e->load_sheet_data();
    $e->print_sheet_cells();

***

### Rows test - print_sheet_rows.php

Prints out a JSON document of excel worksheet cell and values grouped into rows 

    require_once 'excelMap.class.php';
    $e=new excel2JSON();
    //$e->set_excel($file);
    $e->set_excel($file, 'false');
    $e->load_sheet($sheet);
    $e->load_sheet_data();
    $e->print_sheet_rows();

***

### Data filter test - print_filter_data.php

Prints out a JSON document of excel worksheet cell data in detail, only cells added to cell list will be displayed

    require_once 'excelMap.class.php';
    $e=new excel2JSON();
    //$e->set_excel($file);
    $e->set_excel($file, 'false');
    $e->load_sheet($sheet);
    $e->load_sheet_data();
    $e->add_cell_list('A1');
    $e->add_cell_list('A2');
    $e->add_cell_list('B2');
    $e->add_cell_list('A4');
    $e->add_cell_list('B4');
    $e->print_filter_data();

***

### Cell filter test - print_filter_cells.php

Prints out a JSON document of excel worksheet cell and their values, only cells added to cell list will be displayed 

    require_once 'excelMap.class.php';
    $e=new excel2JSON();
    //$e->set_excel($file);
    $e->set_excel($file, 'false');
    $e->load_sheet($sheet);
    $e->load_sheet_data();
    $e->add_cell_list('A1');
    $e->add_cell_list('A2');
    $e->add_cell_list('B2');
    $e->add_cell_list('A4');
    $e->add_cell_list('B4');
    $e->print_filter_cells();

  Classes of Karl Holz  >  PHP Convert Excel to JSON  >  Download .zip .tar.gz  >  Support forum (4)  >  Blog  >  Latest changes  
Name: PHP Convert Excel to JSON
Base name: excel2json
Description: Convert data from Excel spreadsheet to JSON format
Version: 1.0.3
PHP version: 5.3
License: Custom (specified in a license file)
All time users: 1778 users
All time rank: 2183
Week users: 4 users
Week rank: 49
 
  Groups   User ratings   Applications   Related pages   Files  

  Groups  
XML XML parsing and generation View top rated classes
PHP 5 Classes using PHP 5 specific features View top rated classes
Files and Folders Listing, accessing and manipulating files and folders View top rated classes


  Recommendations  

Import excel file (xlsx format) into mysql database
I need to import excel data into database


  User ratings  
Not enough user ratings

  Applications that use this package  
No pages of applications that use this class were specified.

If you know an application of this package, send a message to the author to add a link here.


  Related pages  
Homepage
download excel file used to test this class
Documentation
PHP Doc

  Files  
File Role Description
dist (1 directory)
xsl (4 files)
Basic.test.php Example Example script
excelMap.class.php Class excel2JSON class
index.php Example Example script
LICENCE.txt Lic. Apache 2 licence
makeconfig.php Example Example script
print_filter_cells.php Example cell filter test - print_filter_cells.php Prints out a JSON document of excel worksheet cell and their values, only cells added to cell list will be displayed
print_filter_data.php Example data filter test - print_filter_data.php Prints out a JSON document of excel worksheet cell data in detail, only cells added to cell list will be displayed
print_sheets.php Example sheets test - print_sheets.php => on by default if worksheet not found or set. Prints out a JSON document of a list of excel workbook sheets
print_sheet_cells.php Example cell test - print_sheet_cells.php Prints out a JSON document of excel worksheet cell and their values
print_sheet_data.php Example data test - print_sheet_data.php Prints out a JSON document of excel worksheet cell data in detail
print_sheet_rows.php Example rows test - print_sheet_rows.php Prints out a JSON document of excel worksheet cell and values grouped into rows
README Doc. Updated Readme
test.ini Data Auxiliary data

  Files  /  dist  
File Role Description
css (2 files)

  Files  /  dist  /  css  
File Role Description
   bootstrap-theme.min.css Data Auxiliary data
   bootstrap.min.css Data Auxiliary data

  Files  /  xsl  
File Role Description
   cellList.xsl Data XSLT stylesheet, already embedded into class
   excel.xpr Data Auxiliary data
   StringLookup.xsl Data XSLT stylesheet, already embedded into class
   workbooks.xsl Data XSLT stylesheet, already embedded into class

Install with Composer - Download all files: excel2json.tar.gz excel2json.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.

For more information send a message to info at phpclasses dot org.