/** * Save PHPExcel to file * * @param string $pFilename * @throws Exception */ public function save($pFilename = null) { // Fetch sheet $sheet = $this->phpExcel->getSheet($this->sheetIndex); $saveDebugLog = \PHPExcel\Calculation::getInstance($this->phpExcel)->getDebugLog()->getWriteDebugLog(); \PHPExcel\Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog(false); $saveArrayReturnType = \PHPExcel\Calculation::getArrayReturnType(); \PHPExcel\Calculation::setArrayReturnType(\PHPExcel\Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'wb+'); if ($fileHandle === false) { throw new Exception("Could not open file {$pFilename} for writing."); } if ($this->excelCompatibility) { $this->setUseBOM(true); // Enforce UTF-8 BOM Header $this->setIncludeSeparatorLine(true); // Set separator line $this->setEnclosure('"'); // Set enclosure to " $this->setDelimiter(";"); // Set delimiter to a semi-colon $this->setLineEnding("\r\n"); } if ($this->useBOM) { // Write the UTF-8 BOM code if required fwrite($fileHandle, ""); } if ($this->includeSeparatorLine) { // Write the separator line if required fwrite($fileHandle, 'sep=' . $this->getDelimiter() . $this->lineEnding); } // Identify the range that we need to extract from the worksheet $maxCol = $sheet->getHighestDataColumn(); $maxRow = $sheet->getHighestDataRow(); // Write rows to file for ($row = 1; $row <= $maxRow; ++$row) { // Convert the row to an array... $cellsArray = $sheet->rangeToArray('A' . $row . ':' . $maxCol . $row, '', $this->preCalculateFormulas); // ... and write to the file $this->writeLine($fileHandle, $cellsArray[0]); } // Close file fclose($fileHandle); \PHPExcel\Calculation::setArrayReturnType($saveArrayReturnType); \PHPExcel\Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog); }
/** * Save PHPExcel to file * * @param string $pFilename * @throws \PHPExcel\Writer\Exception */ public function save($pFilename = null) { // garbage collect $this->phpExcel->garbageCollect(); $saveDebugLog = Calculation::getInstance($this->phpExcel)->getDebugLog()->getWriteDebugLog(); Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog(false); $saveArrayReturnType = Calculation::getArrayReturnType(); Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Build CSS $this->buildCSS(!$this->useInlineCss); // Open file $fileHandle = fopen($pFilename, 'wb+'); if ($fileHandle === false) { throw new \PHPExcel\Writer\Exception("Could not open file {$pFilename} for writing."); } // Write headers fwrite($fileHandle, $this->generateHTMLHeader(!$this->useInlineCss)); // Write navigation (tabs) if (!$this->isPdf && $this->generateSheetNavigationBlock) { fwrite($fileHandle, $this->generateNavigation()); } // Write data fwrite($fileHandle, $this->generateSheetData()); // Write footer fwrite($fileHandle, $this->generateHTMLFooter()); // Close file fclose($fileHandle); Calculation::setArrayReturnType($saveArrayReturnType); Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog); }