PHP Classes
elePHPant
Icontem

How can PHP Read Excel File xlsx format using Simple XLSX: Parse and retrieve data from Excel XLS files

Recommend this page to a friend!

  Author Author  
Name: Sergey Shuchkin <contact>
Classes: 2 packages by
Country: Russian Federation Russian Federation
Age: 36
All time rank: 813 in Russian Federation Russian Federation
Week rank: 4 Up1 in Russian Federation Russian Federation Up


  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This class can be used to parse and retrieve data from Excel XLS spreadsheet files.

It can parse a given Excel XLS file by extracting its contents files and parsing the contained XML spreadsheet file.

The class provides functions to retrieve data for the spreadsheet worksheets, rows and cells.

Details

SimpleXLSX class 0.7.12 (Official)

Parse and retrieve data from Excel XLSx files. MS Excel 2007 workbooks PHP reader.

Sergey Shuchkin <sergey.shuchkin@gmail.com> 2010-2018

Basic Usage

if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
	print_r( $xlsx->rows() );
} else {
	echo SimpleXLSX::parse_error();
}
Array
(
    [0] => Array
        (
            [0] => ISBN
            [1] => title
            [2] => author
            [3] => publisher
            [4] => ctry
        )

    [1] => Array
        (
            [0] => 618260307
            [1] => The Hobbit
            [2] => J. R. R. Tolkien
            [3] => Houghton Mifflin
            [4] => USA
        )

    [2] => Array
        (
            [0] => 908606664
            [1] => Slinky Malinki
            [2] => Lynley Dodd
            [3] => Mallinson Rendel
            [4] => NZ
        )

)

Examples

// XLSX to html table
if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
	echo '<table>';
	foreach( $xlsx->rows() as $r ) {
		echo '<tr><td>'.implode('</td><td>', $r ).'</td></tr>';
	}
	echo '</table>';
} else {
	echo SimpleXLSX::parse_error();
}

// rowsEx() 
$xlsx = SimpleXLSX::parse('book.xlsx');
print_r( $xlsx->rowsEx() );

// Select Sheet
$xlsx = SimpleXLSX::parse('book.xlsx');
print_r( $xlsx->rows(1) ); // Sheet numeration started 0, we select second worksheet

// List sheets
$xlsx = SimpleXLSX::parse('book.xlsx');
print_r( $xlsx->sheetNames() ); // array( 0 => 'Sheet 1', 1 => 'Catalog' );

// Sheet by id
$xlsx = SimpleXLSX::parse('book.xlsx');	
echo 'Sheet Name 2 = '.$xlsx->sheetName(1);

// XLSX::parse remote data 
$data = file_get_contents('http://www.example.com/example.xlsx');
if ( $xlsx = SimpleXLSX::parse( $data, true) ) {
	list($num_cols, $num_rows) = $xlsx->dimension(1);
	echo $xlsx->sheetName(1).':'.$num_cols.'x'.$num_rows;
} else {
	echo SimpleXLSX::parse_error();
}

// Classic OOP style 
$xlsx = new SimpleXLSX('books.xlsx');
if ($xslx->success()) {
	print_r( $xlsx->rows() );
} else {
	echo 'xlsx error: '.$xlsx->error();
}

History

v0.7.12 (2018-06-17) $worksheet_id to $worksheet_index, sheet numeration started 0
v0.7.11 (2018-04-25) rowsEx(), added row index "r" to cell info
v0.7.10 (2018-04-21) fixed getCell, returns NULL if not exits
v0.7.9 (2018-03-17) fixed sheetNames() (namespaced or not namespaced attr)
v0.7.8 (2018-01-15) remove namespace prefixes (hardcoded)
v0.7.7 (2017-10-02) XML External Entity (XXE) Prevention (<!ENTITY xxe SYSTEM "file: ///etc/passwd" >]>)
v0.7.6 (2017-09-26) if worksheet_id === 0 (default) then detect first sheet (for LibreOffice capabilities)
v0.7.5 (2017-09-10) ->getCell() - fixed
v0.7.4 (2017-08-22) ::parse_error() - to get last error in "static style"
v0.7.3 (2017-08-14) ->_parse fixed relations reader, added ->getCell( sheet_id, address, format ) for direct cell reading
v0.7.2 (2017-05-13) ::parse( $filename ) helper method
v0.7.1 (2017-03-29) License added
v0.6.11 (2016-07-27) fixed timestamp()
v0.6.10 (2016-06-10) fixed search entries (UPPERCASE)
v0.6.9 (2015-04-12) $xlsx->datetime_format to force dates out
v0.6.8 (2013-10-13) fixed dimension() where 1 row only, fixed rowsEx() empty cells indexes (Daniel Stastka)
v0.6.7 (2013-08-10) fixed unzip (mac), added $debug param to _constructor to display errors
v0.6.6 (2013-06-03) +entryExists()
v0.6.5 (2013-03-18) fixed sheetName()
v0.6.4 (2013-03-13) rowsEx(), _parse(): fixed date column type & format detection
v0.6.3 (2013-03-13) rowsEx(): fixed formulas, added date type 'd', added format 'format'
					dimension(): fixed empty sheet dimension
                    + sheetNames() - returns array( sheet_id => sheet_name, sheet_id2 => sheet_name2 ...)
v0.6.2 (2012-10-04) fixed empty cells, rowsEx() returns type and formulas now
v0.6.1 (2012-09-14) removed "raise exception" and fixed _unzip
v0.6 (2012-09-13) success(), error(), __constructor( $filename, $is_data = false )
v0.5.1 (2012-09-13) sheetName() fixed
v0.5 (2012-09-12) sheetName()
v0.4 sheets(), sheetsCount(), unixstamp( $excelDateTime )
v0.3 - fixed empty cells (Gonzo patch)

  Classes of Sergey Shuchkin  >  How can PHP Read Excel File xlsx format using Simple XLSX  >  Download Download .zip .tar.gz  >  Support forum Support forum (106)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: How can PHP Read Excel File xlsx format using Simple XLSX
Base name: simple-xlsx
Description: Parse and retrieve data from Excel XLS files
Version: 0.7.12
PHP version: 5.0
License: GNU General Public License (GPL)
All time users: 19207 users
All time rank: 35
Week users: 41 users
Week rank: 2 Up
 
  Groups   Rate classes User ratings   Trackback  
  Applications   Related pages   Files Files  

  Groups  
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


  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Good (95%) Good (87%) Sufficient (75%) Good (85%) - - Sufficient (72%) 280
Month: Not enough user ratings

  Pages that reference this package  
Reading xls and xlsx files in PHP4 (Russian)
In the life of every PHP-developer comes a time when he is asked to import data from Excel, and limited to CSV, as a rule, no one wants, despite its obvious advantages - native support and the ability to read a file series (and thus saving memory).

Latest pages that reference packages Latest pages that reference packages


  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  
Example spreedsheet (countries_and_population.xlsx)
Used in examples

  Files folder image Files  
File Role Description
Accessible without login Plain text file license.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file simplexlsx.class.php Class simplexlsx php class source
Accessible without login Plain text file simplexlsx.example.php Example basic example
Accessible without login Plain text file simplexlsx.example2.php Example example: table output, switch worksheets
Accessible without login Plain text file simplexlsx.example3.php Example example: upload & parse
Accessible without login Plain text file where_countries_and_population_xlsx.txt Doc. url to download countries_and_population.xlsx

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