From 12250fd26d5903598b98005712af427a7e1dd44f Mon Sep 17 00:00:00 2001 From: viest <986465329@qq.com> Date: Mon, 13 Nov 2017 12:16:41 +0800 Subject: [PATCH] fix:result error resourceToArray method 1:avoid `Undefined offset` error; 2:result array to add the header values; --- src/Writer/ExcelWriter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Writer/ExcelWriter.php b/src/Writer/ExcelWriter.php index 09dda99..bc0cc84 100755 --- a/src/Writer/ExcelWriter.php +++ b/src/Writer/ExcelWriter.php @@ -67,12 +67,14 @@ public function resourceToArray() try { $reader = IOFactory::load($this->data); $worksheet = $reader->getActiveSheet()->toArray(); - array_shift($worksheet); + $tableHeader = array_shift($worksheet); $retval = []; if (isset($this->config['table_header'])) { foreach ($worksheet as $dataKey => $data) { foreach ($data as $itemKey => $item) { - $retval[$dataKey][$this->config['table_header'][$itemKey]] = $item; + if(in_array($tableHeader[$itemKey], $this->config['table_header'])) { + $retval[$dataKey][$tableHeader[$itemKey]] = $item; + } } } } else {