PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!

  Author Author  
Name: Karl Holz is available for providing paid consulting. Contact Karl Holz .
Classes: 13 packages by
Country: Canada Canada
Age: 36
All time rank: 58819 in Canada Canada
Week rank: 99 Up2 in Canada Canada Up
Innovation award
Innovation award
Nominee: 8x


  Detailed description   Download Download .zip .tar.gz   Install with Composer 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 Download .zip .tar.gz  >  Support forum Support forum (3)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed 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: 1342 users
All time rank: 2805
Week users: 8 users
Week rank: 114 Up
 
  Groups   Rate classes User ratings   Applications   Related pages   Files Files  

  Groups  
Group folder image XML XML parsing and generation View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image 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.

Add link image 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 folder image Files  
File Role Description
Files folder imagedist (1 directory)
Files folder imagexsl (4 files)
Accessible without login Plain text file Basic.test.php Example Example script
Plain text file excelMap.class.php Class excel2JSON class
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENCE.txt Lic. Apache 2 licence
Accessible without login Plain text file makeconfig.php Example Example script
Accessible without login Plain text file 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
Accessible without login Plain text file 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
Accessible without login Plain text file 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
Accessible without login Plain text file print_sheet_cells.php Example cell test - print_sheet_cells.php Prints out a JSON document of excel worksheet cell and their values
Accessible without login Plain text file print_sheet_data.php Example data test - print_sheet_data.php Prints out a JSON document of excel worksheet cell data in detail
Accessible without login Plain text file 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
Accessible without login Plain text file README Doc. Updated Readme
Accessible without login Plain text file test.ini Data Auxiliary data

  Files folder image Files  /  dist  
File Role Description
Files folder imagecss (2 files)

  Files folder image Files  /  dist  /  css  
File Role Description
  Accessible without login Plain text file bootstrap-theme.min.css Data Auxiliary data
  Accessible without login Plain text file bootstrap.min.css Data Auxiliary data

  Files folder image Files  /  xsl  
File Role Description
  Accessible without login Plain text file cellList.xsl Data XSLT stylesheet, already embedded into class
  Accessible without login Plain text file excel.xpr Data Auxiliary data
  Accessible without login Plain text file StringLookup.xsl Data XSLT stylesheet, already embedded into class
  Accessible without login Plain text file workbooks.xsl Data XSLT stylesheet, already embedded into class

Install with Composer Install with Composer - Download 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.