diff --git a/src/Spout/Writer/ODS/Internal/Worksheet.php b/src/Spout/Writer/ODS/Internal/Worksheet.php index 3a65726c..f0544f06 100644 --- a/src/Spout/Writer/ODS/Internal/Worksheet.php +++ b/src/Spout/Writer/ODS/Internal/Worksheet.php @@ -218,6 +218,10 @@ protected function getCellContent($cellValue, $styleIndex, $numTimesValueRepeate */ public function close() { + if (!is_resource($this->sheetFilePointer)) { + return; + } + fclose($this->sheetFilePointer); } } diff --git a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php index a17493a9..9d9639db 100644 --- a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php +++ b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php @@ -88,6 +88,10 @@ public function writeString($string) */ public function close() { + if (!is_resource($this->sharedStringsFilePointer)) { + return; + } + fwrite($this->sharedStringsFilePointer, ''); // Replace the default strings count with the actual number of shared strings in the file header diff --git a/src/Spout/Writer/XLSX/Internal/Worksheet.php b/src/Spout/Writer/XLSX/Internal/Worksheet.php index 3ffd97b6..af3fbc41 100644 --- a/src/Spout/Writer/XLSX/Internal/Worksheet.php +++ b/src/Spout/Writer/XLSX/Internal/Worksheet.php @@ -178,6 +178,10 @@ public function addRow($dataRow, $style) */ public function close() { + if (!is_resource($this->sheetFilePointer)) { + return; + } + fwrite($this->sheetFilePointer, ''); fwrite($this->sheetFilePointer, ''); fclose($this->sheetFilePointer);