Simplexcel.php - Easily read / parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc spreadsheet tabular file formats

Overview

Simple Excel

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

For further deatails see the GitHuib Pages site: http://faisalman.github.com/simple-excel-php

PHP Versions Supported

PHP >= 5.3

Installation

If you're using Composer to manage libraries, include this package in your composer.json

"require" : {
    "faisalman/simple-excel-php" : "0.3.*"
}

If you want to try version 0.4 (still in develop branch) you can use

"require" : {
    "faisalman/simple-excel-php" : "develop as 0.4.0-alpha"
}

Or just load this library in your PHP project by including SimpleExcel.php

require_once('../your/project/directory/here/lib/SimpleExcel/SimpleExcel.php');

Features

  • Available parsers: Microsoft Excel 2003 XML, CSV, TSV, HTML, JSON
  • Available writers: Microsoft Excel 2003 XML, CSV, TSV, HTML, JSON

Usage

use SimpleExcel\SimpleExcel

$excel = new SimpleExcel('CSV');
$excel->parser->loadFile('test.csv');

echo $excel->parser->getCell(1, 1);

$excel->convertTo('JSON');
$excel->writer->addRow(array('add', 'another', 'row'));
$excel->writer->saveFile('example');

Development

Build Status

Testing

$ phpunit --configuration test/phpunit.xml

Next version 0.4.0-alpha is now available under develop branch

License

Copyright (c) 2011-2012 Faisalman <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Export array to CSV to disk

    Export array to CSV to disk

    Hello, please how can i export array to CSV and please, how can I export array to CSV file directly to disk with a specific path and file name?

    Thank you Tom

    opened by tomkralik 7
  • Class 'SimpleExcel' not found

    Class 'SimpleExcel' not found

    I'm running into the same problem as mentioned by Nevega on linux.org.ru here. Namely an error "Class 'SimpleExcel' not found".

    <?php
      error_reporting (-1);
      ini_set ('display_errors', 'On');
      include_once (dirname (__FILE__) . '/../lib/SimpleExcel/SimpleExcel.php');
      $excel = new SimpleExcel ('xml');
    ?>
    

    The include works, but then the new fails.

    opened by Bert-de-Jong 4
  • Fix number datatype identification in XMLWriter

    Fix number datatype identification in XMLWriter

    When converting CSV to XML, XMLWriter doesn't recognize numeric values properly. Instead, everything gets cast to string.

    The problem seems to be in the wrong order of calling is_string and is_numeric. To my understanding, the present, wrong order works in no circumstances.

    This pull request inverts the order and thus fixes the problem.

    opened by firoxer 3
  • Autoloader is now a easily unregisterable function

    Autoloader is now a easily unregisterable function

    Closures can't be unregistered easily: AFAIK you must unregister all autoloading functions and then add back those that you didn't want to exclude in the first place.

    This commit will allow you to unregister the autoloader instance created by this package by simply doing:

    spl_autoload_unregister(array('SimpleExcel\SimpleExcel', 'autoLoader'));

    opened by unreal4u 3
  • Develop

    Develop

    Added method removeColumn() to worksheet class. Had to create this to remove column of a worksheet that caused processing of the worksheet laborious.

    Side note: first ever pull request. Please let me know if I did this correctly.

    opened by KariTrace 3
  • bug abstract method

    bug abstract method

    I tried to use the library but got error trying to use the example code

    Fatal error: Class SimpleExcel\Writer\XMLWriter contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (SimpleExcel\Writer\IWriter::saveFile) in D:\htdocs\libraries\SimpleExcel\Writer\XMLWriter.php on line 154

    bug 
    opened by ghost 3
  • Non-Excel XML to Excel?

    Non-Excel XML to Excel?

    Hello. I try to use SimpleExcel for parsing and convert non-Excel XML file. When I try to do it I get that error: "Document namespace isn't a valid Excel XML 2003 Spreadsheet".

    Can I use SimpleExcel for create .xls documents from non Excel XML? Thanks.

    opened by skazhikadyadya 2
  • Catch libxml errors & fixed minor errors

    Catch libxml errors & fixed minor errors

    • Catch libxml errors in XMLParser::loadString
    • PHPDoc block fixes
    • Fixed too late fclose in BaseParser::checkFile
    • Manually merged changes from #31 by @unreal4u
    • Fixed SimpleExcel::loadString
    • Added tests for PHP 5.5 - 5.6
    • XLSXParser must implement loadString
    • Fixed HTMLParser::loadString
    opened by sergeyklay 1
  • Incompatible with PHP 5.4

    Incompatible with PHP 5.4

    In php 5.4 Call-time pass-by-reference has been removed meaning that you need to put the & in the function definition and not in the function call.

    opened by garethlees 1
  • Bugfixes

    Bugfixes

    Hello,

    i made several fixes to your library including:

    • adding autoloader to composer
    • fixed bug where you use local insted of instance variable
    • fixed wront filetype check
    • added return values after parsing XML

    Cheers, Moritz

    opened by McRip 1
  • CSV export broken

    CSV export broken

    Hey Dude,

    if I try to export a csv, I get the following warnings:

    Warning: fputcsv() expects parameter 1 to be resource, string given in /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/CSVWriter.php on line 45

    Call Stack: 0.0002 640496 1. {main}() /home/cbrauckmann/web/www/excel_export/index.php:0 0.0022 864288 2. SimpleExcel\Writer\BaseWriter->saveFile() /home/cbrauckmann/web/www/excel_export/index.php:23 0.0023 866080 3. SimpleExcel\Writer\CSVWriter->saveString() /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/BaseWriter.php:95 0.0023 866296 4. fputcsv() /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/CSVWriter.php:45

    Warning: fputcsv() expects parameter 1 to be resource, string given in /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/CSVWriter.php on line 45

    Call Stack: 0.0002 640496 1. {main}() /home/cbrauckmann/web/www/excel_export/index.php:0 0.0022 864288 2. SimpleExcel\Writer\BaseWriter->saveFile() /home/cbrauckmann/web/www/excel_export/index.php:23 0.0023 866080 3. SimpleExcel\Writer\CSVWriter->saveString() /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/BaseWriter.php:95 0.0025 866296 4. fputcsv() /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/CSVWriter.php:45

    Warning: fputcsv() expects parameter 1 to be resource, string given in /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/CSVWriter.php on line 45

    Call Stack: 0.0002 640496 1. {main}() /home/cbrauckmann/web/www/excel_export/index.php:0 0.0022 864288 2. SimpleExcel\Writer\BaseWriter->saveFile() /home/cbrauckmann/web/www/excel_export/index.php:23 0.0023 866080 3. SimpleExcel\Writer\CSVWriter->saveString() /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/BaseWriter.php:95 0.0026 866296 4. fputcsv() /home/cbrauckmann/web/www/excel_export/src/SimpleExcel/Writer/CSVWriter.php:45

    bug 
    opened by derbronko 1
  • Problem with JSON convert

    Problem with JSON convert

    Is there some option to show the empty fields in JSON string as empty string. The problem is that $excel->toString('JSON') skip the empty fields and if I try to get the content of column X, the content type doesn't match with other rows column X content.

    For example

    image

    The output array is:

    array(3) { [0]=> string(?) "Title" [1]=> string(?) "Quantity" [2]=> string(?) "Price" } array(3) { [0]=> string(?) "BMW" [1]=> string(?) "5" [2]=> string(?) "$192.000" } array(2) { [0]=> string(?) "Mercedes" [1]=> string(?) "$204.000" } array(3) { [0]=> string(?) "Audi" [1]=> string(?) "10" [2]=> string(?) "$150.000" }

    So, when I'm trying to get all quantites result is:

    5, $204.000, 10

    opened by PYovchevski 1
  • Bug: new line after closing php tag.

    Bug: new line after closing php tag.

    Please remove all the php closing tags in your files, because it write a new line to the output unnecessary.

    For example: XMLWriter.php line 147

    I am using v.0.3

    Thank you, and keep up the good work, your project is awesome. I did not found any openxml parser what is work fast like this.

    opened by vaso123 0
  • can't use any parsing methods after setData

    can't use any parsing methods after setData

    When you you getData() on an instance, manipulate the data in php, then write it back into the instance using setData(), any parsing such as getRow() will affect the original file that was loaded and not the modified data that was set. Any writing options do write the data from setData(). Is there anyway to make the result of setData visible to the parsing engine?

    opened by mmelon 0
  • how to do if a cell has a long content and including newline ?

    how to do if a cell has a long content and including newline ?

    i have a sheet(csv), and some cells gets a long contents, including one/two newline, and i tried to parse the sheet with SimpleExcel, but found i can't get all contents of the cell, only the contents of the first line(before \n).

    how to do with it ?

    opened by huang-sheng 1
Owner
Faisal Salman
Software Developer @faisalman
Faisal Salman
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

Spout Spout is a PHP library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way. Contrary to other file readers or wr

Box 4.2k Jan 6, 2023
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

OpenSpout OpenSpout is a community driven fork of box/spout, a PHP library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scal

null 239 Jan 6, 2023
You can convert any table to CSV/EXCEL file.

Convert MySQL to EXCEL You can convert any table to CSV/EXCEL file by this code. In this repository I've used Link1 and Link2 . Simply edit config.php

Arsalan 1 Dec 25, 2021
Parse and retrieve data from old format Excel XLS files. MS Excel 97 workbooks PHP reader.

SimpleXLS class 0.9.15 Parse and retrieve data from old Excel .XLS files. MS Excel 97-2003 workbooks PHP reader. PHP BIFF reader. No additional extens

Sergey Shuchkin 160 Jan 6, 2023
Merge Excel Files to single excel file per columns

Merge Excel Files to single excel file per columns

Max Base 3 Apr 26, 2021
A pure PHP library for reading and writing spreadsheet files

PhpSpreadsheet PhpSpreadsheet is a library written in pure PHP and offers a set of classes that allow you to read and write various spreadsheet file f

PHPOffice 11.8k Jan 8, 2023
Simple yet powerful Excel manipulation library for PHP 5.4+

| | \ / \_/ __ /^\ __ ' `. \_/ ,' ` \/ \/ _,--./| |\.--._ _,' _.-\_/-._ `._ | / \ | |

Wisembly 68 Sep 20, 2022
an excel export/import tool for laravel based on php-xlswriter

Laravel-xlswriter 一款基于xlswriter的laravel扩展包 php-xlswriter是一款高性能的excel读写扩展,laravel-xlswriter基于该扩展做了封装,旨在提供一个便于使用的xlswriter的laravel工具包。 目前laravel-xlswrit

lysice 54 Dec 3, 2022
ExcelAnt - Simple yet powerful Excel manipulation library for PHP 5.4+

ExcelAnt is an Excel manipulation library for PHP 5.4. It currently works on top of PHPExcel. If you want to add / use another library, feel free to fork and contribute !

Wisembly 68 Sep 20, 2022
🚀 Supercharged Excel exports and imports in Laravel

Supercharged Excel exports and imports A simple, but elegant Laravel wrapper around PhpSpreadsheet exports and imports. Quickstart · Documentation · V

Maatwebsite 11.2k Jan 4, 2023
🦉 Fast Excel import/export for Laravel

Fast Excel import/export for Laravel, thanks to Spout. See benchmarks below. Quick start Install via composer: composer require rap2hpoutre/fast-excel

Raphaël Huchet 1.7k Jan 8, 2023
Laravel Excel Export & Import example

Laravel Excel Export & Import example It's pretty easy to export to Excel and import from Excel, with great Laravel Excel package. This package superc

Syed Arsalan Ahmed 1 Oct 26, 2021
Data import to excel without any package

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Dilshodbek 2 May 30, 2022
PHPExcelFormatter is class to make getting data from Excel documents simpler.

PHPExcelFormatter PHPExcelFormatter is class to make getting data from Excel documents simpler. Read columns what you really need Set column names for

Rene Korss 4 Apr 28, 2022
CSV data manipulation made easy in PHP

CSV Csv is a simple library to ease CSV parsing, writing and filtering in PHP. The goal of the library is to be powerful while remaining lightweight,

The League of Extraordinary Packages 3k Jan 1, 2023
CSV files from Eloquent model in seconds - a Laravel package.

LaraCSV A Laravel package to easily generate CSV files from Eloquent model. Basic usage $users = User::get(); // All users $csvExporter = new \Laracsv

Muhammad Usman 604 Dec 16, 2022
A pure PHP library for reading and writing word processing documents

Master: Develop: PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. Th

PHPOffice 6.5k Jan 7, 2023
A pure PHP library for reading and writing presentations documents

Branch Master : Branch Develop : PHPPresentation is a library written in pure PHP that provides a set of classes to write to different presentation fi

PHPOffice 1.2k Jan 2, 2023
A pure PHP library for reading and writing project management files

PHPProject PHPProject is a library written in pure PHP that provides a set of classes to write to different project management file formats, i.e. Micr

PHPOffice 192 Dec 17, 2022