Skip to content

Commit

Permalink
Merge pull request #1 from Sonichaos360/develop
Browse files Browse the repository at this point in the history
Multiples improvements and new functions
  • Loading branch information
Sonichaos360 authored Jun 28, 2021
2 parents dea19bd + 09853c0 commit 4d1eaa3
Show file tree
Hide file tree
Showing 14 changed files with 493 additions and 285 deletions.
148 changes: 77 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>

<p align="center">
Simple but powerful PHP library to generate on-disk XLSX spreadsheets in focused in low memory usage.
Simple but powerful PHP library to generate on-disk XLSX spreadsheets focused in low memory usage.
</p>

## Usage
Expand All @@ -19,50 +19,58 @@ $xls = new Sonichaos360\PHPSimpleSpreadsheet\PHPSimpleSpreadsheet();

$xls
//Sheet Name
->setName('test')
->setName('test')
//Author Name
->setAuthor('Luciano Joan Vergara')
->setAuthor('Luciano Vergara')
//Set Columns range
->setRange(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']);
->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;

//Add data with insertRow using predefined array range
while($count <= 10)
{
//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 <= 10) {
//Set row data
$xls->insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA']);

if($count == 5) {
$xls->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 rows ON your sheet and PHP can't zip the files because of server limitations
* you can use any other program on your terminal, zip the files and rename the zipped file as NAME.xlsx
* 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'))
{
if ($xls->doXmlx('test.xlsx')) {
echo "File generated successfully. <a href=\"test.xlsx\">OPEN FILE<a>";
}
else
{
} else {
throw new Exception('There was a problem generating the Spreadsheet.');
}

```

### Advanced Paginated Spreadsheet (Lots of rows)
```php
/**
* Require Class
*/
require('../../src/PHPSimpleSpreadsheet.php');

/**
Expand All @@ -71,56 +79,62 @@ require('../../src/PHPSimpleSpreadsheet.php');
$xls = new Sonichaos360\PHPSimpleSpreadsheet\PHPSimpleSpreadsheet();

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

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

/**
* Request pointer parameter and calculate current page number
* 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"]);
$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)
{
/**
* Pay attention to sheet name, this is the id to continue the sheet
*/
$xls
->setName('test')
->setAuthor('Luciano Vergara')
if ($pointer == $elements) {
/**
* Start class
*/
$xls
->setName('test')
->setAuthor('Luciano Vergara')
->setRange(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
->startSheet();
}
else
{
/**
* On every reload you should use exact same sheet name as parameter to continue,
* in this case "test" is the name we defined before
*/
$xls->continueSheet("test");
} 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;

//Add data with insertRow using predefined array range
while($count <= $elements)
//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 <= $elements) {
/**
* Here you can do your querys or something like that to
* obtain the data using LIMIT clauses or similar indicating
* the $pointer variable as LIMIT and set data to ROW
* obtain the data using LIMIT clauses or similar indicating
* the $pointer variable as LIMIT and set data to the ROW
*/

//Set row data
Expand All @@ -131,45 +145,37 @@ while($count <= $elements)
}

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

?>
<strong><?php echo $pointer; ?> OF <?php echo $total_elements; ?> ELEMENTS PROCESSED...</strong>
if ($pointer < $total_elements) {
$xls->pauseSheet(); ?>
<strong><?php echo $pointer; ?> OUT OF <?php echo $total_elements; ?> ELEMENTS PROCESSED...</strong>
<script>
/**
* In JS just reload page and increase counter
*/
setTimeout(function(){
window.location.href = 'paginated.php?pointer=<?php echo ($pointer+$elements); ?>';
window.location.href = 'paginated.php?pointer=<?php echo($pointer+$elements); ?>';
}, 3000);
</script>
<?php
}
else
{
/**
* End Sheet
*/
$xls->endSheet();

/*
* Save file (ZIP TO XLSX) if there are so many rows ON your sheet and PHP can't zip the files because of server limitations
* you can use any other program on your terminal, zip the files and rename the zipped file as NAME.xlsx
* That's all
*/
if($xls->doXmlx('test.xlsx'))
{
echo "File generated successfully. <a href=\"test.xlsx\">OPEN FILE<a>";
}
else
{
throw new Exception('There was a problem generating the Spreadsheet.');
}
} else {
/**
* End Sheet
*/
$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. <a href=\"test.xlsx\">OPEN FILE<a>";
} else {
throw new Exception('There was a problem generating the Spreadsheet.');
}
}
```

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sonichaos360/phpsimplespreadsheet",
"description": "Very simple and powerful tool for generate XLSX spreadsheets in PHP with low memory usage.",
"description": "Simple but powerful PHP library to generate on-disk XLSX spreadsheets focused in low memory usage.",
"require": {
"php": "^5.3.3"
"php": ">=5.6"
}
}
52 changes: 39 additions & 13 deletions examples/SimpleSheet/simplesheet.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,58 @@
<?php
/**
* This file is part of Sonichaos360/PHPSimpleSpreadsheet
*
* Sonichaos360/PHPSimpleSpreadsheet is open source software: you can
* distribute it and/or modify it under the terms of the MIT License
* (the "License"). You may not use this file except in
* compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* @copyright Copyright (c) Luciano Vergara <[email protected]>
* @license https://opensource.org/licenses/MIT MIT License
*/

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

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

$xls
//Sheet Name
->setName('test')
->setName('test')
//Author Name
->setAuthor('Luciano Vergara')
->setAuthor('Luciano Vergara')
//Set Columns range
->setRange(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']);
->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 <= 10)
{
while ($count <= 10) {
//Set row data
$xls->insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA']);

if($count == 5) {
$xls->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++;
}
Expand All @@ -32,15 +61,12 @@
$xls->endSheet();

/*
* Save file (ZIP TO XLSX) if there are so many regs ON your sheet and PHP can't zip the files
* 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'))
{
if ($xls->doXmlx('test.xlsx')) {
echo "File generated successfully. <a href=\"test.xlsx\">OPEN FILE<a>";
}
else
{
} else {
throw new Exception('There was a problem generating the Spreadsheet.');
}
Loading

0 comments on commit 4d1eaa3

Please sign in to comment.