diff --git a/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php b/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php index 07c29253..61f86c69 100644 --- a/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php +++ b/modules/EcommerceFinance/Services/PayablesWorkbookStreamReader.php @@ -89,21 +89,12 @@ class PayablesWorkbookStreamReader return; } - $zip = new ZipArchive(); - if ($zip->open($this->path) !== true) { - throw new RuntimeException('无法打开工作簿。'); + $reader = new XMLReader(); + if (! $reader->open('zip://' . $this->path . '#' . $path, null, LIBXML_NONET)) { + throw new RuntimeException('无法打开工作表。'); } try { - $stream = $zip->getStream($path); - if ($stream === false) { - return; - } - - $reader = new XMLReader(); - $reader->XML(stream_get_contents($stream), null, LIBXML_NONET); - fclose($stream); - $dictionary = $this->xlsxSharedStrings(); $rowNumber = 0; @@ -125,7 +116,7 @@ class PayablesWorkbookStreamReader yield $rowNumber => $this->readRow($reader, $dictionary); } } finally { - $zip->close(); + $reader->close(); } } @@ -467,21 +458,13 @@ class PayablesWorkbookStreamReader return [$this->sharedStrings, $this->sharedStringOffsets]; } - $zip = new ZipArchive(); - if ($zip->open($this->path) !== true) { - throw new RuntimeException('无法打开工作簿。'); + $blob = ''; + $reader = new XMLReader(); + if (! @$reader->open('zip://' . $this->path . '#xl/sharedStrings.xml', null, LIBXML_NONET)) { + return [$this->sharedStrings = '', $this->sharedStringOffsets = new SplFixedArray(1)]; } - $blob = ''; try { - $xml = $zip->getFromName('xl/sharedStrings.xml'); - if ($xml === false) { - return [$this->sharedStrings = '', $this->sharedStringOffsets = new SplFixedArray(1)]; - } - - $reader = new XMLReader(); - $reader->XML($xml, null, LIBXML_NONET); - $count = 0; $offsets = new SplFixedArray(1024); $offsets[0] = 0; @@ -517,10 +500,9 @@ class PayablesWorkbookStreamReader } } - $reader->close(); $offsets->setSize($count + 1); } finally { - $zip->close(); + $reader->close(); } return [$this->sharedStrings = $blob, $this->sharedStringOffsets = $offsets];