PHP Classes

Basic Excel: Import and export Excel files to XLS, XLSX and CSV

Recommend this page to a friend!

  Author Author  
Picture of Craig Smith
Name: Craig Smith <contact>
Classes: 5 packages by
Country: New Zealand New Zealand
Age: 44
All time rank: 3453 in New Zealand New Zealand
Week rank: 33 Up1 in New Zealand New Zealand Up


  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This package can import and export Excel files to XLS, XLSX and CSV file formats.

It provides reader and writer factory classes that can create specific objects of classes depending on the file format that is meant to be imported or exported.

Currently it provides specific classes for reading or writing data to CSV, XLS or XLSX formats.

Details

BasicExcel

Lightweight Basic Excel Read / Writer for PHP 5.3+

This Class can both read and write to CSV, XLS and XLSX. Added in the abiliity to guess which file type it is and parse accordingly to array

Examples - Reading

1) From a file

   try {
	$xmldata = \BasicExcel\Reader::readFile('/path/to/abc.csv'); //or abc.xls or abc.xlsx
    echo '<pre>' . print_r($xmldata->toArray() , 1) . '</pre>';
   }catch(Exception $e){
	echo $e->getMessage();
	exit;
   }

2) from an upload

   try {
	$xmldata = \BasicExcel\Reader::readUpload($_FILES['upload']);
    echo '<pre>' . print_r($xmldata->toArray() , 1) . '</pre>';
   }catch(Exception $e){
	echo $e->getMessage();
	exit;
   }

3) You can even get the file type if that is all you seek.

   try {
	$type = \BasicExcel\Reader::identify('/path/to/file');
	echo $type;
   }catch(Exception $e){
	echo $e->getMessage();
	exit;
   }

Examples - Writing

1) write a csv / xls / xlsx from an array

$data = array(
    array('Nr.', 'Name', 'E-Mail'),
    array(1, 'Jane Smith', 'jane.smith@fakemail.com'),
    array(2, 'John Smith', 'john.smith@fakemail.com'));
		
   try {
	$csvwriter = new \BasicExcel\Writer\Csv(); //or \Xsl || \Xslx
	$csvwriter->fromArray($data);
	$csvwriter->writeFile('myfilename.csv');
	//OR
	$csvwriter->download('myfilename.csv');
   }catch(Exception $e){
	echo $e->getMessage();
	exit;
   }

2)Usingn XLS or XLSX you can have multiple sheets.


$data = array(
    'Names' => array(
        array('Nr.', 'Name', 'E-Mail'),
        array(1, 'Jane Smith', 'jane.smith@fakemail.com'),
        array(2, 'John Smith', 'john.smith@fakemail.com')
    ),
    'Ages' => array(
        array('Nr.', 'Age'),
        array(1, 103),
        array(2, 21)
    ),
    'Genders' => array(
        array('Nr.', 'Gender'),
        array(1, 'Male'),
        array(2, 'Female')
    )
);
		
   try {
	$csvwriter = new \BasicExcel\Writer\Xls(); //or \Xslx
	$csvwriter->fromArray($data);
	$csvwriter->writeFile('myfilename.csv');
	//OR
	$csvwriter->download('myfilename.csv');
   }catch(Exception $e){
	echo $e->getMessage();
	exit;
   }

Full documentation available soon at http://www.omnihost.co.nz


  Classes of Craig Smith  >  Basic Excel  >  Download Download .zip .tar.gz  >  Support forum Support forum (10)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: Basic Excel
Base name: basic-excel
Description: Import and export Excel files to XLS, XLSX and CSV
Version: 1.9
PHP version: 5.4
License: BSD License
All time users: 5121 users
All time rank: 518
Week users: 12 users
Week rank: 25 Up
 
  Groups   Rate classes User ratings   Applications   Files Files  

  Groups  
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes


  Recommendations  

What is the best PHP class to write an Excel file?
Writing collected data to native excel file

What is the best PHP excel mysql import class?
Excel import to MySQL table

What is the best PHP xlsx writer class?
Export to Excel


  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Sufficient (75%) Sufficient (68%) - Sufficient (60%) - - Not sure (50%) 2356
Month: Not yet rated by the users

  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.

  Files folder image Files  
File Role Description
Files folder imageBasicExcel (4 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  BasicExcel  
File Role Description
Files folder imageReader (3 files)
Files folder imageWriter (3 files)
  Plain text file AbstractReader.php Class Class source
  Plain text file AbstractWriter.php Class Class source
  Plain text file Exception.php Class Class source
  Plain text file Reader.php Class Class source

  Files folder image Files  /  BasicExcel  /  Reader  
File Role Description
  Plain text file Csv.php Class Class source
  Plain text file Xls.php Class Class source
  Plain text file Xlsx.php Class Class source

  Files folder image Files  /  BasicExcel  /  Writer  
File Role Description
  Plain text file Csv.php Class Class source
  Plain text file Xls.php Class Class source
  Plain text file Xlsx.php Class Class source

Install with Composer Install with Composer - Download Download all files: basic-excel.tar.gz basic-excel.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
File Role Description
Files folder imageBasicExcel (4 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  BasicExcel  
File Role Description
Files folder imageReader (3 files)
Files folder imageWriter (3 files)
  Plain text file AbstractReader.php Class Class source
  Plain text file AbstractWriter.php Class Class source
  Plain text file Exception.php Class Class source
  Plain text file Reader.php Class Class source

  Files folder image Files  /  BasicExcel  /  Reader  
File Role Description
  Plain text file Csv.php Class Class source
  Plain text file Xls.php Class Class source
  Plain text file Xlsx.php Class Class source

  Files folder image Files  /  BasicExcel  /  Writer  
File Role Description
  Plain text file Csv.php Class Class source
  Plain text file Xls.php Class Class source
  Plain text file Xlsx.php Class Class source

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