PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum (10)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (3 days ago) RSS 2.0 feedStarStarStar 50%Total: 5,177 This week: 19All time: 513 This week: 10Up
Version License PHP version Categories
basic-excel 1.12BSD License5.4PHP 5
Description 

Author

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.

Picture of Craig Smith
  Performance   Level  
Name: Craig Smith <contact>
Classes: 5 packages by
Country: New Zealand New Zealand

Recommendations

Example

<?php

require_once('BasicExcel/Reader.php');
\
BasicExcel\Reader::registerAutoloader();


$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 \Xls || \Xlsx
   
$csvwriter->fromArray($data);
   
//$csvwriter->writeFile('myfilename.csv');
    //OR
   
$csvwriter->download('myfilename.csv');
} catch (
Exception $e) {
    echo
$e->getMessage();
    exit;
}




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


  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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:5,177
This week:19
All time:513
This week:10Up
User Ratings User Comments (4)
 All time
Utility:75%StarStarStarStar
Consistency:68%StarStarStarStar
Documentation:-
Examples:60%StarStarStarStar
Tests:-
Videos:-
Overall:50%StarStarStar
Rank:2359
 
Your Reader::readFile() method is not working.
4 years ago (Jordan Mendes Prestes)
25%StarStar
The example worked which is great (as often examples o not wo...
4 years ago (Rick Ruggiero)
62%StarStarStarStar
Parses xls and xlsx good!
8 years ago (oleg proskurin)
60%StarStarStarStar
not working
10 years ago (synthetron)
0%Star