ExcelAnt\Adapter\PhpExcel\Workbook\Workbook::addSheet PHP Метод

addSheet() публичный Метод

public addSheet ( ExcelAnt\Sheet\SheetInterface $sheet, $index = null, $insert = false )
$sheet ExcelAnt\Sheet\SheetInterface
    public function addSheet(SheetInterface $sheet, $index = null, $insert = false)
    {
        if (isset($index)) {
            if (false === filter_var($index, FILTER_VALIDATE_INT)) {
                throw new \InvalidArgumentException("The index must be numeric");
            }
            if (false === $insert) {
                $this->sheetCollection[$index] = $sheet;
                return $this;
            }
            if (true === $insert) {
                $array1 = array_slice($this->sheetCollection, 0, $index);
                $array1[] = $sheet;
                $array2 = array_slice($this->sheetCollection, $index);
                $this->sheetCollection = array_merge($array1, $array2);
                return $this;
            }
        }
        $this->sheetCollection[] = $sheet;
        return $this;
    }

Usage Example

Пример #1
0
 /** {@inheritdoc} */
 public function create($path, array $firstRow, $sheetName = '')
 {
     $workbook = new Workbook();
     $sheet = new Sheet($workbook);
     $table = new Table();
     $table->setRow($firstRow);
     $sheet->addTable($table, new Coordinate(1, 1));
     $workbook->addSheet($sheet);
     $writerFactory = new WriterFactory();
     $writer = $writerFactory->createWriter(new Excel5($path));
     $phpExcel = $writer->convert($workbook);
     $writer->write($phpExcel);
 }