/** * Add a new worksheet to the Excel workbook. * If no name is given the name of the worksheet will be Sheeti$i, with * $i in [1..]. * * @param string $name the optional name of the worksheet * @throws \Exception * @return Worksheet */ public function addWorksheet($name = '') { $index = count($this->worksheets); if ($name == '') { $name = 'Sheet' . ($index + 1); } $this->checkSheetName($name); if ($this->hasSheet($name)) { throw new \Exception("Worksheet '{$name}' already exists"); } $worksheet = new Worksheet($name, $index, $this, $this->sst, $this->urlFormat, $this->formulaParser); $this->worksheets[$index] = $worksheet; $this->sheetNames[$index] = $name; if (count($this->worksheets) == 1) { $this->setActiveSheetIndex(0); } // Register worksheet name with parser $this->formulaParser->addSheet($name, $index); $this->formulaParser->addRef($index, $index); return $worksheet; }