PHP Classes

MS-Excel Stream Handler: Stream wrapper to read and write MS Excel files

Recommend this page to a friend!
  Info   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (54)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 59%Total: 60,214 All time: 2 This week: 82Down
Version License PHP version Categories
xlsstream 1.0.0BSD License4.3Files and Folders, Stream wrappers
Description 

Author

This class implements a stream handler interface to read and write Microsoft Excel spreadsheet files in the XLS format.

XLS files may be read and written using PHP fopen, fread or fwrite, or any other PHP functions that can access to streams.

The file name has the format xlsfile://path/to/spreadsheet.xls where /path/to/spreadsheet.xls is the path of the actual spreadsheet file to be read or written.

To create a XLS file just pass a serialized array of spreadsheet row arrays that associate the column names with their values.

In the current version the class does not process the data read from a XLS file. Instead it just returns the raw XLS file data as is.

This class requires at least PHP 4.3.0 as that is the version when stream handling support was introduced in PHP.

Innovation Award
PHP Programming Innovation award winner
October 2004
Winner


Prize: One downloadable copy of Roadsend PHP Compiler
Microsoft Excel is one of the most popular applications for desktop users, especially as a business work tool. Therefore the generation of spreadsheets in the Excel XLS format is a frequently used feature of Web applications to provide information in a way that lets their users do their work using Excel.

There have always been plenty of solutions to generate spreadsheet files in the XLS format. However, this class provide an innovating approach to the problem of generating XLS files.

This class takes advantage of the stream wrapping capabilities introduced in PHP 4.3 to let applications create XLS files just by using common file handling functions, making the generation of this type of files a trivial task.

Manuel Lemos
Picture of Ignatius Teo
Name: Ignatius Teo is available for providing paid consulting. Contact Ignatius Teo .
Classes: 2 packages by
Country: Australia Australia
Age: 58
All time rank: 51 in Australia Australia
Week rank: 371 Down3 in Australia Australia Down
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Details

NAME ====== xlsStream VERSION ======= 0.3 - 20 Jan 2005 DESCRIPTION =========== MS-Excel stream handler SYNOPSIS ======== This class read/writes a data stream directly from/to a Microsoft Excel spreadsheet opened with the xlsfile:// protocol. This is used to export associative array data directly to MS-Excel. REQUIREMENTS ============ PHP4 >= 4.3.2 USAGE ===== Include this file in your script, using include/require: <?php require_once "excel.php"; ?> To export an associative array to an Excel spreadsheet, simply call fopen() using the registered stream wrapper protocol xlsfile://, for example: $fp = fopen("xlsfile://path/to/file.xls", "wb"); This version expects an associative array in the form: $data = array( 0 => array( "column1" => "value1", "column2" => "value2", "column3" => "value3", "column4" => "value4", "column5" => "value5", ), 1 => array( "column1" => "value6", "column2" => "value7", "column3" => "value8", "column4" => "value9", "column5" => "value10", ), ... ); Now write your data array using a single call to fwrite(): fwrite($fp, $data); Then call fclose(), as you would normally. fclose($fp); To download an excel spreadsheet: <?php header ("Content-Type: application/x-msexcel"); header ("Content-Disposition: attachment; filename=\"sample.xls\"" ); readfile("xlsfile://path/to/sample.xls"); exit; ?> FILES ===== excel.php Main class example_export.php Example export script example_download.php Example download script CHANGELOG ========= 0.3 - 20th Jan 2005 Fixed generated .xls unrecognized format issue due to server endian mode (Thanks to Charles Turner for pointing this out) 0.2 - 7th Jan 2005 Fixed bug with arrays and excel files with sizes over the 8192 byte limit 0.1 - 21th Oct 2004 Initial release LICENSE ======= Copyright (C)2004-2005, Ignatius Teo <http://act28.com> All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. COPYRIGHT ========= Copyright (C) 2004-2005 Ignatius Teo <http://act28.com> All Rights Reserved $Id: README,v 1.3 2005/01/20 09:58:58 Owner Exp $

  Files folder image Files  
File Role Description
Accessible without login Plain text file example_download.php Example Example download script
Accessible without login Plain text file example_export.php Example Example export script
Plain text file excel.php Class Primary class
Accessible without login Plain text file README Doc. README file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:60,214
This week:0
All time:2
This week:82Down
User Ratings User Comments (13)
 All time
Utility:77%StarStarStarStar
Consistency:72%StarStarStarStar
Documentation:66%StarStarStarStar
Examples:69%StarStarStarStar
Tests:-
Videos:-
Overall:59%StarStarStar
Rank:1303
 
How to read data is not there
6 years ago (Mamata Mohapatra)
0%Star
There were two error en excel.
7 years ago (Mar)
77%StarStarStarStar
Very easy to use.
9 years ago (Carlos Alberto Garcia)
75%StarStarStarStar
bueno
12 years ago (guadalupe)
80%StarStarStarStarStar
bueno
12 years ago (guadalupe)
80%StarStarStarStarStar
Delivers what's promised.
12 years ago (Tom Carnevale)
75%StarStarStarStar
nice
12 years ago (siddharth)
72%StarStarStarStar
not work at php 5.
14 years ago (rio danar)
20%StarStar
Awful
14 years ago (Nick Howarth)
15%Star
Tested for writing Excel files only, works perfect.
15 years ago (petruchek)
80%StarStarStarStarStar
Love this stream.
16 years ago (Joe M)
77%StarStarStarStar
Never worked for me!
16 years ago (Abdul-Aziz Al-Oraij)
5%Star
It works great and its a snap to use.
16 years ago (Dustin Davis)
55%StarStarStar