PHPackages                             sonichaos360/phpsimplespreadsheet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. sonichaos360/phpsimplespreadsheet

ActiveLibrary[File &amp; Storage](/categories/file-storage)

sonichaos360/phpsimplespreadsheet
=================================

Simple but powerful PHP library to generate on-disk XLSX spreadsheets focused in low memory usage.

v1.0.1(4y ago)23PHPPHP &gt;=5.6

Since Mar 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Sonichaos360/PHPSimpleSpreadsheet)[ Packagist](https://packagist.org/packages/sonichaos360/phpsimplespreadsheet)[ RSS](/packages/sonichaos360-phpsimplespreadsheet/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (5)Used By (0)

 [![PHPSimpleSpreadsheet](https://camo.githubusercontent.com/a1099e4ce9f895017f8e2539fbcae45258587259fe6e88b10d46880d8309719f/68747470733a2f2f6c756369616e6f2e636f6d2e61722f77702d636f6e74656e742f75706c6f6164732f323032312f30362f70687073732d312e706e67)](https://camo.githubusercontent.com/a1099e4ce9f895017f8e2539fbcae45258587259fe6e88b10d46880d8309719f/68747470733a2f2f6c756369616e6f2e636f6d2e61722f77702d636f6e74656e742f75706c6f6164732f323032312f30362f70687073732d312e706e67)

Simple but powerful PHP library to generate on-disk XLSX spreadsheets focused in low memory usage.

Usage
-----

[](#usage)

### Basic Spreadsheet

[](#basic-spreadsheet)

```
require('../../src/PHPSimpleSpreadsheet.php');

$xls = new Sonichaos360\PHPSimpleSpreadsheet\PHPSimpleSpreadsheet();

$xls
//Sheet Name
->setName('test')
//Author Name
->setAuthor('Luciano Vergara')
//Set Columns range
->setRange(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
//Set Columns width
->setColumnsWidth(['25', '35', '35', '35', '35', '35', '35', '35', '35']);

//Start Sheet
$xls->startSheet();

//SetData
$count = 1;

//Set header row, style bold
$xls->insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA'], "bold");

//Increment row count
$count++;

//Add data using insertRow and pass range ordered array values
while ($count insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA'], "italic");
    } else {
        $xls->insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA']);
    }

    //Show row number on console
    $count++;
}

//Close sheet data
$xls->endSheet();

/*
* Save file (ZIP TO XLSX) if there are so many regs ON your sheet and PHP can't zip the files
* you can use any other program on your terminal, zip the files and rename the resultant file as NAME.xlsx
* That's all
*/
if ($xls->doXmlx('test.xlsx')) {
    echo "File generated successfully. OPEN FILE";
} else {
    throw new Exception('There was a problem generating the Spreadsheet.');
}
```

### Advanced Paginated Spreadsheet (Lots of rows)

[](#advanced-paginated-spreadsheet-lots-of-rows)

```
require('../../src/PHPSimpleSpreadsheet.php');

/**
 * Create object
 */
$xls = new Sonichaos360\PHPSimpleSpreadsheet\PHPSimpleSpreadsheet();

/**
 * Define number of elements per page
 */
$elements = 100;

/**
 * Defile total items to export
 */
$total_elements = 500;

/**
 * Get the pointer paremeter,
 * just a counter to know the current page
 * If it is NULL then we know this is the first page
 */
$pointer = (!isset($_GET["pointer"]) ? $elements : $_GET["pointer"]);

/**
 * If this is the first page
 * then we should start the spreadsheet
 * Else we just continue the current spreadsheet
 */
 if ($pointer == $elements) {
     /**
      * Start class
      */
     $xls
    ->setName('test')
    ->setAuthor('Luciano Vergara')
    ->setRange(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
    ->startSheet();
 } else {
     /**
     * You shound use the sheet name as parameter to continue,
     * in this case "test" is the name we defined before
     */
     $xls->continueSheet("test");
 }

//SetData
$count = 1;

//Set header row, style bold
if($pointer == $elements)
{
    $xls->insertRow(['A '.$pointer.' DATA', 'B '.$pointer.' DATA', 'C '.$pointer.' DATA', 'D '.$pointer.' DATA', 'E '.$pointer.' DATA', 'F '.$pointer.' DATA', 'G '.$pointer.' DATA', 'H '.$pointer.' DATA', 'I '.$pointer.' DATA'], "bold");
}

//Increment row count
$count++;

//Add data using insertRow and pass range ordered array values
while ($count insertRow(['A '.$pointer.' DATA', 'B '.$pointer.' DATA', 'C '.$pointer.' DATA', 'D '.$pointer.' DATA', 'E '.$pointer.' DATA', 'F '.$pointer.' DATA', 'G '.$pointer.' DATA', 'H '.$pointer.' DATA', 'I '.$pointer.' DATA']);

    //Show row number on console
    $count++;
}

/**
 * If we can not reach the pag limit then pause sheet
 * Else we should just end the sheet
 */
if ($pointer < $total_elements) {
    $xls->pauseSheet(); ?>
     OUT OF  ELEMENTS PROCESSED...

        /**
        * In JS just reload page and increase counter
        */
        setTimeout(function(){
            window.location.href = 'paginated.php?pointer=';
        }, 3000);
