This repository has been archived by the owner on Dec 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for WithColumnFormatting Concern
- Loading branch information
1 parent
57c3a54
commit bdf0297
Showing
5 changed files
with
158 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Nikazooz\Simplesheet\Concerns; | ||
|
||
interface WithColumnFormatting | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function columnFormats(): array; | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace Nikazooz\Simplesheet\Helpers; | ||
|
||
class NumberFormat | ||
{ | ||
const FORMAT_GENERAL = 'General'; | ||
|
||
const FORMAT_TEXT = '@'; | ||
|
||
const FORMAT_NUMBER = '0'; | ||
const FORMAT_NUMBER_00 = '0.00'; | ||
const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00'; | ||
const FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_-'; | ||
|
||
const FORMAT_PERCENTAGE = '0%'; | ||
const FORMAT_PERCENTAGE_00 = '0.00%'; | ||
|
||
const FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd'; | ||
const FORMAT_DATE_YYYYMMDD = 'yyyy-mm-dd'; | ||
const FORMAT_DATE_DDMMYYYY = 'dd/mm/yyyy'; | ||
const FORMAT_DATE_DMYSLASH = 'd/m/yy'; | ||
const FORMAT_DATE_DMYMINUS = 'd-m-yy'; | ||
const FORMAT_DATE_DMMINUS = 'd-m'; | ||
const FORMAT_DATE_MYMINUS = 'm-yy'; | ||
const FORMAT_DATE_XLSX14 = 'mm-dd-yy'; | ||
const FORMAT_DATE_XLSX15 = 'd-mmm-yy'; | ||
const FORMAT_DATE_XLSX16 = 'd-mmm'; | ||
const FORMAT_DATE_XLSX17 = 'mmm-yy'; | ||
const FORMAT_DATE_XLSX22 = 'm/d/yy h:mm'; | ||
const FORMAT_DATE_DATETIME = 'd/m/yy h:mm'; | ||
const FORMAT_DATE_TIME1 = 'h:mm AM/PM'; | ||
const FORMAT_DATE_TIME2 = 'h:mm:ss AM/PM'; | ||
const FORMAT_DATE_TIME3 = 'h:mm'; | ||
const FORMAT_DATE_TIME4 = 'h:mm:ss'; | ||
const FORMAT_DATE_TIME5 = 'mm:ss'; | ||
const FORMAT_DATE_TIME6 = 'h:mm:ss'; | ||
const FORMAT_DATE_TIME7 = 'i:s.S'; | ||
const FORMAT_DATE_TIME8 = 'h:mm:ss;@'; | ||
const FORMAT_DATE_YYYYMMDDSLASH = 'yyyy/mm/dd;@'; | ||
|
||
const FORMAT_CURRENCY_USD_SIMPLE = '$#,##0.00_-'; | ||
const FORMAT_CURRENCY_USD = '$#,##0_-'; | ||
const FORMAT_CURRENCY_EUR_SIMPLE = '#,##0.00_-€'; | ||
const FORMAT_CURRENCY_EUR = '#,##0_-€'; | ||
const FORMAT_ACCOUNTING_USD = '_($* #,##0.00_);_($* \(#,##0.00\);_($* -??_);_(@_)'; | ||
const FORMAT_ACCOUNTING_EUR = '_(€* #,##0.00_);_(€* \(#,##0.00\);_(€* -??_);_(@_)'; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Nikazooz\Simplesheet\Tests\Concerns; | ||
|
||
use Box\Spout\Common\Entity\Cell; | ||
use Nikazooz\Simplesheet\Helpers\NumberFormat; | ||
use Nikazooz\Simplesheet\Tests\Data\Stubs\WithColumnFormattingExport; | ||
use Nikazooz\Simplesheet\Tests\Data\Stubs\WithMappingExport; | ||
use Nikazooz\Simplesheet\Tests\TestCase; | ||
|
||
class WithColumnFormattingTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function can_export_with_column_formatting() | ||
{ | ||
$export = new WithColumnFormattingExport(); | ||
|
||
$response = $export->store('with-column-formatting-store.xlsx'); | ||
|
||
$this->assertTrue($response); | ||
|
||
$filePath = __DIR__.'/../Data/Disks/Local/with-column-formatting-store.xlsx'; | ||
|
||
$reader = $this->read($filePath, 'xlsx'); | ||
|
||
$sheet = $this->getSheetByIndex($reader); | ||
|
||
foreach ($sheet->getRowIterator() as $row) { | ||
/** @var Cell[] $cells */ | ||
$cells = $row->getCells(); | ||
$this->assertEquals($cells[1]->getStyle(), NumberFormat::FORMAT_NUMBER_00); | ||
} | ||
|
||
// Cleanup | ||
unlink(__DIR__.'/../Data/Disks/Local/with-column-formatting-store.xlsx'); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Nikazooz\Simplesheet\Tests\Data\Stubs; | ||
|
||
use Illuminate\Support\Collection; | ||
use Nikazooz\Simplesheet\Concerns\Exportable; | ||
use Nikazooz\Simplesheet\Concerns\FromCollection; | ||
use Nikazooz\Simplesheet\Concerns\WithColumnFormatting; | ||
use Nikazooz\Simplesheet\Concerns\WithMapping; | ||
use Nikazooz\Simplesheet\Helpers\NumberFormat; | ||
|
||
class WithColumnFormattingExport implements FromCollection, WithColumnFormatting | ||
{ | ||
use Exportable; | ||
|
||
/** | ||
* @return \Illuminate\Support\Collection | ||
*/ | ||
public function collection() | ||
{ | ||
return collect([ | ||
['A1', 'B1', 'C1'], | ||
['A2', 'B2', 'C2'], | ||
]); | ||
} | ||
|
||
public function columnFormats(): array | ||
{ | ||
return [ | ||
'B' => NumberFormat::FORMAT_NUMBER_00 | ||
]; | ||
} | ||
} |