2017 © Pedro Peláez
 

library spreadsheet

Spreadsheet reader library for Excel, OpenOffice and structured text files, compatible with cakephp3

image

elton182/spreadsheet

Spreadsheet reader library for Excel, OpenOffice and structured text files, compatible with cakephp3

  • Tuesday, January 26, 2016
  • by elton182
  • Repository
  • 3 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 292 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

This is a fork from (https://github.com/nuovo/spreadsheet-reader). I made this fork so i could make it compatible with cakephp3 and psr-4., (*1)

spreadsheet-reader is a PHP spreadsheet reader that differs from others in that the main goal for it was efficient data extraction that could handle large (as in really large) files. So far it may not definitely be CPU, time or I/O-efficient but at least it won't run out of memory (except maybe for XLS files)., (*2)

So far XLSX, ODS and text/CSV file parsing should be memory-efficient. XLS file parsing is done with php-excel-reader from http://code.google.com/p/php-excel-reader/ which, sadly, has memory issues with bigger spreadsheets, as it reads the data all at once and keeps it all in memory., (*3)

Requirements:

  • PHP 5.3.0 or newer
  • PHP must have Zip file support (see http://php.net/manual/en/zip.installation.php)

Usage on Cakephp Controller:

<?php
    namespace App\Controller;

    use App\Controller\AppController;
    use elton182\spreadsheet\SpreadsheetReader;

    class ExcelController extends AppController
    {


        public function index(){

            if($this->request->is('post')){

                $arquivo = $this->request->data['uploadfile'][0]['tmp_name'];
                $nome = $this->request->data['uploadfile'][0]['name'];

                $Reader = new SpreadsheetReader($arquivo,$nome);
                foreach ($Reader as $Row)
                {
                    print_r($Row);
                }

            }


        }
    }
?>

Usage:

All data is read from the file sequentially, with each row being returned as a numeric array. This is about the easiest way to read a file:, (*4)

<?php
    // If you need to parse XLS files, include php-excel-reader
    require('php-excel-reader/excel_reader2.php');

    require('SpreadsheetReader.php');

    $Reader = new SpreadsheetReader('example.xlsx');
    foreach ($Reader as $Row)
    {
        print_r($Row);
    }
?>

However, now also multiple sheet reading is supported for file formats where it is possible. (In case of CSV, it is handled as if it only has one sheet.), (*5)

You can retrieve information about sheets contained in the file by calling the Sheets() method which returns an array with sheet indexes as keys and sheet names as values. Then you can change the sheet that's currently being read by passing that index to the ChangeSheet($Index) method., (*6)

Example:, (*7)

<?php
    $Reader = new SpreadsheetReader('example.xlsx');
    $Sheets = $Reader -> Sheets();

    foreach ($Sheets as $Index => $Name)
    {
        echo 'Sheet #'.$Index.': '.$Name;

        $Reader -> ChangeSheet($Index);

        foreach ($Reader as $Row)
        {
            print_r($Row);
        }
    }
?>

If a sheet is changed to the same that is currently open, the position in the file still reverts to the beginning, so as to conform to the same behavior as when changed to a different sheet., (*8)

Testing

From the command line:, (*9)

php test.php path-to-spreadsheet.xls

In the browser:, (*10)

http://path-to-library/test.php?File=/path/to/spreadsheet.xls

Licensing

All of the code in this library is licensed under the MIT license as included in the LICENSE file, however, for now the library relies on php-excel-reader library for XLS file parsing which is licensed under the PHP license., (*11)

The Versions

26/01 2016

dev-master

9999999-dev https://github.com/elton182/spreadsheet-reader

Spreadsheet reader library for Excel, OpenOffice and structured text files, compatible with cakephp3

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-zip *

 

csv excel xls spreadsheet xlsx ods openoffice

30/04 2015

0.5.11

0.5.11.0 https://github.com/nuovo/spreadsheet-reader

Spreadsheet reader library for Excel, OpenOffice and structured text files

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-zip *

 

csv excel xls spreadsheet xlsx ods openoffice

04/09 2013

dev-0.6.0-pre-alpha

dev-0.6.0-pre-alpha https://github.com/nuovo/spreadsheet-reader

Spreadsheet reader library for Excel, OpenOffice and structured text files

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-zip *

 

csv excel xls spreadsheet xlsx ods openoffice