/**
  * Attach the data table to an existing xlsx file. The file location is given via the
  * first parameter. If a second parameter is given the source file will not be overwritten
  * and a new file will be created.
  *
  * @param string srcFilename
  * @param string|null targetFilename
  * @return $this
  */
 public function attachToFile($srcFilename, $targetFilename = null)
 {
     $xlsx = new ExcelWorkbook($srcFilename);
     $worksheet = new ExcelWorksheet();
     if (!is_null($targetFilename)) {
         $xlsx->setFilename($targetFilename);
     }
     $worksheet->addRows($this->toArray());
     $xlsx->addWorksheet($worksheet, $this->sheetId, $this->sheetName)->save();
     unset($xlsx);
     return $this;
 }
Esempio n. 2
0
 /**
  * Attach the data table to an existing xlsx file. The file location is given via the
  * first parameter. If a second parameter is given the source file will not be overwritten
  * and a new file will be created. The third parameter can be used to force updating the
  * auto calculation in the excel workbook.
  *
  * @param string srcFilename
  * @param string|null targetFilename
  * @param bool|null forceAutoCalculation
  * @return $this
  */
 public function attachToFile($srcFilename, $targetFilename = null, $forceAutoCalculation = false)
 {
     $calculatedColumns = null;
     if ($this->preserveFormulas) {
         $temp_xlsx = new ExcelWorkbook($srcFilename);
         $calculatedColumns = $temp_xlsx->getCalculatedColumns($this->preserveFormulas);
         unset($temp_xlsx);
     }
     $xlsx = new ExcelWorkbook($srcFilename);
     $worksheet = new ExcelWorksheet();
     if (!is_null($targetFilename)) {
         $xlsx->setFilename($targetFilename);
     }
     $worksheet->addRows($this->toArray(), $calculatedColumns);
     $xlsx->addWorksheet($worksheet, $this->sheetId, $this->sheetName);
     if ($forceAutoCalculation) {
         $xlsx->enableAutoCalculation();
     }
     if ($this->refreshTableRange) {
         $xlsx->refreshTableRange($this->refreshTableRange, count($this->data) + 1);
     }
     $xlsx->save();
     unset($xlsx);
     return $this;
 }