├── tests ├── Templates │ ├── css │ │ ├── style1.css │ │ ├── style2.css │ │ └── style.css │ ├── files │ │ ├── excel.tpl │ │ ├── excel.html │ │ ├── .cache │ │ │ └── .gitignore │ │ ├── excel.blade.php │ │ └── excel.php │ ├── BladeEngineTest.php │ ├── PhpFactoryTest.php │ ├── TwigFactoryTest.php │ ├── SmartyFactoryTest.php │ ├── BladeFactoryTest.php │ ├── StylesheetExtractorTest.php │ ├── CssInlinerTest.php │ └── EngineResolverTest.php ├── Excel │ ├── Identifiers │ │ ├── files │ │ │ ├── test.csv │ │ │ ├── test.xls │ │ │ ├── test.xlsx │ │ │ └── test.htm │ │ └── PHPExcelFormatIdentifierTest.php │ ├── Readers │ │ ├── files │ │ │ └── test.xls │ │ └── ReaderFactoryTest.php │ ├── Writers │ │ ├── LeagueCsvWriterTest.php │ │ ├── PHPExcelWriterTest.php │ │ └── WriterFactoryTest.php │ ├── Workbook │ │ └── WorkbookFactoryTest.php │ ├── Html │ │ ├── HtmlToSheetConverterTest.php │ │ ├── ElementParserFactoryTest.php │ │ ├── Elements │ │ │ ├── TableElementTest.php │ │ │ ├── TrElementTest.php │ │ │ ├── ThElementTest.php │ │ │ ├── TdElementTest.php │ │ │ └── AElementTest.php │ │ ├── Attributes │ │ │ ├── HeightAttributeTest.php │ │ │ ├── WidthAttributeTest.php │ │ │ ├── StyleAttributeTest.php │ │ │ ├── AlignAttributeTest.php │ │ │ ├── ColspanAttributeTest.php │ │ │ ├── RowspanAttributeTest.php │ │ │ └── ValignAttributeTest.php │ │ └── Styles │ │ │ ├── FontSizeStyleTest.php │ │ │ ├── FontStyleStyleTest.php │ │ │ ├── FontWeightStyleTest.php │ │ │ ├── ColorStyleTest.php │ │ │ ├── WrapTextStyleTest.php │ │ │ ├── FontFamilyStyleTest.php │ │ │ ├── TextIndentStyleTest.php │ │ │ ├── TextAlignStyleTest.php │ │ │ ├── VerticalAlignStyleTest.php │ │ │ ├── BorderStyleTest.php │ │ │ ├── BorderTopStyleTest.php │ │ │ ├── BorderLeftStyleTest.php │ │ │ ├── BorderRightStyleTest.php │ │ │ ├── BorderBottomStyleTest.php │ │ │ ├── BackgroundStyleTest.php │ │ │ ├── TextDecorationStyleTest.php │ │ │ └── BackgroundColorStyleTest.php │ ├── Parsers │ │ └── PHPExcel │ │ │ ├── RowParserTest.php │ │ │ └── CellTest.php │ └── Sheets │ │ ├── LeagueCsvSheetTest.php │ │ └── PHPExcelSheetTest.php ├── Files │ ├── import │ │ └── test.xls │ ├── CsvTest.php │ ├── ExcelTest.php │ ├── Excel2007Test.php │ └── ExcelFileTestCase.php ├── ClerkTest.php ├── LedgerTest.php └── DocumentFactoryTest.php ├── banner.jpg ├── .gitignore ├── src ├── Pdf │ ├── Reader.php │ ├── Writer.php │ ├── Pages │ │ ├── HtmlText.php │ │ ├── Text.php │ │ └── Page.php │ ├── Adapters │ │ └── Snappy │ │ │ ├── Page.php │ │ │ └── Document.php │ ├── Page.php │ ├── Documents │ │ ├── Header.php │ │ ├── Footer.php │ │ └── DocumentFactory.php │ ├── Writers │ │ └── WriterFactory.php │ └── Document.php ├── Word │ ├── Reader.php │ ├── Writer.php │ ├── Pages │ │ ├── PreserveText.php │ │ ├── HtmlText.php │ │ ├── Footer.php │ │ ├── Header.php │ │ └── Text.php │ ├── Adapters │ │ └── PHPWord │ │ │ ├── Page.php │ │ │ ├── Writers │ │ │ └── Writer.php │ │ │ └── Document.php │ ├── Document.php │ ├── Documents │ │ ├── DocumentFactory.php │ │ └── Document.php │ ├── Page.php │ └── Writers │ │ └── WriterFactory.php ├── Excel │ ├── Html │ │ ├── Elements │ │ │ ├── ThElement.php │ │ │ ├── Document.php │ │ │ ├── TdElement.php │ │ │ ├── TrElement.php │ │ │ ├── AElement.php │ │ │ └── TableElement.php │ │ ├── Styles │ │ │ ├── BackgroundColorStyle.php │ │ │ ├── ColorStyle.php │ │ │ ├── TextAlignStyle.php │ │ │ ├── BackgroundStyle.php │ │ │ ├── FontSizeStyle.php │ │ │ ├── VerticalAlignStyle.php │ │ │ ├── FontFamilyStyle.php │ │ │ ├── TextIndentStyle.php │ │ │ ├── BorderLeftStyle.php │ │ │ ├── BorderTopStyle.php │ │ │ ├── BorderRightStyle.php │ │ │ ├── BorderBottomStyle.php │ │ │ ├── FontStyleStyle.php │ │ │ ├── FontWeightStyle.php │ │ │ ├── WrapTextStyle.php │ │ │ ├── TextDecorationStyle.php │ │ │ ├── Style.php │ │ │ └── BorderStyle.php │ │ ├── Attributes │ │ │ ├── RowspanAttribute.php │ │ │ ├── ColspanAttribute.php │ │ │ ├── HeightAttribute.php │ │ │ ├── WidthAttribute.php │ │ │ ├── AlignAttribute.php │ │ │ ├── ValignAttribute.php │ │ │ ├── Attribute.php │ │ │ ├── MergeCells.php │ │ │ └── StyleAttribute.php │ │ ├── ElementParserFactory.php │ │ ├── AttributeParserFactory.php │ │ ├── StyleParserFactory.php │ │ └── HtmlToSheetConverter.php │ ├── Collections │ │ ├── StyleCollection.php │ │ ├── RowCollection.php │ │ ├── SheetCollection.php │ │ ├── ExcelCollection.php │ │ └── CellCollection.php │ ├── Styles │ │ ├── Style.php │ │ └── Styleable.php │ ├── Writer.php │ ├── CsvReader.php │ ├── Adapters │ │ ├── PHPExcel │ │ │ ├── Writers │ │ │ │ ├── CsvWriter.php │ │ │ │ └── CellWriter.php │ │ │ ├── Readers │ │ │ │ ├── CsvReader.php │ │ │ │ └── Reader.php │ │ │ └── Parsers │ │ │ │ ├── HeadingParser.php │ │ │ │ ├── RowParser.php │ │ │ │ └── WorkbookParser.php │ │ ├── SpreadsheetParser │ │ │ ├── Parsers │ │ │ │ ├── RowParser.php │ │ │ │ ├── HeadingParser.php │ │ │ │ └── WorkbookParser.php │ │ │ └── Readers │ │ │ │ ├── CsvReader.php │ │ │ │ └── Reader.php │ │ └── LeagueCsv │ │ │ └── Writers │ │ │ └── CsvWriter.php │ ├── Writers │ │ ├── StyleWriter.php │ │ └── WriterFactory.php │ ├── Cell.php │ ├── Workbooks │ │ └── WorkbookFactory.php │ ├── Readers │ │ └── ReaderFactory.php │ └── Cells │ │ ├── Coordinate.php │ │ └── DataType.php ├── Writers │ └── Exportable.php ├── Exceptions │ ├── TemplateNotFoundException.php │ ├── FormatNotSupportedByDriver.php │ ├── FeatureNotSupportedException.php │ ├── ExportFailedException.php │ ├── InvalidArgumentException.php │ ├── SheetNotFoundException.php │ └── DriverNotFoundException.php ├── Drivers │ ├── Snappy.php │ ├── LeagueCsv.php │ ├── PHPWord.php │ ├── SpreadsheetParser.php │ ├── PHPExcel.php │ └── DriverInterface.php ├── Templates │ ├── Factory.php │ ├── Adapters │ │ ├── ExtensionChecker.php │ │ ├── Php │ │ │ ├── PhpFactory.php │ │ │ ├── FileFinder.php │ │ │ └── PhpEngine.php │ │ ├── Twig │ │ │ └── TwigFactory.php │ │ ├── Smarty │ │ │ └── SmartyFactory.php │ │ └── Blade │ │ │ ├── Dispatcher.php │ │ │ └── BladeEngine.php │ ├── Css │ │ ├── CssFactoryDecorator.php │ │ ├── CssInliner.php │ │ └── StylesheetExtractor.php │ └── TemplateFactory.php ├── Clerk.php ├── Traits │ └── CallableTrait.php ├── Files │ ├── Csv.php │ ├── Word2007.php │ ├── Excel2007.php │ ├── File.php │ └── Word.php ├── Adapter.php ├── Document.php └── DocumentFactory.php ├── .travis.yml ├── phpunit.xml ├── README.md ├── .php_cs └── composer.json /tests/Templates/css/style1.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/Templates/css/style2.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/Excel/Identifiers/files/test.csv: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/Templates/files/excel.tpl: -------------------------------------------------------------------------------- 1 |

{$name}

-------------------------------------------------------------------------------- /tests/Templates/files/excel.html: -------------------------------------------------------------------------------- 1 |

{{ name }}

-------------------------------------------------------------------------------- /tests/Templates/files/.cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /tests/Templates/css/style.css: -------------------------------------------------------------------------------- 1 | table { background: #000000; } -------------------------------------------------------------------------------- /tests/Templates/files/excel.blade.php: -------------------------------------------------------------------------------- 1 |

{{ $name }}

2 | -------------------------------------------------------------------------------- /tests/Templates/files/excel.php: -------------------------------------------------------------------------------- 1 |

2 | -------------------------------------------------------------------------------- /banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpartnerNL/Clerk/HEAD/banner.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | .php_cs.cache 6 | -------------------------------------------------------------------------------- /src/Pdf/Reader.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Maatwebsite\Clerk\Files\Csv', $clerk->write('csv', 'name')->getFile()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Drivers/Snappy.php: -------------------------------------------------------------------------------- 1 | [ 13 | 'pdf' => true 14 | ] 15 | ]; 16 | } 17 | -------------------------------------------------------------------------------- /src/Excel/Styles/Style.php: -------------------------------------------------------------------------------- 1 | [ 13 | 'csv' => true 14 | ], 15 | 'writer' => [ 16 | 'csv' => true 17 | ] 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /src/Templates/Factory.php: -------------------------------------------------------------------------------- 1 | addText($text); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Excel/Html/Elements/Document.php: -------------------------------------------------------------------------------- 1 | next($node, $table); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Clerk.php: -------------------------------------------------------------------------------- 1 | getColumn() . ($table->getRow() + ($attribute->value - 1)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Drivers/PHPWord.php: -------------------------------------------------------------------------------- 1 | [ 13 | 'word2003' => true, 14 | 'word2007' => true 15 | ], 16 | 'writer' => [ 17 | 'word2003' => true, 18 | 'word2007' => true 19 | ] 20 | ]; 21 | } 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - hhvm 8 | 9 | install: 10 | - travis_retry composer self-update 11 | - travis_retry composer install --no-interaction --prefer-source 12 | 13 | script: phpunit --coverage-clover=coverage.clover 14 | 15 | after_script: 16 | - wget https://scrutinizer-ci.com/ocular.phar 17 | - php ocular.phar code-coverage:upload --format=php-clover coverage.clover 18 | 19 | matrix: 20 | allow_failures: 21 | - php: hhvm 22 | fast_finish: true -------------------------------------------------------------------------------- /src/Drivers/SpreadsheetParser.php: -------------------------------------------------------------------------------- 1 | [ 13 | 'excel2007' => true, 14 | 'csv' => true 15 | ], 16 | 'writer' => [ 17 | 'excel2007' => true, 18 | 'csv' => true 19 | ] 20 | ]; 21 | } 22 | -------------------------------------------------------------------------------- /src/Excel/CsvReader.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Illuminate\Contracts\View\Factory', $engine->getFactory()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/ColorStyle.php: -------------------------------------------------------------------------------- 1 | font()->color($value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/TextAlignStyle.php: -------------------------------------------------------------------------------- 1 | align($value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/BackgroundStyle.php: -------------------------------------------------------------------------------- 1 | fill($value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/FontSizeStyle.php: -------------------------------------------------------------------------------- 1 | font()->size($value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/VerticalAlignStyle.php: -------------------------------------------------------------------------------- 1 | valign($value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Traits/CallableTrait.php: -------------------------------------------------------------------------------- 1 | font()->family($value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/TextIndentStyle.php: -------------------------------------------------------------------------------- 1 | align()->indent($value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Word/Adapters/PHPWord/Page.php: -------------------------------------------------------------------------------- 1 | addText($text); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Excel/Html/Elements/TdElement.php: -------------------------------------------------------------------------------- 1 | next($node, $table); 19 | 20 | $this->flush($table); 21 | 22 | $table->nextColumn(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Drivers/PHPExcel.php: -------------------------------------------------------------------------------- 1 | [ 13 | 'excel2003' => true, 14 | 'excel2007' => true, 15 | 'csv' => true 16 | ], 17 | 'writer' => [ 18 | 'excel2003' => true, 19 | 'excel2007' => true, 20 | 'csv' => true 21 | ] 22 | ]; 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Attributes/ColspanAttribute.php: -------------------------------------------------------------------------------- 1 | nextColumn($attribute->value - 1); 20 | 21 | // Set end cell 22 | return $table->getColumn() . $table->getRow(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Excel/Html/Attributes/HeightAttribute.php: -------------------------------------------------------------------------------- 1 | sheet->setRowHeight( 19 | $table->getRow(), 20 | $attribute->value 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Attributes/WidthAttribute.php: -------------------------------------------------------------------------------- 1 | sheet->setColumnWidth( 19 | $table->getColumn(), 20 | $attribute->value 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Files/Csv.php: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/Files/Word2007.php: -------------------------------------------------------------------------------- 1 | analyseBorder($value); 20 | 21 | $cell->borders()->left()->setColor($color)->setStyle($style); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/BorderTopStyle.php: -------------------------------------------------------------------------------- 1 | analyseBorder($value); 20 | 21 | $cell->borders()->top()->setColor($color)->setStyle($style); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Attributes/AlignAttribute.php: -------------------------------------------------------------------------------- 1 | sheet->cell($table->getCoordinate(), function (Cell $cell) use ($attribute) { 20 | $cell->align($attribute->value); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/BorderRightStyle.php: -------------------------------------------------------------------------------- 1 | analyseBorder($value); 20 | 21 | $cell->borders()->right()->setColor($color)->setStyle($style); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/BorderBottomStyle.php: -------------------------------------------------------------------------------- 1 | analyseBorder($value); 20 | 21 | $cell->borders()->bottom()->setColor($color)->setStyle($style); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Excel/Writers/LeagueCsvWriterTest.php: -------------------------------------------------------------------------------- 1 | workbook = m::mock('Maatwebsite\Clerk\Excel\Workbook'); 13 | } 14 | 15 | public function tearDown() 16 | { 17 | m::close(); 18 | } 19 | 20 | public function test_can_init() 21 | { 22 | $writer = new CsvWriter('CSV', 'csv', $this->workbook); 23 | 24 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Writer', $writer); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Excel/Html/Attributes/ValignAttribute.php: -------------------------------------------------------------------------------- 1 | sheet->cell($table->getColumn() . $table->getRow(), function (Cell $cell) use ($attribute) { 20 | $cell->valign($attribute->value); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/FontStyleStyle.php: -------------------------------------------------------------------------------- 1 | font()->italic(); 21 | } elseif ($value == 'normal') { 22 | $cell->font()->italic(false); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Excel/Html/Elements/TrElement.php: -------------------------------------------------------------------------------- 1 | nextRow(); 20 | 21 | $table->setColumn( 22 | $table->getStartColumn() 23 | ); 24 | 25 | $table->resetContent(); 26 | 27 | // Next element 28 | $this->next($node, $table); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Excel/Collections/ExcelCollection.php: -------------------------------------------------------------------------------- 1 | title; 27 | } 28 | 29 | /** 30 | * Set the title. 31 | * 32 | * @param $title 33 | */ 34 | public function setTitle($title) 35 | { 36 | $this->title = $title; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/FontWeightStyle.php: -------------------------------------------------------------------------------- 1 | = 500) { 20 | $cell->font()->bold(); 21 | } elseif ($value == 'normal' || $value < 500) { 22 | $cell->font()->bold(false); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Pdf/Page.php: -------------------------------------------------------------------------------- 1 | sheet = $sheet; 22 | } 23 | 24 | /** 25 | * @param DOMAttr $attribute 26 | * @param ReferenceTable $table 27 | * 28 | * @return mixed 29 | */ 30 | abstract public function parse(DOMAttr $attribute, ReferenceTable & $table); 31 | } 32 | -------------------------------------------------------------------------------- /tests/Templates/PhpFactoryTest.php: -------------------------------------------------------------------------------- 1 | make('excel', ['name' => 'Patrick'])->render(); 18 | $this->assertEquals('

Patrick

', trim($html)); 19 | 20 | $html = $factory->make('excel.php', ['name' => 'Patrick'])->render(); 21 | $this->assertEquals('

Patrick

', trim($html)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/WrapTextStyle.php: -------------------------------------------------------------------------------- 1 | align()->wrap($state); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/TextDecorationStyle.php: -------------------------------------------------------------------------------- 1 | font()->underline(); 22 | 23 | case 'line-through': 24 | $cell->font()->strikethrough(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/Style.php: -------------------------------------------------------------------------------- 1 | sheet = $sheet; 22 | } 23 | 24 | /** 25 | * @param Cell $cell 26 | * @param $value 27 | * @param ReferenceTable $table 28 | * 29 | * @return mixed 30 | */ 31 | abstract public function parse(Cell $cell, $value, ReferenceTable & $table); 32 | } 33 | -------------------------------------------------------------------------------- /src/Pdf/Documents/Header.php: -------------------------------------------------------------------------------- 1 | text = $text; 23 | } 24 | 25 | /** 26 | * @return Text 27 | */ 28 | public function getText() 29 | { 30 | return $this->text->getText(); 31 | } 32 | 33 | /** 34 | * @param Text $text 35 | */ 36 | public function setText(Text $text) 37 | { 38 | $this->text = $text; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Adapter.php: -------------------------------------------------------------------------------- 1 | driver; 21 | } 22 | 23 | /** 24 | * @param $method 25 | * @param $params 26 | * 27 | * @return mixed 28 | */ 29 | public function __call($method, $params) 30 | { 31 | if (method_exists($this->getDriver(), $method)) { 32 | return call_user_func_array([$this->getDriver(), $method], $params); 33 | } 34 | 35 | throw new \BadMethodCallException("Method [{$method}] not found on Reader"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Excel/Html/ElementParserFactory.php: -------------------------------------------------------------------------------- 1 | make('excel', ['name' => 'Patrick'])->render(); 19 | $this->assertEquals('

Patrick

', $html); 20 | 21 | $html = $factory->make('excel.html', ['name' => 'Patrick'])->render(); 22 | $this->assertEquals('

Patrick

', $html); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Templates/Adapters/ExtensionChecker.php: -------------------------------------------------------------------------------- 1 | hasExtension($file)) { 20 | return $file; 21 | } else { 22 | // Append the extension 23 | return rtrim($file, '.') . '.' . $this->extension; 24 | } 25 | } 26 | 27 | /** 28 | * @param $file 29 | * 30 | * @return bool 31 | */ 32 | protected function hasExtension($file) 33 | { 34 | return pathinfo($file, PATHINFO_EXTENSION); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Excel/Workbook/WorkbookFactoryTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Maatwebsite\Clerk\Excel\Workbook', WorkbookFactory::create(new PHPExcel('drivers.writer.excel2003'), 'title')); 12 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Workbook', WorkbookFactory::create(new PHPExcel('drivers.writer.excel2003'), 'title')); 13 | 14 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\LeagueCsv\Workbook', WorkbookFactory::create(new LeagueCsv('drivers.writer.csv'), 'title')); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/Excel/Html/HtmlToSheetConverterTest.php: -------------------------------------------------------------------------------- 1 | convert('
Patrick
', $this->mockSheet()); 17 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Sheet', $sheet); 18 | } 19 | 20 | public function mockSheet() 21 | { 22 | $sheet = \Mockery::mock('Maatwebsite\Clerk\Excel\Sheet')->makePartial(); 23 | $sheet->shouldReceive('cell')->with('A1', 'Patrick')->once(); 24 | 25 | return $sheet; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Word/Pages/HtmlText.php: -------------------------------------------------------------------------------- 1 | text = $text; 19 | $this->fullHtml = $fullHtml; 20 | } 21 | 22 | /** 23 | * @return bool 24 | */ 25 | public function isFullHtml() 26 | { 27 | return $this->fullHtml; 28 | } 29 | 30 | /** 31 | * @param bool $fullHtml 32 | * 33 | * @return $this 34 | */ 35 | public function setIsFullHtml($fullHtml = true) 36 | { 37 | $this->fullHtml = $fullHtml; 38 | 39 | return $this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Word/Pages/Footer.php: -------------------------------------------------------------------------------- 1 | text = $text; 22 | } 23 | 24 | /** 25 | * @return Text 26 | */ 27 | public function getText() 28 | { 29 | return $this->text->getText(); 30 | } 31 | 32 | /** 33 | * @return Text 34 | */ 35 | public function getRawText() 36 | { 37 | return $this->text; 38 | } 39 | 40 | /** 41 | * @param Text $text 42 | */ 43 | public function setText(Text $text) 44 | { 45 | $this->text = $text; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Word/Pages/Header.php: -------------------------------------------------------------------------------- 1 | text = $text; 22 | } 23 | 24 | /** 25 | * @return Text 26 | */ 27 | public function getText() 28 | { 29 | return $this->text->getText(); 30 | } 31 | 32 | /** 33 | * @return Text 34 | */ 35 | public function getRawText() 36 | { 37 | return $this->text; 38 | } 39 | 40 | /** 41 | * @param Text $text 42 | */ 43 | public function setText(Text $text) 44 | { 45 | $this->text = $text; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Excel/Html/AttributeParserFactory.php: -------------------------------------------------------------------------------- 1 | convertToDriver($this->getExportable()) 20 | ); 21 | 22 | if ($this->getType() == 'CSV') { 23 | $writer->setDelimiter($this->getExportable()->getDelimiter()); 24 | $writer->setEnclosure($this->getExportable()->getEnclosure()); 25 | $writer->setLineEnding($this->getExportable()->getLineEnding()); 26 | } 27 | 28 | return $writer; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/LedgerTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('PHPExcel', Ledger::getInstance()->getConfig('drivers.reader.excel2003')); 10 | $this->assertEquals('PHPExcel', Ledger::get('drivers.reader.excel2003')); 11 | } 12 | 13 | public function test_set() 14 | { 15 | Ledger::set('drivers.reader.excel2003', 'TEST'); 16 | $this->assertEquals('TEST', Ledger::get('drivers.reader.excel2003')); 17 | } 18 | 19 | public function test_default_get() 20 | { 21 | $this->assertEquals('default', Ledger::get('non-found', 'default')); 22 | } 23 | 24 | public function test_default_has() 25 | { 26 | $this->assertTrue(Ledger::has('drivers.reader.excel2003')); 27 | $this->assertFalse(Ledger::has('not-found')); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Pdf/Documents/Footer.php: -------------------------------------------------------------------------------- 1 | text = $text; 23 | } 24 | 25 | /** 26 | * @return Text 27 | */ 28 | public function getText() 29 | { 30 | return $this->text->getText(); 31 | } 32 | 33 | /** 34 | * @return Text 35 | */ 36 | public function getRawText() 37 | { 38 | return $this->text; 39 | } 40 | 41 | /** 42 | * @param Text $text 43 | */ 44 | public function setText(Text $text) 45 | { 46 | $this->text = $text; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Excel/Html/Elements/AElement.php: -------------------------------------------------------------------------------- 1 | sheet->getCell($table->getCoordinate()) 19 | ->getHyperlink() 20 | ->setUrl($node->getAttribute('href')); 21 | 22 | // Underline and make it blue 23 | $this->sheet->cell($table->getCoordinate(), function ($cell) { 24 | $cell->font()->underline()->color('0000ff'); 25 | }); 26 | 27 | // Add whitespace 28 | $table->appendContent(' '); 29 | 30 | $this->next($node, $table); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Word/Document.php: -------------------------------------------------------------------------------- 1 | make('excel', ['name' => 'Patrick'])->render(); 21 | $this->assertEquals('

Patrick

', $html); 22 | 23 | $html = $factory->make('excel.tpl', ['name' => 'Patrick'])->render(); 24 | $this->assertEquals('

Patrick

', $html); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Templates/BladeFactoryTest.php: -------------------------------------------------------------------------------- 1 | make('excel', ['name' => 'Patrick'])->render(); 19 | $this->assertEquals('

Patrick

', trim($html)); 20 | 21 | $html = $factory->make('excel.blade', ['name' => 'Patrick'])->render(); 22 | $this->assertEquals('

Patrick

', trim($html)); 23 | 24 | $html = $factory->make('excel.blade.php', ['name' => 'Patrick'])->render(); 25 | $this->assertEquals('

Patrick

', trim($html)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Document.php: -------------------------------------------------------------------------------- 1 | file = DocumentFactory::create($type, $title, $callback); 23 | } 24 | 25 | /** 26 | * @return Files\File|File 27 | */ 28 | public function getFile() 29 | { 30 | return $this->file; 31 | } 32 | 33 | /** 34 | * @param $method 35 | * @param $params 36 | */ 37 | public function __call($method, $params) 38 | { 39 | if (method_exists($this->getFile(), $method)) { 40 | call_user_func_array([$this->file, $method], $params); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Excel/Html/StyleParserFactory.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Maatwebsite\Clerk\Excel\Html\Elements\TrElement', 15 | ElementParserFactory::create('tr', $this->mockSheet())); 16 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Html\Elements\TdElement', 17 | ElementParserFactory::create('td', $this->mockSheet())); 18 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Html\Elements\ThElement', 19 | ElementParserFactory::create('th', $this->mockSheet())); 20 | } 21 | 22 | protected function mockSheet() 23 | { 24 | return \Mockery::mock('Maatwebsite\Clerk\Excel\Sheet')->makePartial(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Excel/Html/Elements/TableElementTest.php: -------------------------------------------------------------------------------- 1 | mockSheet(); 18 | 19 | $this->assertEquals(0, $table->getRow()); 20 | 21 | $element = new TableElement($sheet); 22 | $element->parse($dom, $table); 23 | 24 | $this->assertEquals(1, $table->getRow()); 25 | } 26 | 27 | /** 28 | * @return \Maatwebsite\Clerk\Sheet 29 | */ 30 | public function mockSheet() 31 | { 32 | $sheet = \Mockery::mock('Maatwebsite\Clerk\Excel\Sheet'); 33 | 34 | return $sheet; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Excel/Html/Attributes/HeightAttributeTest.php: -------------------------------------------------------------------------------- 1 | mockSheet(); 15 | 16 | $attribute = new HeightAttribute($sheet); 17 | $attribute->parse($node, $table); 18 | 19 | $this->assertEquals('20', $sheet->getDriver()->getRowDimension($table->getRow())->getRowHeight()); 20 | } 21 | 22 | /** 23 | * @return Sheet 24 | */ 25 | protected function mockSheet() 26 | { 27 | return new Sheet(new Workbook('title'), 'title'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Excel/Html/Attributes/WidthAttributeTest.php: -------------------------------------------------------------------------------- 1 | mockSheet(); 16 | 17 | $attribute = new WidthAttribute($sheet); 18 | $attribute->parse($node, $table); 19 | 20 | $this->assertEquals('20', $sheet->getDriver()->getColumnDimension($table->getColumn())->getWidth()); 21 | } 22 | 23 | /** 24 | * @return Sheet 25 | */ 26 | protected function mockSheet() 27 | { 28 | return new Sheet(new Workbook('title'), 'title'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/DocumentFactory.php: -------------------------------------------------------------------------------- 1 | factory = $factory; 20 | } 21 | 22 | /** 23 | * Make the view. 24 | * 25 | * @param string $file 26 | * @param array $data 27 | * 28 | * @return $this 29 | */ 30 | public function make($file, array $data = []) 31 | { 32 | return $this->factory->make($file, $data); 33 | } 34 | 35 | /** 36 | * Render the template. 37 | * @return string 38 | */ 39 | public function render() 40 | { 41 | return (new CssInliner())->transformCssToInlineStyles( 42 | $this->factory->render() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Excel/Html/Attributes/MergeCells.php: -------------------------------------------------------------------------------- 1 | getStartCell($table) . ':' . $this->getEndCell($attribute, $table); 19 | 20 | $this->sheet->mergeCells($range); 21 | } 22 | 23 | /** 24 | * @param $table 25 | * 26 | * @return string 27 | */ 28 | protected function getStartCell(&$table) 29 | { 30 | return $table->getColumn() . $table->getRow(); 31 | } 32 | 33 | /** 34 | * @param $attribute 35 | * @param $table 36 | * 37 | * @return string 38 | */ 39 | abstract public function getEndCell($attribute, &$table); 40 | } 41 | -------------------------------------------------------------------------------- /tests/Templates/StylesheetExtractorTest.php: -------------------------------------------------------------------------------- 1 | '; 10 | 11 | $extractor = new StylesheetExtractor($html); 12 | $result = $extractor->extract(); 13 | 14 | $this->assertCount(3, $result); 15 | } 16 | 17 | public function test_extracting_stylesheets_returns_the_css() 18 | { 19 | $html = ''; 20 | 21 | $extractor = new StylesheetExtractor($html); 22 | $result = $extractor->extract(); 23 | 24 | $this->assertEquals('table { background: #000000; }', $result[__DIR__ . '/css/' . 'style.css']); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Excel/Adapters/PHPExcel/Readers/CsvReader.php: -------------------------------------------------------------------------------- 1 | reader->setDelimiter($delimiter); 28 | 29 | return $this; 30 | } 31 | 32 | /** 33 | * Set CSV enclosure. 34 | * 35 | * @param $enclosure 36 | * 37 | * @return Reader 38 | */ 39 | public function setEnclosure($enclosure) 40 | { 41 | $this->reader->setEnclosure($enclosure); 42 | 43 | return $this; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/DocumentFactoryTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Maatwebsite\Clerk\Files\Csv', DocumentFactory::create('Csv', 'name')); 10 | } 11 | 12 | public function test_create_excel_file() 13 | { 14 | $this->assertInstanceOf('Maatwebsite\Clerk\Files\Excel', DocumentFactory::create('Excel', 'name')); 15 | } 16 | 17 | public function test_create_excel_2007_file() 18 | { 19 | $this->assertInstanceOf('Maatwebsite\Clerk\Files\Excel2007', DocumentFactory::create('Excel2007', 'name')); 20 | } 21 | 22 | public function test_create_word_file() 23 | { 24 | $this->assertInstanceOf('Maatwebsite\Clerk\Files\Word', DocumentFactory::create('Word', 'name')); 25 | } 26 | 27 | public function test_create_word_2007_file() 28 | { 29 | $this->assertInstanceOf('Maatwebsite\Clerk\Files\Word2007', DocumentFactory::create('Word2007', 'name')); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Excel/Writers/StyleWriter.php: -------------------------------------------------------------------------------- 1 | getStyleName($style); 22 | 23 | if (method_exists($this, $method)) { 24 | list($name, $value) = $this->{$method}($style); 25 | 26 | $styles[$name] = $value; 27 | } 28 | } 29 | 30 | return $styles; 31 | } 32 | 33 | /** 34 | * @param Style $style 35 | * 36 | * @return string 37 | */ 38 | protected function getStyleName(Style $style) 39 | { 40 | $reflect = new ReflectionClass($style); 41 | 42 | return $reflect->getShortName(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/FontSizeStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new FontSizeStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertEquals('16', $cell->font()->getSize()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/FontStyleStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new FontStyleStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertTrue($cell->font()->isItalic()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/FontWeightStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new FontWeightStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertTrue($cell->font()->isBold()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/ColorStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new ColorStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('333333', $cell->font()->getColor()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/WrapTextStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new WrapTextStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertTrue($cell->align()->getWrapText()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Elements/TrElementTest.php: -------------------------------------------------------------------------------- 1 | 20 | $table->setColumn( 21 | $table->setStartColumn() 22 | ); 23 | 24 | $sheet = $this->mockSheet(); 25 | 26 | $this->assertEquals(0, $table->getRow()); 27 | 28 | $element = new TrElement($sheet); 29 | $element->parse($dom, $table); 30 | 31 | $this->assertEquals(1, $table->getRow()); 32 | } 33 | 34 | /** 35 | * @return \Maatwebsite\Clerk\Sheet 36 | */ 37 | public function mockSheet() 38 | { 39 | $sheet = \Mockery::mock('Maatwebsite\Clerk\Excel\Sheet'); 40 | 41 | return $sheet; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Pdf/Documents/DocumentFactory.php: -------------------------------------------------------------------------------- 1 | getName()}] was not found"); 28 | } 29 | 30 | /** 31 | * @param DriverInterface $driver 32 | * 33 | * @return string 34 | */ 35 | protected static function getClassByType(DriverInterface $driver) 36 | { 37 | return $driver->getDocumentClass('Pdf'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Word/Documents/DocumentFactory.php: -------------------------------------------------------------------------------- 1 | getName()}] was not found"); 28 | } 29 | 30 | /** 31 | * @param DriverInterface $driver 32 | * 33 | * @return string 34 | */ 35 | protected static function getClassByType(DriverInterface $driver) 36 | { 37 | return $driver->getDocumentClass('Word'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/FontFamilyStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new FontFamilyStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('verdana', $cell->font()->getName()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/TextIndentStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new TextIndentStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertEquals('20', $cell->align()->getTextIndent()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/TextAlignStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new TextAlignStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertEquals('center', $cell->align()->getHorizontal()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Parsers/PHPExcel/RowParserTest.php: -------------------------------------------------------------------------------- 1 | parse($this->mockRow()); 14 | 15 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Collections\CellCollection', $parsed); 16 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Cell', $parsed->first()); 17 | $this->assertCount(3, $parsed); 18 | } 19 | 20 | /** 21 | * @return \PHPExcel 22 | */ 23 | protected function mockRow() 24 | { 25 | $workbook = new \PHPExcel(); 26 | $workbook->disconnectWorksheets(); 27 | $sheet = new \PHPExcel_Worksheet($workbook); 28 | $sheet->fromArray([ 29 | ['a1', 'b1', 'c1'], 30 | ]); 31 | 32 | $row = new \PHPExcel_Worksheet_Row($sheet, 1); 33 | 34 | return $row; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Excel/Html/Elements/TableElement.php: -------------------------------------------------------------------------------- 1 | flush($table); 20 | 21 | // Set column before processing table 22 | $table->setColumn( 23 | $table->setStartColumn() 24 | ); 25 | 26 | if ($table->getLevel() > 1) { 27 | $table->previousRow(); 28 | } 29 | 30 | // Parse next node 31 | $this->next($node, $table); 32 | 33 | // Set column after process the entire table 34 | $table->setColumn( 35 | $table->releaseStartColumn() 36 | ); 37 | 38 | if ($table->getLevel() > 1) { 39 | $table->nextColumn(); 40 | } else { 41 | $table->nextRow(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/VerticalAlignStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new VerticalAlignStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertEquals('center', $cell->valign()->getVertical()); 22 | } 23 | 24 | /** 25 | * @return Cell 26 | */ 27 | protected function mockCell() 28 | { 29 | return new Cell('name'); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Readers/ReaderFactoryTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Readers\Reader', ReaderFactory::create(new PHPExcel('drivers.reader.excel2003'), 'test.xls', null, 'Excel5')); 12 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Readers\Reader', ReaderFactory::create(new PHPExcel('drivers.reader.excel2007'), 'test.xlsx', null, 'Excel2007')); 13 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\LeagueCsv\Readers\CsvReader', ReaderFactory::create(new LeagueCsv('drivers.reader.csv'), 'test.csv', null, 'CSV')); 14 | } 15 | 16 | public function test_that_factory_can_guess_the_file_type() 17 | { 18 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Readers\Reader', ReaderFactory::create(new PHPExcel('drivers.reader.excel2003'), __DIR__ . '/files/test.xls')); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Templates/Adapters/Php/PhpFactory.php: -------------------------------------------------------------------------------- 1 | extension 34 | ); 35 | 36 | // Compile the template with the PhpEngine 37 | $this->results = (new PhpEngine($finder))->compile($file, $data); 38 | 39 | return $this; 40 | } 41 | 42 | /** 43 | * Render the template. 44 | * 45 | * @return string 46 | */ 47 | public function render() 48 | { 49 | return $this->results; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Excel/Cell.php: -------------------------------------------------------------------------------- 1 | getName()}] was not found"); 31 | } 32 | 33 | /** 34 | * @param DriverInterface $driver 35 | * 36 | * @return string 37 | */ 38 | protected static function getClassByType(DriverInterface $driver) 39 | { 40 | return $driver->getWorkbookClass('Excel'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/BorderStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new BorderStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('000000', $cell->border()->getColor()); 22 | $this->assertContains('thick', $cell->border()->getStyle()); 23 | } 24 | 25 | /** 26 | * @return Cell 27 | */ 28 | protected function mockCell() 29 | { 30 | return new Cell('name'); 31 | } 32 | 33 | /** 34 | * @return Sheet 35 | */ 36 | protected function mockSheet() 37 | { 38 | return new Sheet(new Workbook('title'), 'title'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Excel/Html/Styles/BorderStyle.php: -------------------------------------------------------------------------------- 1 | analyseBorder($value); 21 | 22 | $cell->border()->setColor($color)->setStyle($style); 23 | } 24 | 25 | /** 26 | * @param $value 27 | * 28 | * @return array 29 | */ 30 | protected function analyseBorder($value) 31 | { 32 | $borders = explode(' ', $value); 33 | $style = $borders[1]; 34 | $color = end($borders); 35 | 36 | // Set border style to thin 37 | if ($style == 'solid') { 38 | $style = Border::BORDER_THIN; 39 | } 40 | 41 | return [ 42 | $style, 43 | $color, 44 | ]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/Excel/Html/Attributes/StyleAttributeTest.php: -------------------------------------------------------------------------------- 1 | 15 | $table->setColumn( 16 | $table->setStartColumn() 17 | ); 18 | 19 | // Fake as if we are inside a 20 | $table->nextRow(); 21 | 22 | $node = new \DOMAttr('style', 'text-align:center;'); 23 | $sheet = $this->mockSheet(); 24 | 25 | $attribute = new StyleAttribute($sheet); 26 | $attribute->parse($node, $table); 27 | 28 | $this->assertContains('center', $sheet->cell($table->getCoordinate())->align()->getHorizontal()); 29 | } 30 | 31 | /** 32 | * @return Sheet 33 | */ 34 | protected function mockSheet() 35 | { 36 | return new Sheet(new Workbook('title'), 'title'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Templates/Css/CssInliner.php: -------------------------------------------------------------------------------- 1 | inliner = new CssToInlineStyles(); 20 | $this->inliner->setCleanup(true); 21 | $this->inliner->setUseInlineStylesBlock(true); 22 | $this->inliner->setStripOriginalStyleTags(true); 23 | } 24 | 25 | /** 26 | * @param $html 27 | * 28 | * @return string 29 | */ 30 | public function transformCssToInlineStyles($html) 31 | { 32 | $this->inliner->setHTML($html); 33 | 34 | foreach ($this->getStylesheets($html) as $css) { 35 | $this->inliner->setCSS($css); 36 | } 37 | 38 | return $this->inliner->convert(); 39 | } 40 | 41 | /** 42 | * @param $html 43 | * 44 | * @return mixed 45 | */ 46 | protected function getStylesheets($html) 47 | { 48 | return (new StylesheetExtractor($html))->extract(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/Excel/Html/Attributes/AlignAttributeTest.php: -------------------------------------------------------------------------------- 1 | 15 | $table->setColumn( 16 | $table->setStartColumn() 17 | ); 18 | 19 | // Fake as if we are inside a 20 | $table->nextRow(); 21 | 22 | $node = new \DOMAttr('align', 'center'); 23 | $sheet = $this->mockSheet(); 24 | 25 | $attribute = new AlignAttribute($sheet); 26 | $attribute->parse($node, $table); 27 | 28 | $this->assertContains('center', $sheet->cell($table->getCoordinate())->align()->getHorizontal()); 29 | } 30 | 31 | /** 32 | * @return Sheet 33 | */ 34 | protected function mockSheet() 35 | { 36 | return new Sheet(new Workbook('title'), 'title'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Excel/Html/Attributes/ColspanAttributeTest.php: -------------------------------------------------------------------------------- 1 | 15 | $table->setColumn( 16 | $table->setStartColumn() 17 | ); 18 | 19 | // Fake as if we are inside a 20 | $table->nextRow(); 21 | 22 | $node = new \DOMAttr('colspan', 3); 23 | $sheet = $this->mockSheet(); 24 | 25 | $attribute = new ColspanAttribute($sheet); 26 | $attribute->parse($node, $table); 27 | 28 | // 3 columns on the first row 29 | $this->assertContains('A1:C1', $sheet->getMergeCells()); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Attributes/RowspanAttributeTest.php: -------------------------------------------------------------------------------- 1 | 15 | $table->setColumn( 16 | $table->setStartColumn() 17 | ); 18 | 19 | // Fake as if we are inside a 20 | $table->nextRow(); 21 | 22 | $node = new \DOMAttr('rowspan', 3); 23 | $sheet = $this->mockSheet(); 24 | 25 | $attribute = new RowspanAttribute($sheet); 26 | $attribute->parse($node, $table); 27 | 28 | // 3 rows in the first column 29 | $this->assertContains('A1:A3', $sheet->getMergeCells()); 30 | } 31 | 32 | /** 33 | * @return Sheet 34 | */ 35 | protected function mockSheet() 36 | { 37 | return new Sheet(new Workbook('title'), 'title'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Excel/Html/Attributes/ValignAttributeTest.php: -------------------------------------------------------------------------------- 1 | 15 | $table->setColumn( 16 | $table->setStartColumn() 17 | ); 18 | 19 | // Fake as if we are inside a 20 | $table->nextRow(); 21 | 22 | $node = new \DOMAttr('valign', 'center'); 23 | $sheet = $this->mockSheet(); 24 | 25 | $attribute = new ValignAttribute($sheet); 26 | $attribute->parse($node, $table); 27 | 28 | $this->assertContains('center', $sheet->cell($table->getCoordinate())->valign()->getVertical()); 29 | } 30 | 31 | /** 32 | * @return Sheet 33 | */ 34 | protected function mockSheet() 35 | { 36 | return new Sheet(new Workbook('title'), 'title'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Pdf/Pages/Text.php: -------------------------------------------------------------------------------- 1 | text = $text; 28 | $this->alignment = $alignment; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getText() 35 | { 36 | return $this->text; 37 | } 38 | 39 | /** 40 | * @param string $text 41 | */ 42 | public function setText($text) 43 | { 44 | $this->text = $text; 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function getAlignment() 51 | { 52 | return $this->alignment; 53 | } 54 | 55 | /** 56 | * @param string $alignment 57 | */ 58 | public function setAlignment($alignment) 59 | { 60 | $this->alignment = $alignment; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/BorderTopStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new BorderTopStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('000000', $cell->borders()->getTop()->getColor()); 22 | $this->assertContains('thick', $cell->borders()->getTop()->getStyle()); 23 | } 24 | 25 | /** 26 | * @return Cell 27 | */ 28 | protected function mockCell() 29 | { 30 | return new Cell('name'); 31 | } 32 | 33 | /** 34 | * @return Sheet 35 | */ 36 | protected function mockSheet() 37 | { 38 | return new Sheet(new Workbook('title'), 'title'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/BorderLeftStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new BorderLeftStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('000000', $cell->borders()->getLeft()->getColor()); 22 | $this->assertContains('thick', $cell->borders()->getLeft()->getStyle()); 23 | } 24 | 25 | /** 26 | * @return Cell 27 | */ 28 | protected function mockCell() 29 | { 30 | return new Cell('name'); 31 | } 32 | 33 | /** 34 | * @return Sheet 35 | */ 36 | protected function mockSheet() 37 | { 38 | return new Sheet(new Workbook('title'), 'title'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Maatwebsite Clerk 2 | 3 | **Are you struggling getting all those document readers and writers working in your project? Meet Clerk! Clerk offers you a quick and easy way to import, export and convert file types like Excel, CSV, Word and PDF, with the help of powerful packages like PhpExcel, PhpWord, LeagueCsv, Dompdf, Carbon and Laravel Collections.** 4 | 5 | 6 | 7 | [![GitHub release](https://img.shields.io/github/release/Maatwebsite/Clerk.svg?style=flat)](https://packagist.org/packages/maatwebsite/clerk) 8 | [![Travis](https://img.shields.io/travis/Maatwebsite/Clerk.svg?style=flat)](https://travis-ci.org/Maatwebsite/Clerk) 9 | [![Scrutinizer](https://img.shields.io/scrutinizer/g/Maatwebsite/Clerk.svg?style=flat)](https://github.com/Maatwebsite/Clerk) 10 | [![Packagist](https://img.shields.io/packagist/dd/Maatwebsite/Clerk.svg?style=flat)](https://packagist.org/packages/maatwebsite/clerk) 11 | [![Packagist](https://img.shields.io/packagist/dm/Maatwebsite/Clerk.svg?style=flat)](https://packagist.org/packages/maatwebsite/clerk) 12 | [![Packagist](https://img.shields.io/packagist/dt/Maatwebsite/Clerk.svg?style=flat)](https://packagist.org/packages/maatwebsite/clerk) 13 | 14 | [WIP] Not yet stable! 15 | -------------------------------------------------------------------------------- /src/Templates/TemplateFactory.php: -------------------------------------------------------------------------------- 1 | getEngine(); 21 | 22 | // Get factory class 23 | $class = self::getFactoryClass($engine); 24 | 25 | if (class_exists($class)) { 26 | return new CssFactoryDecorator( 27 | new $class() 28 | ); 29 | } 30 | 31 | throw new DriverNotFoundException("Template factory [{$engine}] was not found"); 32 | } 33 | 34 | /** 35 | * @param string $engine 36 | * 37 | * @return string 38 | */ 39 | protected static function getFactoryClass($engine) 40 | { 41 | return __NAMESPACE__ . '\\Adapters\\' . ucfirst($engine) . '\\' . ucfirst($engine) . 'Factory'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/BorderRightStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new BorderRightStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('000000', $cell->borders()->getRight()->getColor()); 22 | $this->assertContains('thick', $cell->borders()->getRight()->getStyle()); 23 | } 24 | 25 | /** 26 | * @return Cell 27 | */ 28 | protected function mockCell() 29 | { 30 | return new Cell('name'); 31 | } 32 | 33 | /** 34 | * @return Sheet 35 | */ 36 | protected function mockSheet() 37 | { 38 | return new Sheet(new Workbook('title'), 'title'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/BorderBottomStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new BorderBottomStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('000000', $cell->borders()->getBottom()->getColor()); 22 | $this->assertContains('thick', $cell->borders()->getBottom()->getStyle()); 23 | } 24 | 25 | /** 26 | * @return Cell 27 | */ 28 | protected function mockCell() 29 | { 30 | return new Cell('name'); 31 | } 32 | 33 | /** 34 | * @return Sheet 35 | */ 36 | protected function mockSheet() 37 | { 38 | return new Sheet(new Workbook('title'), 'title'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Excel/Adapters/SpreadsheetParser/Parsers/RowParser.php: -------------------------------------------------------------------------------- 1 | settings = $settings; 30 | $this->heading = $heading; 31 | } 32 | 33 | /** 34 | * @param array $row 35 | * 36 | * @return CellCollection 37 | */ 38 | public function parse(array $row = []) 39 | { 40 | $cells = []; 41 | 42 | foreach ($row as $index => $cell) { 43 | $index = ($this->settings->getHasHeading() && isset($this->heading[$index])) ? $this->heading[$index] : $index; 44 | 45 | $cells[$index] = $cell; 46 | } 47 | 48 | return new CellCollection($cells); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Templates/Adapters/Php/FileFinder.php: -------------------------------------------------------------------------------- 1 | path = $path; 35 | $this->extension = $extension; 36 | } 37 | 38 | /** 39 | * Find the file. 40 | * 41 | * @param $file 42 | * 43 | * @throws TemplateNotFoundException 44 | * @return string 45 | */ 46 | public function find($file) 47 | { 48 | $path = $this->path . '/' . $this->getFile($file); 49 | 50 | if (file_exists($path)) { 51 | return $path; 52 | } 53 | 54 | throw new TemplateNotFoundException("Template [{$file}] at path {$path} could not be found"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Word/Documents/Document.php: -------------------------------------------------------------------------------- 1 | setTitle($title); 30 | 31 | // Make a callback on the workbook 32 | $this->call($callback); 33 | } 34 | 35 | /** 36 | * @param Page $page 37 | */ 38 | public function addPage(Page $page) 39 | { 40 | $this->pages[] = $page; 41 | } 42 | 43 | /** 44 | * @return array|Page[] 45 | */ 46 | public function getPages() 47 | { 48 | return $this->pages; 49 | } 50 | 51 | /** 52 | * Set title. 53 | * 54 | * @param string $title 55 | * 56 | * @return $this 57 | */ 58 | abstract public function setTitle($title); 59 | } 60 | -------------------------------------------------------------------------------- /src/Pdf/Writers/WriterFactory.php: -------------------------------------------------------------------------------- 1 | getName()}] was not found"); 32 | } 33 | 34 | /** 35 | * @param DriverInterface $driver 36 | * 37 | * @return string 38 | */ 39 | protected static function getClassByDriver(DriverInterface $driver) 40 | { 41 | return $driver->getWriterClass('Pdf'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Excel/Sheets/LeagueCsvSheetTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Maatwebsite\Clerk\Excel\Sheet', $sheet); 19 | } 20 | 21 | public function test_setting_a_new_sheet_title() 22 | { 23 | $workbook = new Workbook('Workbook'); 24 | $sheet = new Sheet($workbook, 'Sheet title'); 25 | $this->assertEquals('Sheet title', $sheet->getTitle()); 26 | 27 | $sheet->setTitle('Overruled'); 28 | $this->assertEquals('Overruled', $sheet->getTitle()); 29 | } 30 | 31 | public function test_setting_title_through_the_callback() 32 | { 33 | $workbook = new Workbook('Workbook'); 34 | $sheet = new Sheet($workbook, 'Sheet title', function ($sheet) { 35 | $sheet->setTitle('From closure'); 36 | }); 37 | 38 | $this->assertEquals('From closure', $sheet->getTitle()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Excel/Sheets/PHPExcelSheetTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('Maatwebsite\Clerk\Excel\Sheet', $sheet); 19 | } 20 | 21 | public function test_setting_a_new_workbook_title() 22 | { 23 | $workbook = new Workbook('Workbook'); 24 | $sheet = new Sheet($workbook, 'Sheet title'); 25 | $this->assertEquals('Sheet title', $sheet->getTitle()); 26 | 27 | $sheet->setTitle('Overruled'); 28 | $this->assertEquals('Overruled', $sheet->getTitle()); 29 | } 30 | 31 | public function test_setting_title_through_the_callback() 32 | { 33 | $workbook = new Workbook('Workbook'); 34 | $sheet = new Sheet($workbook, 'Sheet title', function ($sheet) { 35 | $sheet->setTitle('From closure'); 36 | }); 37 | 38 | $this->assertEquals('From closure', $sheet->getTitle()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Excel/Adapters/SpreadsheetParser/Readers/CsvReader.php: -------------------------------------------------------------------------------- 1 | settings()->setRowIteratorSetting('delimiter', $delimiter); 23 | 24 | return $this; 25 | } 26 | 27 | /** 28 | * Set CSV enclosure. 29 | * 30 | * @param $enclosure 31 | * 32 | * @return Reader 33 | */ 34 | public function setEnclosure($enclosure) 35 | { 36 | $this->settings()->setRowIteratorSetting('enclosure', $enclosure); 37 | 38 | return $this; 39 | } 40 | 41 | /** 42 | * Set CSV the line endings. 43 | * 44 | * @param $lineEnding 45 | * 46 | * @return Reader 47 | */ 48 | public function setLineEnding($lineEnding) 49 | { 50 | $this->settings()->setRowIteratorSetting('escape', $lineEnding); 51 | 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Excel/Html/Attributes/StyleAttribute.php: -------------------------------------------------------------------------------- 1 | styleSeparator, $attribute->value); 31 | 32 | foreach ($styles as $style) { 33 | $style = explode($this->valueSeperator, $style); 34 | $name = trim(reset($style)); 35 | $value = trim(end($style)); 36 | 37 | // When the parser exists, parse the style 38 | if ($name && $value && $parser = StyleParserFactory::create($name, $this->sheet)) { 39 | $cell = $this->sheet->cell($table->getCoordinate()); 40 | $parser->parse($cell, $value, $table); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | exclude('vendor') 5 | ->in(__DIR__); 6 | 7 | return Symfony\CS\Config\Config::create() 8 | ->setUsingCache(true) 9 | ->level(Symfony\CS\FixerInterface::PSR2_LEVEL) 10 | ->fixers(array( 11 | 'psr0', 12 | 'encoding', 13 | 'short_tag', 14 | 'blankline_after_open_tag', 15 | 'namespace_no_leading_whitespace', 16 | 'no_blank_lines_after_class_opening', 17 | 'single_array_no_trailing_comma', 18 | 'no_empty_lines_after_phpdocs', 19 | 'concat_with_spaces', 20 | 'eof_ending', 21 | 'ordered_use', 22 | 'extra_empty_lines', 23 | 'single_line_after_imports', 24 | 'trailing_spaces', 25 | 'remove_lines_between_uses', 26 | 'return', 27 | 'indentation', 28 | 'linefeed', 29 | 'braces', 30 | 'visibility', 31 | 'unused_use', 32 | 'whitespacy_lines', 33 | 'php_closing_tag', 34 | 'phpdoc_order', 35 | 'phpdoc_params', 36 | 'phpdoc_trim', 37 | 'phpdoc_scalar', 38 | 'short_array_syntax', 39 | 'align_double_arrow', 40 | 'align_equals', 41 | 'lowercase_constants', 42 | 'lowercase_keywords', 43 | 'multiple_use', 44 | 'line_after_namespace', 45 | ))->finder($finder); 46 | -------------------------------------------------------------------------------- /src/Pdf/Document.php: -------------------------------------------------------------------------------- 1 | 20 | $table->setColumn( 21 | $table->setStartColumn() 22 | ); 23 | 24 | // Fake as if we are inside a 25 | $table->nextRow(); 26 | 27 | $this->assertEquals('A', $table->getColumn()); 28 | 29 | $sheet = $this->mockSheet(); 30 | 31 | $element = new TdElement($sheet); 32 | $element->parse($dom, $table); 33 | 34 | // Flush the element 35 | $element->flush($table); 36 | 37 | $this->assertEquals('B', $table->getColumn()); 38 | } 39 | 40 | /** 41 | * @return \Maatwebsite\Clerk\Sheet 42 | */ 43 | public function mockSheet() 44 | { 45 | $sheet = \Mockery::mock('Maatwebsite\Clerk\Excel\Sheet'); 46 | 47 | // the cell value should be set. 48 | $sheet->shouldReceive('cell')->with('A1', 'Name')->once(); 49 | 50 | return $sheet; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Excel/Html/Elements/TdElementTest.php: -------------------------------------------------------------------------------- 1 | 20 | $table->setColumn( 21 | $table->setStartColumn() 22 | ); 23 | 24 | // Fake as if we are inside a 25 | $table->nextRow(); 26 | 27 | $this->assertEquals('A', $table->getColumn()); 28 | 29 | $sheet = $this->mockSheet(); 30 | 31 | $element = new TdElement($sheet); 32 | $element->parse($dom, $table); 33 | 34 | // Flush the element 35 | $element->flush($table); 36 | 37 | $this->assertEquals('B', $table->getColumn()); 38 | } 39 | 40 | /** 41 | * @return \Maatwebsite\Clerk\Sheet 42 | */ 43 | public function mockSheet() 44 | { 45 | $sheet = \Mockery::mock('Maatwebsite\Clerk\Excel\Sheet'); 46 | 47 | // the cell value should be set. 48 | $sheet->shouldReceive('cell')->with('A1', 'Patrick')->once(); 49 | 50 | return $sheet; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Templates/CssInlinerTest.php: -------------------------------------------------------------------------------- 1 | 10 | table { 11 | background: #000000; 12 | } 13 | 14 |
'; 15 | 16 | $inliner = new CssInliner(); 17 | $inlined = $inliner->transformCssToInlineStyles($html); 18 | 19 | $this->assertEquals(' 20 |
21 | ', $inlined); 22 | } 23 | 24 | public function test_css_from_style_sheets_links_get_inlined() 25 | { 26 | $html = ' 27 |
'; 28 | 29 | $inliner = new CssInliner(); 30 | $inlined = $inliner->transformCssToInlineStyles($html); 31 | 32 | $this->assertEquals(' 33 |
34 | ', $inlined); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Excel/Collections/CellCollection.php: -------------------------------------------------------------------------------- 1 | setItems($items); 18 | } 19 | 20 | /** 21 | * Set the items. 22 | * 23 | * @param array $items 24 | */ 25 | public function setItems($items) 26 | { 27 | foreach ($items as $name => $value) { 28 | $value = !empty($value) || is_numeric($value) ? $value : null; 29 | if ($name && !is_numeric($name)) { 30 | $this->put($name, $value); 31 | } else { 32 | $this->push($value); 33 | } 34 | } 35 | } 36 | 37 | /** 38 | * Dynamically get values. 39 | * 40 | * @param string $key 41 | * 42 | * @return string 43 | */ 44 | public function __get($key) 45 | { 46 | if ($this->has($key)) { 47 | return $this->get($key); 48 | } 49 | } 50 | 51 | /** 52 | * Determine if an attribute exists on the model. 53 | * 54 | * @param string $key 55 | * 56 | * @return bool 57 | */ 58 | public function __isset($key) 59 | { 60 | return $this->has($key); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Word/Page.php: -------------------------------------------------------------------------------- 1 | settings->getHasHeading() ? $this->getHeading($sheet) : []; 21 | } 22 | 23 | /** 24 | * Get the heading. 25 | * 26 | * @param PHPExcel_Worksheet $worksheet 27 | * 28 | * @return array 29 | */ 30 | protected function getHeading($worksheet) 31 | { 32 | // Fetch the first row 33 | $row = $worksheet->getRowIterator($this->settings->getHeadingRow())->current(); 34 | 35 | // Set empty labels array 36 | $heading = []; 37 | 38 | // Loop through the cells 39 | foreach ($row->getCellIterator() as $cell) { 40 | $heading[] = $this->getIndex($cell); 41 | } 42 | 43 | return $heading; 44 | } 45 | 46 | /** 47 | * Get orignal indice. 48 | * 49 | * @param $cell 50 | * 51 | * @return string 52 | */ 53 | public function getOriginalIndex($cell) 54 | { 55 | return is_object($cell) ? $cell->getValue() : $cell; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Excel/Writers/PHPExcelWriterTest.php: -------------------------------------------------------------------------------- 1 | workbook = m::mock('Maatwebsite\Clerk\Excel\Workbook'); 14 | } 15 | 16 | public function tearDown() 17 | { 18 | m::close(); 19 | } 20 | 21 | public function test_can_init() 22 | { 23 | $writer = new Writer('CSV', 'csv', $this->workbook); 24 | 25 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Writer', $writer); 26 | } 27 | 28 | public function test_get_content_type() 29 | { 30 | $writer = new Writer('CSV', 'csv', $this->workbook); 31 | $this->assertContains('application/csv; charset=UTF-8', $writer->getContentType('CSV')); 32 | 33 | $writer = new CsvWriter('CSV', 'csv', $this->workbook); 34 | $this->assertContains('application/csv; charset=UTF-8', $writer->getContentType('CSV')); 35 | 36 | $writer = new Writer('Excel5', 'xls', $this->workbook); 37 | $this->assertContains('application/vnd.ms-excel; charset=UTF-8', $writer->getContentType('Excel5')); 38 | 39 | $writer = new Writer('Excel2007', 'xlsx', $this->workbook); 40 | $this->assertContains('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8', $writer->getContentType('Excel2007')); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/BackgroundStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new BackgroundStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('000000', $cell->fill()->getColor()); 22 | } 23 | 24 | public function test_background_color_style_with_hash() 25 | { 26 | $value = '#000000'; 27 | $cell = $this->mockCell(); 28 | $sheet = $this->mockSheet(); 29 | $table = new ReferenceTable(); 30 | 31 | $attribute = new BackgroundStyle($sheet); 32 | $attribute->parse($cell, $value, $table); 33 | 34 | $this->assertContains('000000', $cell->fill()->getColor()); 35 | } 36 | 37 | /** 38 | * @return Cell 39 | */ 40 | protected function mockCell() 41 | { 42 | return new Cell('name'); 43 | } 44 | 45 | /** 46 | * @return Sheet 47 | */ 48 | protected function mockSheet() 49 | { 50 | return new Sheet(new Workbook('title'), 'title'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/TextDecorationStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new TextDecorationStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertEquals('single', $cell->font()->getUnderline()); 22 | } 23 | 24 | public function test_text_strikethrough() 25 | { 26 | $value = 'line-through'; 27 | $cell = $this->mockCell(); 28 | $sheet = $this->mockSheet(); 29 | $table = new ReferenceTable(); 30 | 31 | $attribute = new TextDecorationStyle($sheet); 32 | $attribute->parse($cell, $value, $table); 33 | 34 | $this->assertTrue($cell->font()->getStrikethrough()); 35 | } 36 | 37 | /** 38 | * @return Cell 39 | */ 40 | protected function mockCell() 41 | { 42 | return new Cell('name'); 43 | } 44 | 45 | /** 46 | * @return Sheet 47 | */ 48 | protected function mockSheet() 49 | { 50 | return new Sheet(new Workbook('title'), 'title'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Excel/Html/Elements/AElementTest.php: -------------------------------------------------------------------------------- 1 | createElement('a'); 19 | $dom->setAttribute('href', 'http://google.com'); 20 | 21 | $sheet = $this->mockSheet(); 22 | $table = new ReferenceTable(); 23 | 24 | // Fake as if we are inside a 25 | $table->setColumn( 26 | $table->setStartColumn() 27 | ); 28 | 29 | // Fake as if we are inside a 30 | $table->nextRow(); 31 | 32 | $element = new AElement($sheet); 33 | $element->parse($dom, $table); 34 | 35 | $this->assertEquals('http://google.com', $sheet->getCell($table->getCoordinate())->getHyperlink()->getUrl()); 36 | 37 | // Text color should be blue 38 | $sheet->cell($table->getCoordinate(), function ($cell) { 39 | $this->assertEquals('0000ff', $cell->font()->getColor()); 40 | }); 41 | } 42 | 43 | /** 44 | * @return \Maatwebsite\Clerk\Excel\Sheet 45 | */ 46 | public function mockSheet() 47 | { 48 | return new Sheet(new Workbook('title'), 'title'); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/Excel/Writers/WriterFactoryTest.php: -------------------------------------------------------------------------------- 1 | sheet('mock'); 14 | 15 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Writers\Writer', WriterFactory::create(new PHPExcel('drivers.writer.excel2003'), 'Excel5', 'xls', $workbook)); 16 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Writers\Writer', WriterFactory::create(new PHPExcel('drivers.writer.excel2007'), 'Excel2007', 'xlsx', $workbook)); 17 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\LeagueCsv\Writers\CsvWriter', WriterFactory::create(new LeagueCsv('drivers.writer.csv'), 'Csv', 'csv', $workbook)); 18 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Writers\CsvWriter', WriterFactory::create(new PHPExcel('drivers.writer.csv'), 'Csv', 'csv', $workbook)); 19 | } 20 | 21 | public function test_factory_returns_exception_when_trying_to_use_it_without_sheets() 22 | { 23 | $this->setExpectedException('Maatwebsite\Clerk\Exceptions\ExportFailedException'); 24 | 25 | $workbook = new Workbook('mock'); 26 | WriterFactory::create(new PHPExcel('drivers.writer.excel2003'), 'Excel5', 'xls', $workbook); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Excel/Html/Styles/BackgroundColorStyleTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 15 | $sheet = $this->mockSheet(); 16 | $table = new ReferenceTable(); 17 | 18 | $attribute = new BackgroundColorStyle($sheet); 19 | $attribute->parse($cell, $value, $table); 20 | 21 | $this->assertContains('000000', $cell->fill()->getColor()); 22 | } 23 | 24 | public function test_background_color_style_with_hash() 25 | { 26 | $value = '#000000'; 27 | $cell = $this->mockCell(); 28 | $sheet = $this->mockSheet(); 29 | $table = new ReferenceTable(); 30 | 31 | $attribute = new BackgroundColorStyle($sheet); 32 | $attribute->parse($cell, $value, $table); 33 | 34 | $this->assertContains('000000', $cell->fill()->getColor()); 35 | } 36 | 37 | /** 38 | * @return Cell 39 | */ 40 | protected function mockCell() 41 | { 42 | return new Cell('name'); 43 | } 44 | 45 | /** 46 | * @return Sheet 47 | */ 48 | protected function mockSheet() 49 | { 50 | return new Sheet(new Workbook('title'), 'title'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Drivers/DriverInterface.php: -------------------------------------------------------------------------------- 1 | [ 18 | * 'excel2003' => true, 19 | * ], 20 | * 'writer' => [ 21 | * 'excel2003' => true, 22 | * ] 23 | * ]; 24 | */ 25 | public function supports(); 26 | 27 | /** 28 | * @param $format 29 | * 30 | * @return string 31 | */ 32 | public function getWorkbookClass($format); 33 | 34 | /** 35 | * @param $format 36 | * 37 | * @return string 38 | */ 39 | public function getReaderClass($format); 40 | 41 | /** 42 | * @param $format 43 | * @param $type 44 | * 45 | * @return string 46 | */ 47 | public function getReaderClassByType($format, $type); 48 | 49 | /** 50 | * @param $format 51 | * 52 | * @return string 53 | */ 54 | public function getWriterClass($format); 55 | 56 | /** 57 | * @param $format 58 | * @param $type 59 | * 60 | * @return string 61 | */ 62 | public function getWriterClassByType($format, $type); 63 | 64 | /** 65 | * @param $format 66 | * 67 | * @return mixed 68 | */ 69 | public function getDocumentClass($format); 70 | } 71 | -------------------------------------------------------------------------------- /src/Excel/Adapters/PHPExcel/Writers/CellWriter.php: -------------------------------------------------------------------------------- 1 | sheet = $sheet; 21 | } 22 | 23 | /** 24 | * @param Cell $cell 25 | */ 26 | public function write(Cell $cell) 27 | { 28 | $coordinate = $cell->getCoordinate()->get(); 29 | 30 | /* 31 | * CELL VALUE 32 | */ 33 | 34 | if ($cell->getDataType()) { 35 | $this->sheet->getCell($coordinate)->setValueExplicit( 36 | $cell->getValue(), 37 | (string) $cell->getDataType() 38 | ); 39 | } else { 40 | $this->sheet->getCell($coordinate)->setValue( 41 | $cell->getValue() 42 | ); 43 | } 44 | 45 | /* 46 | * NUMBER FORMAT 47 | */ 48 | $this->sheet->getStyle($coordinate) 49 | ->getNumberFormat() 50 | ->setFormatCode((string) $cell->getFormat()); 51 | 52 | /* 53 | * CELL STYLES 54 | */ 55 | if ($cell->hasStyles()) { 56 | $styles = (new StyleWriter())->convert( 57 | $cell->getStyles() 58 | ); 59 | 60 | $this->sheet->getStyle($coordinate)->applyFromArray($styles); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Excel/Html/HtmlToSheetConverter.php: -------------------------------------------------------------------------------- 1 | loadHTML($this->getNormalizedHtml($html), $this->getXmlReaderOptions())) { 27 | throw new ExportFailedException('Failed to load the template'); 28 | } 29 | 30 | // Discard white space 31 | $document->preserveWhiteSpace = false; 32 | 33 | // Parse the dom document 34 | (new Document($sheet))->parse( 35 | $document, 36 | new ReferenceTable() 37 | ); 38 | 39 | return $sheet; 40 | } 41 | 42 | /** 43 | * @param $html 44 | * 45 | * @return bool|mixed|string 46 | */ 47 | public function getNormalizedHtml($html) 48 | { 49 | return mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); 50 | } 51 | 52 | /** 53 | * Get the reader options. 54 | * 55 | * @return int 56 | */ 57 | protected function getXmlReaderOptions() 58 | { 59 | @libxml_disable_entity_loader(true); 60 | 61 | return LIBXML_DTDLOAD | LIBXML_DTDATTR; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Templates/Adapters/Twig/TwigFactory.php: -------------------------------------------------------------------------------- 1 | twig = new Twig_Environment($loader, [ 45 | 'cache' => Ledger::get('templates.cache'), 46 | ]); 47 | } 48 | 49 | /** 50 | * Make the view. 51 | * 52 | * @param string $file 53 | * @param array $data 54 | * 55 | * @return $this 56 | */ 57 | public function make($file, array $data = []) 58 | { 59 | $this->template = $this->twig->loadTemplate($this->getFile($file)); 60 | $this->data = $data; 61 | 62 | return $this; 63 | } 64 | 65 | /** 66 | * Render the template. 67 | * 68 | * @return string 69 | */ 70 | public function render() 71 | { 72 | return $this->template->render($this->data); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Templates/Adapters/Smarty/SmartyFactory.php: -------------------------------------------------------------------------------- 1 | smarty = new Smarty(); 38 | $this->smarty->setTemplateDir(Ledger::get('templates.path')); 39 | $this->smarty->setCompileDir(Ledger::get('templates.compile')); 40 | $this->smarty->setCacheDir(Ledger::get('templates.cache')); 41 | $this->smarty->setConfigDir(Ledger::get('templates.config')); 42 | } 43 | 44 | /** 45 | * Make the view. 46 | * 47 | * @param string $file 48 | * @param array $data 49 | * 50 | * @return $this 51 | */ 52 | public function make($file, array $data = []) 53 | { 54 | $this->file = $file; 55 | 56 | // Assign data 57 | $this->smarty->assign($data); 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * Render the template. 64 | * 65 | * @return string 66 | */ 67 | public function render() 68 | { 69 | return $this->smarty->fetch( 70 | $this->getFile($this->file) 71 | ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Excel/Adapters/SpreadsheetParser/Readers/Reader.php: -------------------------------------------------------------------------------- 1 | file = $file; 35 | 36 | $this->call($callback); 37 | } 38 | 39 | /** 40 | * Get all sheets/rows. 41 | * 42 | * @param array $columns 43 | * 44 | * @return \Illuminate\Support\Collection 45 | */ 46 | public function get($columns = []) 47 | { 48 | // Load the file 49 | ini_set('auto_detect_line_endings', true); 50 | $this->driver = SpreadsheetParser::open($this->file); 51 | 52 | // Set selected columns 53 | $this->settings()->setColumns($columns); 54 | 55 | return (new WorkbookParser($this->settings()))->parse($this->getWorkbook()); 56 | } 57 | 58 | /** 59 | * @return SpreadsheetInterface 60 | */ 61 | protected function getWorkbook() 62 | { 63 | return $this->getDriver(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Excel/Styles/Styleable.php: -------------------------------------------------------------------------------- 1 | format; 27 | } 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getExtension() 33 | { 34 | return $this->extension; 35 | } 36 | 37 | /** 38 | * @return \Maatwebsite\Clerk\Excel\Workbook 39 | */ 40 | public function getWorkbook() 41 | { 42 | return $this->workbook; 43 | } 44 | 45 | /** 46 | * @param $filename 47 | * 48 | * @throws \Maatwebsite\Clerk\Exceptions\DriverNotFoundException 49 | * @return mixed|void 50 | */ 51 | public function export($filename = null) 52 | { 53 | $writer = $this->initWriter(); 54 | 55 | return $writer->export($filename); 56 | } 57 | 58 | /** 59 | * @param $path 60 | * @param null $filename 61 | * 62 | * @return mixed|void 63 | */ 64 | public function store($path, $filename = null) 65 | { 66 | $writer = $this->initWriter(); 67 | 68 | return $writer->store($path, $filename); 69 | } 70 | 71 | /** 72 | * @throws \Maatwebsite\Clerk\Exceptions\DriverNotFoundException 73 | * @return \Maatwebsite\Clerk\Writer 74 | */ 75 | abstract public function initWriter(); 76 | 77 | /** 78 | * @param $type 79 | * 80 | * @return mixed 81 | */ 82 | abstract protected function getDriver($type); 83 | } 84 | -------------------------------------------------------------------------------- /src/Templates/Adapters/Php/PhpEngine.php: -------------------------------------------------------------------------------- 1 | finder = $finder; 23 | } 24 | 25 | /** 26 | * Compile a template with the PhpEngine. 27 | * 28 | * @param string $__file 29 | * @param array $__data 30 | * 31 | * @return string 32 | */ 33 | public function compile($__file, array $__data = []) 34 | { 35 | // Find the file path 36 | $__path = $this->finder->find($__file); 37 | 38 | $obLevel = ob_get_level(); 39 | 40 | ob_start(); 41 | 42 | extract($__data); 43 | 44 | // We'll evaluate the contents of the view inside a try/catch block so we can 45 | // flush out any stray output that might get out before an error occurs or 46 | // an exception is thrown. This prevents any partial views from leaking. 47 | try { 48 | include $__path; 49 | } catch (Exception $e) { 50 | $this->handleViewException($e, $obLevel); 51 | } 52 | 53 | return ltrim(ob_get_clean()); 54 | } 55 | 56 | /** 57 | * Handle a view exception. 58 | * 59 | * @param \Exception $e 60 | * @param int $obLevel 61 | * 62 | * @throws $e 63 | */ 64 | protected function handleViewException($e, $obLevel) 65 | { 66 | while (ob_get_level() > $obLevel) { 67 | ob_end_clean(); 68 | } 69 | 70 | throw $e; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Word/Pages/Text.php: -------------------------------------------------------------------------------- 1 | text = $text; 34 | $this->styleFont = $styleFont; 35 | $this->styleParagraph = $styleParagraph; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getText() 42 | { 43 | return $this->text; 44 | } 45 | 46 | /** 47 | * @param string $text 48 | */ 49 | public function setText($text) 50 | { 51 | $this->text = $text; 52 | } 53 | 54 | /** 55 | * @return null 56 | */ 57 | public function getStyleFont() 58 | { 59 | return $this->styleFont; 60 | } 61 | 62 | /** 63 | * @param null $styleFont 64 | */ 65 | public function setStyleFont($styleFont) 66 | { 67 | $this->styleFont = $styleFont; 68 | } 69 | 70 | /** 71 | * @return null 72 | */ 73 | public function getStyleParagraph() 74 | { 75 | return $this->styleParagraph; 76 | } 77 | 78 | /** 79 | * @param null $styleParagraph 80 | */ 81 | public function setStyleParagraph($styleParagraph) 82 | { 83 | $this->styleParagraph = $styleParagraph; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Word/Writers/WriterFactory.php: -------------------------------------------------------------------------------- 1 | getName()}] was not found"); 38 | } 39 | 40 | /** 41 | * @param $driver 42 | * 43 | * @return string 44 | */ 45 | protected static function getClassByDriver(DriverInterface $driver) 46 | { 47 | return $driver->getWriterClass('Word'); 48 | } 49 | 50 | /** 51 | * @param DriverInterface $driver 52 | * @param $type 53 | * 54 | * @return string 55 | */ 56 | private static function getClassByDriverAndType(DriverInterface $driver, $type) 57 | { 58 | return $driver->getWriterClassByType('Word', $type); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Word/Adapters/PHPWord/Writers/Writer.php: -------------------------------------------------------------------------------- 1 | getFilename($filename); 21 | $document = $this->convertToDriver( 22 | $this->getExportable() 23 | ); 24 | 25 | return $document->save( 26 | $filename . '.' . $this->getExtension(), 27 | $this->getType(), 28 | true 29 | ); 30 | } 31 | 32 | /** 33 | * @param $path 34 | * @param null $filename 35 | * 36 | * @return mixed 37 | */ 38 | public function store($path, $filename = null) 39 | { 40 | $filename = $this->getFilename($filename); 41 | $document = $this->convertToDriver( 42 | $this->getExportable() 43 | ); 44 | 45 | return $document->save( 46 | $path . '/' . $filename . '.' . $this->getExtension(), 47 | $this->getType(), 48 | false 49 | ); 50 | } 51 | 52 | /** 53 | * @param Document $document 54 | * 55 | * @return \PhpOffice\PhpWord\PhpWord 56 | */ 57 | protected function convertToDriver(Document $document) 58 | { 59 | $driver = $document->getDriver(); 60 | 61 | foreach ($document->getPages() as $page) { 62 | $section = $document->getDriver()->addSection(); 63 | (new PageWriter())->write($section, $page); 64 | } 65 | 66 | return $driver; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Templates/Css/StylesheetExtractor.php: -------------------------------------------------------------------------------- 1 | html = $html; 26 | 27 | $document = new DOMDocument(); 28 | $document->loadHTML($this->html); 29 | $this->xml = simplexml_import_dom($document); 30 | } 31 | 32 | /** 33 | * @return array 34 | */ 35 | public function extract() 36 | { 37 | $links = []; 38 | 39 | foreach ($this->findByStylesheetTag() as $node) { 40 | $link = $this->getCleanStylesheetLink($node); 41 | $links[$link] = $this->getCssFromLink($link); 42 | } 43 | 44 | return $links; 45 | } 46 | 47 | /** 48 | * Find the stylesheet path. 49 | * 50 | * @return \SimpleXMLElement[] 51 | */ 52 | protected function findByStylesheetTag() 53 | { 54 | return $this->xml->xpath('//link[@rel="stylesheet"]'); 55 | } 56 | 57 | /** 58 | * Get clean stylesheet link. 59 | * 60 | * @param $node 61 | * 62 | * @return string 63 | */ 64 | protected function getCleanStylesheetLink($node) 65 | { 66 | // Get the link 67 | $link = $node->attributes()->href; 68 | 69 | return (string) $link; 70 | } 71 | 72 | /** 73 | * Get css from link. 74 | * 75 | * @param string $link 76 | * 77 | * @return string 78 | */ 79 | protected function getCssFromLink($link) 80 | { 81 | return file_get_contents($link); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Excel/Adapters/PHPExcel/Parsers/RowParser.php: -------------------------------------------------------------------------------- 1 | settings = $settings; 33 | $this->heading = $heading; 34 | } 35 | 36 | /** 37 | * @param PHPExcel_Worksheet_Row $row 38 | * 39 | * @return CellCollection 40 | */ 41 | public function parse(PHPExcel_Worksheet_Row $row) 42 | { 43 | $iterator = $row->getCellIterator(); 44 | $iterator->setIterateOnlyExistingCells($this->settings->getIgnoreEmpty()); 45 | 46 | $cells = []; 47 | 48 | foreach ($iterator as $index => $cell) { 49 | $index = ($this->settings->getHasHeading() && isset($this->heading[$index])) ? $this->heading[$index] : $this->getIndexFromColumn($cell); 50 | 51 | $cells[$index] = new Cell($cell, $index, $this->settings); 52 | } 53 | 54 | return new CellCollection($cells); 55 | } 56 | 57 | /** 58 | * Get index from column. 59 | * 60 | * @param $cell 61 | * 62 | * @return mixed 63 | */ 64 | protected function getIndexFromColumn($cell) 65 | { 66 | return PHPExcel_Cell::columnIndexFromString($cell->getColumn()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "maatwebsite/clerk", 3 | "description": "An eloquent way of importing and exporting Excel and CSV in PHP 5.4+ with the power of packages PHPExcel, League/Csv and Laravel's Collections", 4 | "license": "LGPL", 5 | "keywords": [ 6 | "laravel", 7 | "phpexcel", 8 | "excel", 9 | "csv", 10 | "export", 11 | "import", 12 | "batch" 13 | ], 14 | "authors": [ 15 | { 16 | "name": "Maatwebsite.nl", 17 | "email": "patrick@maatwebsite.nl" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=5.4.0", 22 | "nesbot/carbon": "~1.0", 23 | "knplabs/knp-snappy": "~0.3.4", 24 | "league/csv": "~7.1.0@dev", 25 | "akeneo/spreadsheet-parser": "~1.1.5", 26 | "phpoffice/phpexcel": "~1.8.0", 27 | "phpoffice/phpword": "~0.12.0", 28 | "patchwork/utf8": "~1.2.1", 29 | "symfony/http-foundation": "~2.6|~2.7@dev", 30 | "illuminate/support": "~4.0|~5.0", 31 | "tijsverkoyen/css-to-inline-styles": "~2.0" 32 | }, 33 | "suggests": { 34 | "league/csv": "Using League CSV as CSV parser", 35 | "akeneo/spreadsheet-parser": "Using Akeneo Spreadsheet parser", 36 | "phpoffice/phpexcel": "PHPExcel as Excel driver", 37 | "phpoffice/phpword": "PHPWord as Word driver", 38 | "illuminate/view": "If you want to use Blade as templating engine", 39 | "twig/twig": "If you want to use Twig as templating engine", 40 | "smarty/smarty": "If you want to use Smarty as templating engine" 41 | }, 42 | "require-dev": { 43 | "phpunit/phpunit": "~4.0", 44 | "mockery/mockery": "~0.9", 45 | "illuminate/view": "~4.0|~5.0", 46 | "twig/twig": "~1.18.0", 47 | "smarty/smarty": "~3.1.21", 48 | "phpspec/prophecy": "1.3.1" 49 | }, 50 | "autoload": { 51 | "psr-4": { 52 | "Maatwebsite\\Clerk\\": "src/" 53 | } 54 | }, 55 | "autoload-dev": { 56 | "classmap": [ 57 | "tests" 58 | ] 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Excel/Adapters/PHPExcel/Readers/Reader.php: -------------------------------------------------------------------------------- 1 | setWriter($type); 29 | $this->file = $file; 30 | 31 | $this->call($callback); 32 | } 33 | 34 | /** 35 | * Set the writer. 36 | * 37 | * @param $type 38 | */ 39 | protected function setWriter($type) 40 | { 41 | $this->reader = PHPExcel_IOFactory::createReader($type); 42 | } 43 | 44 | /** 45 | * Get all sheets/rows. 46 | * 47 | * @param array $columns 48 | * 49 | * @return \Illuminate\Support\Collection 50 | */ 51 | public function get($columns = []) 52 | { 53 | // Load the file 54 | $this->driver = $this->reader->load($this->file); 55 | 56 | // Set selected columns 57 | $this->settings()->setColumns($columns); 58 | 59 | return (new WorkbookParser($this->settings()))->parse($this->getWorkbook()); 60 | } 61 | 62 | /** 63 | * @return \PHPExcel_Reader_IReader 64 | */ 65 | public function getReader() 66 | { 67 | return $this->reader; 68 | } 69 | 70 | /** 71 | * @return PHPExcel 72 | */ 73 | protected function getWorkbook() 74 | { 75 | return $this->getDriver(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Excel/Adapters/SpreadsheetParser/Parsers/HeadingParser.php: -------------------------------------------------------------------------------- 1 | settings->getHasHeading() ? $this->getHeading($workbook, $sheetIndex) : []; 22 | } 23 | 24 | /** 25 | * Get the heading. 26 | * 27 | * @param SpreadsheetInterface $workbook 28 | * @param $sheetIndex 29 | * 30 | * @return array 31 | */ 32 | protected function getHeading(SpreadsheetInterface $workbook, $sheetIndex) 33 | { 34 | // Fetch the first row 35 | $row = $workbook->createRowIterator($sheetIndex, $this->settings->getRowIteratorSettings()); 36 | 37 | // Set empty labels array 38 | $heading = []; 39 | 40 | // Loop through the cells 41 | foreach ($row as $index => $values) { 42 | if ($index == $this->settings->getHeadingRow()) { 43 | foreach ($values as $cell) { 44 | $heading[] = $this->getIndex($cell); 45 | } 46 | 47 | return $heading; 48 | } 49 | } 50 | 51 | return $heading; 52 | } 53 | 54 | /** 55 | * Get original index. 56 | * 57 | * @param $cell 58 | * 59 | * @return string 60 | */ 61 | protected function getOriginalIndex($cell) 62 | { 63 | return $cell; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Excel/Adapters/PHPExcel/Parsers/WorkbookParser.php: -------------------------------------------------------------------------------- 1 | settings = $settings; 25 | } 26 | 27 | /** 28 | * Parse the workbook. 29 | * 30 | * @param PHPExcel $workbook 31 | * 32 | * @return SheetCollection 33 | */ 34 | public function parse(PHPExcel $workbook) 35 | { 36 | // Init sheet collection 37 | $collection = new SheetCollection(); 38 | 39 | // Set the workbook title 40 | $collection->setTitle( 41 | $workbook->getProperties()->getTitle() 42 | ); 43 | 44 | // Worksheet parser 45 | $parser = new SheetParser($this->settings); 46 | 47 | // Loop through all worksheets 48 | foreach ($workbook->getWorksheetIterator() as $index => $worksheet) { 49 | if ($this->isSelected($index)) { 50 | // Push the sheet onto the workbook 51 | $collection->push( 52 | $parser->parse($worksheet) 53 | ); 54 | } 55 | } 56 | 57 | return $collection; 58 | } 59 | 60 | /** 61 | * Check if sheet is selected. 62 | * 63 | * @param $index 64 | * 65 | * @return bool 66 | */ 67 | protected function isSelected($index) 68 | { 69 | $sheets = $this->settings->getSheetIndices(); 70 | 71 | return empty($sheets) || in_array($index, $sheets); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Pdf/Pages/Page.php: -------------------------------------------------------------------------------- 1 | call($callback); 32 | 33 | $this->text[] = $text; 34 | 35 | return $this; 36 | } 37 | 38 | /** 39 | * @param $text 40 | * @param callable $callback 41 | * 42 | * @return $this 43 | */ 44 | public function addHtml($text, Closure $callback = null) 45 | { 46 | $text = new HtmlText($text); 47 | 48 | $text->call($callback); 49 | 50 | $this->text[] = $text; 51 | 52 | return $this; 53 | } 54 | 55 | /** 56 | * Load from template. 57 | * 58 | * @param $template 59 | * @param array $data 60 | * @param null $engine 61 | * 62 | * @return mixed 63 | */ 64 | public function loadTemplate($template, array $data = [], $engine = null) 65 | { 66 | // Init factory based on given engine, based on extension or use of default engine 67 | $factory = TemplateFactory::create($template, $engine); 68 | 69 | // Render the template 70 | $html = $factory->make($template, $data)->render(); 71 | 72 | $this->addHtml($html); 73 | 74 | return $this; 75 | } 76 | 77 | /** 78 | * @return array|Text[] 79 | */ 80 | public function getText() 81 | { 82 | return $this->text; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Excel/Adapters/SpreadsheetParser/Parsers/WorkbookParser.php: -------------------------------------------------------------------------------- 1 | settings = $settings; 25 | } 26 | 27 | /** 28 | * Parse the workbook. 29 | * 30 | * @param SpreadsheetInterface $workbook 31 | * 32 | * @return SheetCollection 33 | */ 34 | public function parse(SpreadsheetInterface $workbook) 35 | { 36 | // Init sheet collection 37 | $collection = new SheetCollection(); 38 | 39 | // Sheet parser 40 | $parser = new SheetParser($this->settings); 41 | 42 | // Loop through all worksheets 43 | foreach ($workbook->getWorksheets() as $worksheet) { 44 | $index = $workbook->getWorksheetIndex($worksheet); 45 | 46 | if ($this->isSelected($index)) { 47 | // Push the sheet onto the workbook 48 | $collection->push( 49 | $parser->parse($workbook, $worksheet, $index) 50 | ); 51 | } 52 | } 53 | 54 | return $collection; 55 | } 56 | 57 | /** 58 | * Check if sheet is selected. 59 | * 60 | * @param $index 61 | * 62 | * @return bool 63 | */ 64 | protected function isSelected($index) 65 | { 66 | $sheets = $this->settings->getSheetIndices(); 67 | 68 | return empty($sheets) || in_array($index, $sheets); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/Excel/Identifiers/files/test.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | test 10 | 60 | 61 | 62 | 63 | 64 |
66 | 67 | 68 | 69 | 70 |
71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/Excel/Adapters/LeagueCsv/Writers/CsvWriter.php: -------------------------------------------------------------------------------- 1 | getFilename($filename); 23 | 24 | $source = $this->convertCellsToArray($this->getExportable()); 25 | 26 | $workbook = $this->getExportable()->getDriver()->insertAll($source); 27 | 28 | $workbook->output($filename . '.' . $this->getExtension()); 29 | 30 | exit; 31 | } 32 | 33 | /** 34 | * @param $path 35 | * @param null $filename 36 | * 37 | * @return mixed 38 | */ 39 | public function store($path, $filename = null) 40 | { 41 | // TODO: Implement store() method. 42 | } 43 | 44 | /** 45 | * Convert cells to array 46 | * @param Workbook $workbook 47 | * 48 | * @return array 49 | */ 50 | protected function convertCellsToArray(Workbook $workbook) 51 | { 52 | $source = []; 53 | $r = 0; 54 | $row = 1; 55 | foreach ($workbook->getSheets() as $sheet) { 56 | foreach ($sheet->getCells() as $cell) { 57 | 58 | // Go to next row when needed 59 | if ($cell->getCoordinate()->getRow() != $row) { 60 | $r++; 61 | } 62 | 63 | // Set value 64 | $source[$r][] = $cell->getValue(); 65 | 66 | // Save last row 67 | $row = $cell->getCoordinate()->getRow(); 68 | } 69 | } 70 | 71 | return $source; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Word/Adapters/PHPWord/Document.php: -------------------------------------------------------------------------------- 1 | driver = $driver ?: new PHPWord(); 31 | 32 | parent::__construct($title, $callback); 33 | } 34 | 35 | /** 36 | * Set title. 37 | * 38 | * @param string $title 39 | * 40 | * @return $this 41 | */ 42 | public function setTitle($title) 43 | { 44 | $this->getDriver()->getDocInfo()->setTitle($title); 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getTitle() 53 | { 54 | return $this->getDriver()->getDocInfo()->getTitle(); 55 | } 56 | 57 | /** 58 | * Init a new page. 59 | * 60 | * @param $text 61 | * @param Closure $callback 62 | * 63 | * @return Page 64 | */ 65 | public function page($text = null, Closure $callback = null) 66 | { 67 | // Init a new page 68 | $page = new Page( 69 | !is_callable($text) ? $text : null, 70 | $this 71 | ); 72 | 73 | // Preform callback on the page 74 | $page->call( 75 | !is_callable($text) ? $callback : $text 76 | ); 77 | 78 | $this->addPage($page); 79 | 80 | return $page; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/Templates/EngineResolverTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('php', (new EngineResolver('excel.php'))->getEngine()); 11 | $this->assertEquals('smarty', (new EngineResolver('excel.tpl'))->getEngine()); 12 | $this->assertEquals('blade', (new EngineResolver('excel.blade'))->getEngine()); 13 | $this->assertEquals('blade', (new EngineResolver('excel.blade.php'))->getEngine()); 14 | $this->assertEquals('twig', (new EngineResolver('excel.html'))->getEngine()); 15 | } 16 | 17 | public function test_identify_with_passing_the_right_engine() 18 | { 19 | $this->assertEquals('smarty', (new EngineResolver('excel', 'smarty'))->getEngine()); 20 | } 21 | 22 | public function test_overruling_engine_extensions_defaults() 23 | { 24 | Ledger::set('templates.engines.blade', '.laravel'); 25 | $this->assertEquals('blade', (new EngineResolver('excel.laravel'))->getEngine()); 26 | } 27 | 28 | public function test_overruling_engine_extensions_with_multiple_extension_possibilities() 29 | { 30 | Ledger::set('templates.engines.smarty', [ 31 | '.tpl', 32 | '.tmpl', 33 | '.smarty', 34 | ]); 35 | $this->assertEquals('smarty', (new EngineResolver('excel.tpl'))->getEngine()); 36 | $this->assertEquals('smarty', (new EngineResolver('excel.tmpl'))->getEngine()); 37 | $this->assertEquals('smarty', (new EngineResolver('excel.smarty'))->getEngine()); 38 | } 39 | 40 | public function test_identify_based_on_default() 41 | { 42 | $this->assertEquals('php', (new EngineResolver('excel'))->getEngine()); 43 | 44 | Ledger::set('templates.default', 'blade'); 45 | $this->assertEquals('blade', (new EngineResolver('excel'))->getEngine()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/Files/ExcelFileTestCase.php: -------------------------------------------------------------------------------- 1 | class('Workbook title'); 8 | 9 | $this->assertInstanceOf($this->class, $excel); 10 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Workbook', $excel->getWorkbook()); 11 | $this->assertEquals('Workbook title', $excel->getWorkbook()->getTitle()); 12 | } 13 | 14 | public function test_using_the_callback() 15 | { 16 | $excel = new $this->class('Workbook title', function ($workbook) { 17 | $workbook->setTitle('overruled'); 18 | }); 19 | 20 | $this->assertInstanceOf($this->class, $excel); 21 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Workbook', $excel->getWorkbook()); 22 | $this->assertEquals('overruled', $excel->getWorkbook()->getTitle()); 23 | } 24 | 25 | public function test_create_a_new_file() 26 | { 27 | $class = $this->class; 28 | $excel = $class::create('Workbook title', null, ''); 29 | 30 | $this->assertInstanceOf($this->class, $excel); 31 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Workbook', $excel->getWorkbook()); 32 | $this->assertEquals('Workbook title', $excel->getWorkbook()->getTitle()); 33 | } 34 | 35 | public function test_get_extension() 36 | { 37 | $excel = new $this->class('Workbook title'); 38 | $this->assertEquals($this->ext, $excel->getExtension()); 39 | } 40 | 41 | public function test_minimum_amount_of_sheets_needed() 42 | { 43 | $this->setExpectedException('Maatwebsite\Clerk\Exceptions\ExportFailedException'); 44 | $excel = new $this->class('Workbook title'); 45 | $excel->export(); 46 | } 47 | 48 | public function test_load() 49 | { 50 | $class = $this->class; 51 | $excel = $class::load(__DIR__ . '/import/test.' . $this->ext, null, ''); 52 | 53 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Reader', $excel); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/Excel/Identifiers/PHPExcelFormatIdentifierTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('CSV', $identifier->getFormatByExtension('csv')); 11 | $this->assertEquals('Excel5', $identifier->getFormatByExtension('xls')); 12 | $this->assertEquals('Excel2007', $identifier->getFormatByExtension('xlsx')); 13 | $this->assertEquals('HTML', $identifier->getFormatByExtension('html')); 14 | $this->assertEquals('Excel2003XML', $identifier->getFormatByExtension('xml')); 15 | } 16 | 17 | public function test_get_format_by_file() 18 | { 19 | $identifier = new FormatIdentifier(); 20 | $csv = __DIR__ . '/files/test.csv'; 21 | $xls = __DIR__ . '/files/test.xls'; 22 | $xlsx = __DIR__ . '/files/test.xlsx'; 23 | $htm = __DIR__ . '/files/test.htm'; 24 | $xml = __DIR__ . '/files/test.xml'; 25 | 26 | $this->assertEquals('CSV', $identifier->getFormatByFile($csv)); 27 | $this->assertEquals('Excel5', $identifier->getFormatByFile($xls)); 28 | $this->assertEquals('Excel2007', $identifier->getFormatByFile($xlsx)); 29 | $this->assertEquals('HTML', $identifier->getFormatByFile($htm)); 30 | $this->assertEquals('Excel2003XML', $identifier->getFormatByFile($xml)); 31 | } 32 | 33 | public function test_get_content_type_by_format() 34 | { 35 | $identifier = new FormatIdentifier(); 36 | $this->assertContains('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8', $identifier->getContentTypeByFormat('Excel2007')); 37 | $this->assertContains('application/vnd.ms-excel; charset=UTF-8', $identifier->getContentTypeByFormat('Excel5')); 38 | $this->assertContains('application/csv; charset=UTF-8', $identifier->getContentTypeByFormat('CSV')); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Templates/Adapters/Blade/Dispatcher.php: -------------------------------------------------------------------------------- 1 | getSheetCount() < 1) { 29 | throw new ExportFailedException('No sheets are added to your Excel file. Make sure you do so, before attempting to export'); 30 | } 31 | 32 | $class = self::getClassByDriverAndType($driver, $type); 33 | 34 | if (class_exists($class)) { 35 | return new $class($type, $extension, $workbook); 36 | } 37 | 38 | // Default writer 39 | $class = self::getClassByDriver($driver); 40 | 41 | if (class_exists($class)) { 42 | return new $class($type, $extension, $workbook); 43 | } 44 | 45 | throw new DriverNotFoundException("Writer driver [{$driver->getName()}] was not found"); 46 | } 47 | 48 | /** 49 | * @param DriverInterface $driver 50 | * 51 | * @return string 52 | */ 53 | protected static function getClassByDriver(DriverInterface $driver) 54 | { 55 | return $driver->getWriterClass('Excel'); 56 | } 57 | 58 | /** 59 | * @param DriverInterface $driver 60 | * @param $type 61 | * 62 | * @return string 63 | */ 64 | private static function getClassByDriverAndType(DriverInterface $driver, $type) 65 | { 66 | return $driver->getWriterClassByType('Excel', $type); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/Excel/Parsers/PHPExcel/CellTest.php: -------------------------------------------------------------------------------- 1 | mockCell(); 11 | 12 | $this->assertInstanceOf('Maatwebsite\Clerk\Excel\Adapters\PHPExcel\Cell', $cell); 13 | $this->assertInstanceOf('\PHPExcel_Cell', $cell->getCell()); 14 | } 15 | 16 | public function test_getting_value() 17 | { 18 | $cell = $this->mockCell(); 19 | $this->assertEquals('text', $cell->getValue()); 20 | $this->assertEquals('text', (string) $cell); 21 | } 22 | 23 | public function test_getting_calculated_value() 24 | { 25 | $cell = $this->mockCell('=1+1'); 26 | $this->assertEquals('2', $cell->getCalculatedValue()); 27 | $this->assertEquals('2', (string) $cell); 28 | } 29 | 30 | public function test_getting_date_value() 31 | { 32 | $settings = new ParserSettings(); 33 | 34 | $cell = $this->mockCell('39682'); 35 | $this->assertInstanceOf('Carbon\Carbon', $cell->getDateValue()); 36 | 37 | $settings->setNeedsDateFormatting(false); 38 | $cell = $this->mockCell('39682', $settings); 39 | $this->assertEquals('39682', $cell->getDateValue()); 40 | 41 | $settings->setNeedsDateFormatting(true); 42 | $settings->setDateFormat('d-m-Y'); 43 | $cell = $this->mockCell('39682', $settings); 44 | $this->assertEquals('22-08-2008', $cell->getDateValue()); 45 | } 46 | 47 | /** 48 | * @param string $text 49 | * 50 | * @return Cell 51 | */ 52 | protected function mockCell($text = 'text', $settings = false) 53 | { 54 | $workbook = new \PHPExcel(); 55 | $workbook->disconnectWorksheets(); 56 | 57 | $worksheet = new \PHPExcel_Worksheet($workbook); 58 | $workbook->addSheet($worksheet); 59 | 60 | $cell = $worksheet->setCellValue('A1', $pValue = $text, $returnCell = true); 61 | 62 | $settings = $settings ?: new ParserSettings(); 63 | $cell = new Cell($cell, 1, $settings); 64 | 65 | return $cell; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Excel/Readers/ReaderFactory.php: -------------------------------------------------------------------------------- 1 | getName()}] was not found"); 42 | } 43 | 44 | /** 45 | * @param DriverInterface $driver 46 | * 47 | * @return string 48 | */ 49 | protected static function getDefaultClass(DriverInterface $driver) 50 | { 51 | return $driver->getReaderClass('Excel'); 52 | } 53 | 54 | /** 55 | * Get a specific reader. 56 | * 57 | * @param DriverInterface $driver 58 | * @param $type 59 | * 60 | * @return string 61 | */ 62 | protected static function getClassByDriverAndType(DriverInterface $driver, $type) 63 | { 64 | return $driver->getReaderClassByType('Excel', $type); 65 | } 66 | 67 | /** 68 | * @param $file 69 | * 70 | * @return string 71 | */ 72 | protected static function getTypeByFile($file) 73 | { 74 | return (new FormatIdentifier())->getFormatByFile($file); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Excel/Cells/Coordinate.php: -------------------------------------------------------------------------------- 1 | setColumn($column); 29 | $this->setRow($row); 30 | } 31 | 32 | /** 33 | * @param $coordinate 34 | * 35 | * @return static 36 | */ 37 | public static function fromString($coordinate) 38 | { 39 | $instance = new static(); 40 | 41 | if ($coordinate) { 42 | preg_match(self::$regex, $coordinate, $matches); 43 | array_shift($matches); 44 | list($column, $row) = $matches; 45 | 46 | $instance->setColumn($column); 47 | $instance->setRow($row); 48 | } 49 | 50 | return $instance; 51 | } 52 | 53 | /** 54 | * @return null|string 55 | */ 56 | public function getColumn() 57 | { 58 | return $this->column; 59 | } 60 | 61 | /** 62 | * @param null|string $column 63 | */ 64 | public function setColumn($column) 65 | { 66 | $this->column = strtoupper($column); 67 | } 68 | 69 | /** 70 | * @return int|null 71 | */ 72 | public function getRow() 73 | { 74 | return $this->row; 75 | } 76 | 77 | /** 78 | * @param int|null $row 79 | */ 80 | public function setRow($row) 81 | { 82 | $this->row = $row; 83 | } 84 | 85 | /** 86 | * Get the coordinate. 87 | * 88 | * @return string 89 | */ 90 | public function get() 91 | { 92 | return (string) $this->getColumn() . $this->getRow(); 93 | } 94 | 95 | /** 96 | * @return string 97 | */ 98 | public function __toString() 99 | { 100 | return (string) $this->get(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Pdf/Adapters/Snappy/Document.php: -------------------------------------------------------------------------------- 1 | driver = $driver ?: new Snappy( 32 | Ledger::get('pdf.snappy.binary'), 33 | Ledger::get('pdf.snappy.options', []) 34 | ); 35 | 36 | if ($timeout = Ledger::get('pdf.snappy.timeout', false)) { 37 | $this->driver->setTimeout($timeout); 38 | } 39 | 40 | parent::__construct($title, $callback); 41 | } 42 | 43 | /** 44 | * Set title. 45 | * 46 | * @param string $title 47 | * 48 | * @return $this 49 | */ 50 | public function setTitle($title) 51 | { 52 | //$this->getDriver()->getDocInfo()->setTitle($title); 53 | 54 | return $this; 55 | } 56 | 57 | /** 58 | * @return string 59 | */ 60 | public function getTitle() 61 | { 62 | //return $this->getDriver()->getDocInfo()->getTitle(); 63 | } 64 | 65 | /** 66 | * Init a new page. 67 | * 68 | * @param $text 69 | * @param Closure $callback 70 | * 71 | * @return Page 72 | */ 73 | public function page($text = null, Closure $callback = null) 74 | { 75 | // Init a new page 76 | $page = new Page( 77 | !is_callable($text) ? $text : null, 78 | $this 79 | ); 80 | 81 | // Preform callback on the page 82 | $page->call( 83 | !is_callable($text) ? $callback : $text 84 | ); 85 | 86 | $this->addPage($page); 87 | 88 | return $page; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Templates/Adapters/Blade/BladeEngine.php: -------------------------------------------------------------------------------- 1 | files = new FileSystem(); 43 | $this->viewPaths = (array) $viewPaths; 44 | $this->cachePath = $cachePath; 45 | } 46 | 47 | /** 48 | * Get the factory. 49 | */ 50 | public function getFactory() 51 | { 52 | $resolver = $this->getEngineResolver(); 53 | 54 | $finder = new FileViewFinder( 55 | $this->files, 56 | $this->viewPaths 57 | ); 58 | 59 | return new Factory( 60 | $resolver, 61 | $finder, 62 | new Dispatcher() 63 | ); 64 | } 65 | 66 | /** 67 | * Register the engine resolver instance. 68 | * 69 | * @return EngineResolver 70 | */ 71 | public function getEngineResolver() 72 | { 73 | $resolver = new EngineResolver(); 74 | 75 | // Add PhpEngine 76 | $resolver->register('php', function () { 77 | return new PhpEngine(); 78 | }); 79 | 80 | // Add Blade compiler engine 81 | $resolver->register('blade', function () { 82 | $compiler = new BladeCompiler( 83 | $this->files, 84 | $this->cachePath 85 | ); 86 | 87 | return new CompilerEngine( 88 | $compiler 89 | ); 90 | }); 91 | 92 | return $resolver; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Excel/Cells/DataType.php: -------------------------------------------------------------------------------- 1 | setType($type); 47 | } 48 | } 49 | 50 | /** 51 | * @param string $type 52 | * 53 | * @throws InvalidArgumentException 54 | * 55 | * @return $this 56 | */ 57 | public function setType($type) 58 | { 59 | if (!in_array($type, $this->getDataTypes())) { 60 | throw new InvalidArgumentException('The parameter must belong to the Data Type parameter list'); 61 | } 62 | 63 | $this->type = $type; 64 | 65 | return $this; 66 | } 67 | 68 | /** 69 | * @return string 70 | */ 71 | public function getType() 72 | { 73 | return $this->type; 74 | } 75 | 76 | /** 77 | * Return the types parameter list. 78 | * 79 | * @return array 80 | */ 81 | public function getDataTypes() 82 | { 83 | return [ 84 | self::STRING2, 85 | self::STRING, 86 | self::FORMULA, 87 | self::NUMERIC, 88 | self::NUMERIC_00, 89 | self::BOOL, 90 | self::NULL, 91 | self::INLINE, 92 | self::ERROR, 93 | self::PERCENT, 94 | self::DATETIME, 95 | self::DATE, 96 | self::PERCENT_00, 97 | ]; 98 | } 99 | 100 | /** 101 | * @return string 102 | */ 103 | public function __toString() 104 | { 105 | return (string) $this->getType(); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Files/Word.php: -------------------------------------------------------------------------------- 1 | document = DocumentFactory::create($this->getDriver('writer'), $title, $callback); 37 | } 38 | 39 | /** 40 | * Create new file. 41 | * 42 | * @param string $filename 43 | * @param Closure $callback 44 | * 45 | * @return static 46 | */ 47 | public static function create($filename, Closure $callback = null) 48 | { 49 | return new static($filename, $callback); 50 | } 51 | 52 | /** 53 | * Create new file. 54 | * 55 | * @param string $file 56 | * @param Closure $callback 57 | * @param null $format 58 | * 59 | * @throws \Maatwebsite\Clerk\Exceptions\DriverNotFoundException 60 | * @return \Maatwebsite\Clerk\Reader 61 | */ 62 | public static function load($file, Closure $callback = null, $format = null) 63 | { 64 | } 65 | 66 | /** 67 | * @throws \Maatwebsite\Clerk\Exceptions\DriverNotFoundException 68 | * @return \Maatwebsite\Clerk\Writer 69 | */ 70 | public function initWriter() 71 | { 72 | $writer = WriterFactory::create( 73 | $this->getDriver('writer'), 74 | $this->getFormat(), 75 | $this->getExtension(), 76 | $this->getDocument() 77 | ); 78 | 79 | return $writer; 80 | } 81 | 82 | /** 83 | * @return \Maatwebsite\Clerk\Word\Document 84 | */ 85 | public function getDocument() 86 | { 87 | return $this->document; 88 | } 89 | 90 | /** 91 | * Get the driver. 92 | * 93 | * @param $type 94 | * 95 | * @return mixed 96 | */ 97 | protected function getDriver($type) 98 | { 99 | return Ledger::resolve('drivers.' . $type . '.word2003', 'PHPWord'); 100 | } 101 | } 102 | --------------------------------------------------------------------------------