-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from luanfreitasdev/feature/test_spout
add box spout to generate xlsx / csv
- Loading branch information
Showing
9 changed files
with
292 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
|
||
namespace PowerComponents\LivewirePowerGrid\Services\Spout; | ||
|
||
use Box\Spout\Common\Entity\Style\CellAlignment; | ||
use Box\Spout\Common\Entity\Style\Color; | ||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; | ||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory; | ||
use PowerComponents\LivewirePowerGrid\Services\Contracts\ExportInterface; | ||
use PowerComponents\LivewirePowerGrid\Services\Export; | ||
|
||
class ExportToCsv extends Export implements ExportInterface | ||
{ | ||
|
||
public function download() | ||
{ | ||
|
||
$this->build(); | ||
|
||
return response() | ||
->download(storage_path($this->fileName . '.csv')); | ||
|
||
} | ||
|
||
public function build() | ||
{ | ||
|
||
$data = $this->prepare($this->collection, $this->columns, $this->checked_values); | ||
|
||
$writer = WriterEntityFactory::createCSVWriter(); | ||
$writer->openToFile(storage_path($this->fileName . '.csv')); | ||
|
||
$row = WriterEntityFactory::createRowFromArray($data['headers']); | ||
|
||
$writer->addRow($row); | ||
|
||
foreach ($data['rows'] as $row) { | ||
$row = WriterEntityFactory::createRowFromArray($row); | ||
$writer->addRow($row); | ||
} | ||
|
||
$writer->close(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
|
||
namespace PowerComponents\LivewirePowerGrid\Services\Spout; | ||
|
||
use Box\Spout\Common\Entity\Style\CellAlignment; | ||
use Box\Spout\Common\Entity\Style\Color; | ||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; | ||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory; | ||
use PowerComponents\LivewirePowerGrid\Services\Contracts\ExportInterface; | ||
use PowerComponents\LivewirePowerGrid\Services\Export; | ||
|
||
class ExportToXLS extends Export implements ExportInterface | ||
{ | ||
|
||
public function download() | ||
{ | ||
|
||
$this->build(); | ||
|
||
return response() | ||
->download(storage_path($this->fileName . '.xlsx')); | ||
|
||
} | ||
|
||
public function build() | ||
{ | ||
$data = $this->prepare($this->collection, $this->columns, $this->checked_values); | ||
|
||
$writer = WriterEntityFactory::createXLSXWriter(); | ||
$writer->openToFile(storage_path($this->fileName . '.xlsx')); | ||
|
||
$style = (new StyleBuilder()) | ||
->setFontBold() | ||
->setFontColor(Color::BLACK) | ||
->setShouldWrapText(false) | ||
->setCellAlignment(CellAlignment::CENTER) | ||
->setBackgroundColor('d0d3d8') | ||
->build(); | ||
|
||
$row = WriterEntityFactory::createRowFromArray($data['headers'], $style); | ||
|
||
$writer->addRow($row); | ||
|
||
foreach ($data['rows'] as $row) { | ||
$row = WriterEntityFactory::createRowFromArray($row); | ||
$writer->addRow($row); | ||
} | ||
|
||
$writer->close(); | ||
|
||
} | ||
} |
Oops, something went wrong.