protected function createExcel()
    {
        $this->phpexcel = new \PHPExcel();
        $tableNumber = 0;

        // Loop over all tables in document
        foreach($this->document->getTables() as $table){

            // Handle worksheets
            if ($tableNumber > 0) {
                $this->phpexcel->createSheet();
            }
            $excelWorksheet = $this->phpexcel->setActiveSheetIndex($tableNumber);
            if ($sheetTitle = $table->getAttribute('_excel-name')) {
                $excelWorksheet->setTitle($sheetTitle);
            }

            // Loop over all rows
            $rowNumber = 1;
            foreach($table->getRows() as $row){

                $excelWorksheet->getStyle($rowNumber.':'.$rowNumber)->applyFromArray($this->getRowStylesArray($row));
                $this->setDimensions($excelWorksheet, $excelWorksheet->getRowIterator($rowNumber)->current(), $row);

                // Loop over all cells in row
                $cellNumber = 0;
                foreach($row->getCells() as $cell){
                    $excelCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber).$rowNumber;
                    
                    // Skip cells withing merge range
                    while ($excelWorksheet->getCell($excelCellIndex)->isInMergeRange()) {
                        $cellNumber++;
                        $excelCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber).$rowNumber;
                    }
                    
                    // Set value
                    $explicitCellType = $cell->getAttribute('_excel-explicit');
                    if (!$explicitCellType) {
                        $explicitCellType = $row->getAttribute('_excel-explicit');
                    }

                    if ($explicitCellType) {
                        $excelWorksheet->setCellValueExplicit(
                            $excelCellIndex,
                            $this->changeValueEncoding($cell->getValue()),
                            $this->convertStaticPhpExcelConstantsFromStringsToConstants($explicitCellType)
                        );
                    } else {
                        $excelWorksheet->setCellValue(
                            $excelCellIndex,
                            $this->changeValueEncoding($cell->getValue())
                        );
                    }

                    // Merge cells
                    $colspan = $cell->getAttribute('colspan');
                    $rowspan = $cell->getAttribute('rowspan');

                    if ($colspan || $rowspan) {
                        if ($colspan) {$colspan = $colspan - 1;}
                        if ($rowspan) {$rowspan = $rowspan - 1;}
                        $mergeCellsTargetCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber + $colspan).($rowNumber + $rowspan);
                        $excelWorksheet->mergeCells($excelCellIndex.':'.$mergeCellsTargetCellIndex);
                    }

                    // Set styles
                    $excelWorksheet->getStyle($excelCellIndex)->applyFromArray($this->getCellStylesArray($cell));
                    $this->setDimensions($excelWorksheet, $excelWorksheet->getCell($excelCellIndex), $cell);

                    $cellNumber++;
                }

                $rowNumber++;
            }

            $tableNumber++;
        }

        return $this->phpexcel;
    }
protected function createExcel()
    {
        $this->phpexcel = new \PHPExcel();
        $tableNumber = 0;

        // Loop over all tables in document
        foreach($this->document->getTables() as $table){

            // Handle worksheets
            if ($tableNumber > 0) {
                $this->phpexcel->createSheet();
            }
            $excelWorksheet = $this->phpexcel->setActiveSheetIndex($tableNumber);
            if ($sheetTitle = $table->getAttribute('_excel-name')) {
                $excelWorksheet->setTitle($sheetTitle);
            }

            // Loop over all rows
            $rowNumber = 1;
            foreach($table->getRows() as $row){

                $excelWorksheet->getStyle($rowNumber.':'.$rowNumber)->applyFromArray($this->getRowStylesArray($row));
                $this->setDimensions($excelWorksheet, $excelWorksheet->getRowIterator($rowNumber)->current(), $row);

                // Loop over all cells in row
                $cellNumber = 0;
                foreach($row->getCells() as $cell){
                    $excelCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber).$rowNumber;
                    
                    // Skip cells withing merge range
                    while ($excelWorksheet->getCell($excelCellIndex)->isInMergeRange()) {
                        $cellNumber++;
                        $excelCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber).$rowNumber;
                    }
                    
                    // Set value
                    $explicitCellType = $cell->getAttribute('_excel-explicit');
                    if (!$explicitCellType) {
                        $explicitCellType = $row->getAttribute('_excel-explicit');
                    }

                    if ($explicitCellType) {
                        $excelWorksheet->setCellValueExplicit(
                            $excelCellIndex,
                            $this->changeValueEncoding($cell->getValue()),
                            $this->convertStaticPhpExcelConstantsFromStringsToConstants($explicitCellType)
                        );
                    } else {
                        $excelWorksheet->setCellValue(
                            $excelCellIndex,
                            $this->changeValueEncoding($cell->getValue())
                        );
                    }

                    // Merge cells
                    $colspan = $cell->getAttribute('colspan');
                    $rowspan = $cell->getAttribute('rowspan');

                    if ($colspan || $rowspan) {
                        if ($colspan) {$colspan = $colspan - 1;}
                        if ($rowspan) {$rowspan = $rowspan - 1;}
                        $mergeCellsTargetCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber + $colspan).($rowNumber + $rowspan);
                        $excelWorksheet->mergeCells($excelCellIndex.':'.$mergeCellsTargetCellIndex);
                    }

                    // Set styles
                    $excelWorksheet->getStyle($excelCellIndex)->applyFromArray($this->getCellStylesArray($cell));
                    $this->setDimensions($excelWorksheet, $excelWorksheet->getCell($excelCellIndex), $cell);

                    $cellNumber++;
                }

                $rowNumber++;
            }

            $tableNumber++;
        }

        return $this->phpexcel;
    }
protected function createExcel ( ) { $ this -> phpexcel = new \ PHPExcel ( ) ; $ tableNumber = 0 ; // Loop over all tables in document foreach ( $ this -> document -> getTables ( ) as $ table ) { // Handle worksheets if ( $ tableNumber > 0 ) { $ this -> phpexcel -> createSheet ( ) ; } $ excelWorksheet = $ this -> phpexcel -> setActiveSheetIndex ( $ tableNumber ) ; if ( $ sheetTitle = $ table -> getAttribute ( '_excel-name' ) ) { $ excelWorksheet -> setTitle ( $ sheetTitle ) ; } // Loop over all rows $ rowNumber = 1 ; foreach ( $ table -> getRows ( ) as $ row ) { $ excelWorksheet -> getStyle ( $ rowNumber . ':' . $ rowNumber ) -> applyFromArray ( $ this -> getRowStylesArray ( $ row ) ) ; $ this -> setDimensions ( $ excelWorksheet , $ excelWorksheet -> getRowIterator ( $ rowNumber ) -> current ( ) , $ row ) ; // Loop over all cells in row $ cellNumber = 0 ; foreach ( $ row -> getCells ( ) as $ cell ) { $ excelCellIndex = \ PHPExcel_Cell :: stringFromColumnIndex ( $ cellNumber ) . $ rowNumber ; // Skip cells withing merge range while ( $ excelWorksheet -> getCell ( $ excelCellIndex ) -> isInMergeRange ( ) ) { $ cellNumber ++ ; $ excelCellIndex = \ PHPExcel_Cell :: stringFromColumnIndex ( $ cellNumber ) . $ rowNumber ; } // Set value $ explicitCellType = $ cell -> getAttribute ( '_excel-explicit' ) ; if ( ! $ explicitCellType ) { $ explicitCellType = $ row -> getAttribute ( '_excel-explicit' ) ; } if ( $ explicitCellType ) { $ excelWorksheet -> setCellValueExplicit ( $ excelCellIndex , $ this -> changeValueEncoding ( $ cell -> getValue ( ) ) , $ this -> convertStaticPhpExcelConstantsFromStringsToConstants ( $ explicitCellType ) ) ; } else { $ excelWorksheet -> setCellValue ( $ excelCellIndex , $ this -> changeValueEncoding ( $ cell -> getValue ( ) ) ) ; } // Merge cells $ colspan = $ cell -> getAttribute ( 'colspan' ) ; $ rowspan = $ cell -> getAttribute ( 'rowspan' ) ; if ( $ colspan || $ rowspan ) { if ( $ colspan ) { $ colspan = $ colspan - 1 ; } if ( $ rowspan ) { $ rowspan = $ rowspan - 1 ; } $ mergeCellsTargetCellIndex = \ PHPExcel_Cell :: stringFromColumnIndex ( $ cellNumber + $ colspan ) . ( $ rowNumber + $ rowspan ) ; $ excelWorksheet -> mergeCells ( $ excelCellIndex . ':' . $ mergeCellsTargetCellIndex ) ; } // Set styles $ excelWorksheet -> getStyle ( $ excelCellIndex ) -> applyFromArray ( $ this -> getCellStylesArray ( $ cell ) ) ; $ this -> setDimensions ( $ excelWorksheet , $ excelWorksheet -> getCell ( $ excelCellIndex ) , $ cell ) ; $ cellNumber ++ ; } $ rowNumber ++ ; } $ tableNumber ++ ; } return $ this -> phpexcel ; }
Create excel from document

@return \PHPExcel
Create excel from document