dmoen / super-simple-excel
Package for creating a simple Excel file from arrays
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:libary
Requires
- phpoffice/phpexcel: ^1.8
Requires (Dev)
- illuminate/support: ^5.5
- laravel/framework: ^5.5
- phpunit/phpunit: ^6.3
This package is not auto-updated.
Last update: 2024-05-14 17:57:36 UTC
README
Simple package for creating an Excel file from arrays, traversable objects or Eloquent Collections when you dont need advanced configuration on cell level.
Installation
This package can be installed via Composer:
composer require dmoen/super-simple-excel
Usage
Basic example
$writer = ExcelWriter::create() ->setHeadings(["Lorem", "Ipsum", "Sit", "Amet"]); $writer->addContent(["Row1", "Row1", "Row1", "Row1"]); $writer->addContent(["Row2", "Row2", "Row2", "Row2"]) ->save("filepath");
Also work with Eloquent Collections
$writer = ExcelWriter::create() ->setHeadings(["Lorem", "Ipsum", "Sit", "Amet"]); ->addContent(App\User::all()) ->save("filepath");
If you want to output the file to the browser:
$writer = ExcelWriter::create() ->setHeadings(["Lorem", "Ipsum", "Sit", "Amet"]); $writer->addContent(["Row1", "Row1", "Row1", "Row1"]); $writer->addContent(["Row2", "Row2", "Row2", "Row2"]) ->output("filename");
Multi dimensional array
ExcelWriter::create() ->setHeadings(["Lorem", "Ipsum", "Sit", "Amet"]); ->addContent([ ["Row1", "Row1", "Row1", "Row1"], ["Row2", "Row2", "Row2", "Row2"] ]) ->save("filepath");
Default styles can be set for font weight, font size, font type and alignment
ExcelWriter::create(["bold" => true, "font" => "Arial", "size" => 20, "align" => "center"]);
Styles can also be set for headings or specific row(s)
$writer = ExcelWriter::create(); $writer->setHeadings( ["Lorem", "Ipsum", "Sit", "Amet"], [ "align" => "right", "bold" => false, "size" => 15, "font" => "Arial" ]); $writer->addContent( [ ["Dolore", "Ipsum", "Amet", "Sit"], ["Dolore", "Ipsum", "Amet", "Sit"] ], [ "align" => "right", "bold" => false, "size" => 15, "font" => "Arial" ] );
Sometimes you want some row spaces between the headings and the content rows:
$writer = ExcelWriter::create(); $writer->setHeadings( ["Lorem", "Ipsum", "Sit", "Amet"], [], 1);