ExcelAnt\Adapter\PhpExcel\Writer\Writer::convert PHP Method

convert() public method

public convert ( ExcelAnt\Workbook\WorkbookInterface $workbook )
$workbook ExcelAnt\Workbook\WorkbookInterface
    public function convert(WorkbookInterface $workbook)
    {
        $phpExcel = $workbook->getRawClass();
        // Apply default workbook styles
        if ($workbook->hasStyles()) {
            $styles = $this->styleWorker->convertStyles($workbook->getStyles());
            $phpExcel->getDefaultStyle()->applyFromArray($styles);
        }
        foreach ($workbook->getAllSheets() as $sheet) {
            $phpExcelWorksheet = $sheet->getRawClass();
            $phpExcel->addSheet($phpExcelWorksheet);
            // Write the tables
            foreach ($sheet->getTables() as $table) {
                $this->tableWorker->writeTable($phpExcelWorksheet, $table);
            }
            // Write the individuals cells
            foreach ($sheet->getCells() as $cell) {
                $this->cellWorker->writeCell($cell, $phpExcelWorksheet, $cell->getCoordinate());
            }
        }
        $phpExcel->setActiveSheetIndex(0);
        return $phpExcel;
    }

Usage Example

Beispiel #1
0
 public function testApplyTheStylesOfTheWorkbook()
 {
     $phpExcelStyle = $this->getPhpExcelStyleMock();
     $phpExcelStyle->expects($this->once())->method('applyFromArray');
     $phpExcel = $this->getPhpExcelMock();
     $phpExcel->expects($this->once())->method('getDefaultStyle')->will($this->returnValue($phpExcelStyle));
     $workbook = $this->createWorkbook($phpExcel);
     $workbook->addStyles(new StyleCollection([new Fill(), new Font()]));
     $styleWorker = $this->getStyleWorkerMock();
     $styleWorker->expects($this->once())->method('convertStyles');
     $writer = new Writer($this->getPhpExcelWriterInterfaceMock(), $this->getTableWorkerMock(), $this->getCellWorkerMock(), $styleWorker);
     $phpExcel = $writer->convert($workbook);
     $this->assertInstanceOf('PHPExcel', $phpExcel);
 }
All Usage Examples Of ExcelAnt\Adapter\PhpExcel\Writer\Writer::convert