diff --git a/composer.lock b/composer.lock index 0335a09..e393c12 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "689ecd635903f4de2a331d98d5ded1b1", + "content-hash": "befca454a1bbc9e453ece4f5af8e8b0d", "packages": [ { "name": "markbaker/complex", - "version": "1.4.6", + "version": "1.4.7", "source": { "type": "git", "url": "https://github.com/MarkBaker/PHPComplex.git", - "reference": "a78d82ae4e682c3809fc3023d1b0ce654f6ab12b" + "reference": "1ea674a8308baf547cbcbd30c5fcd6d301b7c000" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/a78d82ae4e682c3809fc3023d1b0ce654f6ab12b", - "reference": "a78d82ae4e682c3809fc3023d1b0ce654f6ab12b", + "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/1ea674a8308baf547cbcbd30c5fcd6d301b7c000", + "reference": "1ea674a8308baf547cbcbd30c5fcd6d301b7c000", "shasum": "" }, "require": { @@ -99,25 +99,95 @@ "complex", "mathematics" ], - "time": "2018-07-31T08:38:40+00:00" + "time": "2018-10-13T23:28:42+00:00" + }, + { + "name": "markbaker/matrix", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/MarkBaker/PHPMatrix.git", + "reference": "5348c5a67e3b75cd209d70103f916a93b1f1ed21" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/5348c5a67e3b75cd209d70103f916a93b1f1ed21", + "reference": "5348c5a67e3b75cd209d70103f916a93b1f1ed21", + "shasum": "" + }, + "require": { + "php": "^5.6.0|^7.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "dev-master", + "phpcompatibility/php-compatibility": "dev-master", + "phploc/phploc": "^4", + "phpmd/phpmd": "dev-master", + "phpunit/phpunit": "^5.7", + "sebastian/phpcpd": "^3.0", + "squizlabs/php_codesniffer": "^3.0@dev" + }, + "type": "library", + "autoload": { + "psr-4": { + "Matrix\\": "classes/src/" + }, + "files": [ + "classes/src/functions/adjoint.php", + "classes/src/functions/antidiagonal.php", + "classes/src/functions/cofactors.php", + "classes/src/functions/determinant.php", + "classes/src/functions/diagonal.php", + "classes/src/functions/identity.php", + "classes/src/functions/inverse.php", + "classes/src/functions/minors.php", + "classes/src/functions/trace.php", + "classes/src/functions/transpose.php", + "classes/src/operations/add.php", + "classes/src/operations/directsum.php", + "classes/src/operations/subtract.php", + "classes/src/operations/multiply.php", + "classes/src/operations/divideby.php", + "classes/src/operations/divideinto.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Baker", + "email": "mark@lange.demon.co.uk" + } + ], + "description": "PHP Class for working with matrices", + "homepage": "https://github.com/MarkBaker/PHPMatrix", + "keywords": [ + "mathematics", + "matrix", + "vector" + ], + "time": "2019-10-06T11:29:25+00:00" }, { "name": "phpoffice/phpspreadsheet", - "version": "1.4.0", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/PHPOffice/PhpSpreadsheet.git", - "reference": "125f462a718956f37d81305ca0df4f17cef0f3b9" + "reference": "f734783d826bd84c3d54fcf7b71c37ab9bac4b04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/125f462a718956f37d81305ca0df4f17cef0f3b9", - "reference": "125f462a718956f37d81305ca0df4f17cef0f3b9", + "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/f734783d826bd84c3d54fcf7b71c37ab9bac4b04", + "reference": "f734783d826bd84c3d54fcf7b71c37ab9bac4b04", "shasum": "" }, "require": { "ext-ctype": "*", "ext-dom": "*", + "ext-fileinfo": "*", "ext-gd": "*", "ext-iconv": "*", "ext-libxml": "*", @@ -128,24 +198,26 @@ "ext-xmlwriter": "*", "ext-zip": "*", "ext-zlib": "*", - "markbaker/complex": "^1.4.1", - "php": "^5.6|^7.0", + "markbaker/complex": "^1.4", + "markbaker/matrix": "^1.2", + "php": "^7.1", "psr/simple-cache": "^1.0" }, "require-dev": { - "dompdf/dompdf": "^0.8.0", - "friendsofphp/php-cs-fixer": "@stable", + "dompdf/dompdf": "^0.8.3", + "friendsofphp/php-cs-fixer": "^2.16", "jpgraph/jpgraph": "^4.0", - "mpdf/mpdf": "^7.0.0", - "phpunit/phpunit": "^5.7", - "squizlabs/php_codesniffer": "^3.3", - "tecnickcom/tcpdf": "^6.2" + "mpdf/mpdf": "^8.0", + "phpcompatibility/php-compatibility": "^9.3", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "^3.5", + "tecnickcom/tcpdf": "^6.3" }, "suggest": { "dompdf/dompdf": "Option for rendering PDF with PDF Writer", "jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers", "mpdf/mpdf": "Option for rendering PDF with PDF Writer", - "tecnick.com/tcpdf": "Option for rendering PDF with PDF Writer" + "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer" }, "type": "library", "autoload": { @@ -155,23 +227,26 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-2.1-or-later" + "MIT" ], "authors": [ { "name": "Maarten Balliauw", - "homepage": "http://blog.maartenballiauw.be" + "homepage": "https://blog.maartenballiauw.be" }, { - "name": "Erik Tilt" + "name": "Mark Baker", + "homepage": "https://markbakeruk.net" }, { "name": "Franck Lefevre", - "homepage": "http://rootslabs.net" + "homepage": "https://rootslabs.net" }, { - "name": "Mark Baker", - "homepage": "http://markbakeruk.net" + "name": "Erik Tilt" + }, + { + "name": "Adrien Crivelli" } ], "description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine", @@ -186,7 +261,7 @@ "xls", "xlsx" ], - "time": "2018-08-06T02:58:06+00:00" + "time": "2019-11-18T11:33:05+00:00" }, { "name": "psr/simple-cache", diff --git a/example/pages/export.php b/example/pages/export.php index 09f2f3d..47f75d4 100644 --- a/example/pages/export.php +++ b/example/pages/export.php @@ -112,12 +112,14 @@ function export5() ->setTitle($defined) ->setContent($defined); - // 建構外部對映表 + // 建構外部對映表 - 有異常換行 $listMap = array( 'gender' => array( array( - 'value' => '1', - 'text' => '男' + 'value' => '1 + ', + 'text' => '男 + ' ), array( 'value' => '0', diff --git a/src/config/abstracts/Config.php b/src/config/abstracts/Config.php index 76dc076..49ad60a 100644 --- a/src/config/abstracts/Config.php +++ b/src/config/abstracts/Config.php @@ -47,7 +47,9 @@ abstract class Config // 模式:簡易(simple)、複雜(complex)、待偵測(detect) 'type' => 'detect', // 必要欄位,必需有值,提供讀取資料時驗証用 - 有設定,且必要欄位有無資料者,跳出 - 因各版本excel對空列定義不同,可能編輯過列,就會產生沒有結尾的空列 - 'requiredField' => array() + 'requiredField' => array(), + // List Menu 不匹配時的回傳值,預設為空字串 + 'listMismatchValue' => '', ); /** @@ -183,7 +185,7 @@ public function getOption($optionName = null) return $this->_options; } else { // 指定鍵名 - if (! isset($this->_options[$optionName])) { + if (! array_key_exists($optionName, $this->_options)) { throw new \Exception('Donot have option: ' . $optionName . ' !', 404); } @@ -658,6 +660,9 @@ public function contentFilter(Array & $data) */ public function contentParser(Array & $data) { + // 取得List Menu不匹配時的回傳值 + $listMismatchValue = $this->getOption('listMismatchValue'); + // 將現有對映表轉成text=>value格式存入暫存 $this->text2ValueMapBuilder(); // 資料範本資料量、key @@ -676,11 +681,11 @@ public function contentParser(Array & $data) $row = array_slice($row, 0, $templateSize); $row = array_combine($templateKey, $row); - // 執行資料轉換 value <=> text - 單筆資料 - $this->valueTextConv($key, $row); - // issue#13 Trim all data when parsing imported data $row = array_map('trim', $row); + + // 執行資料轉換 value <=> text - 單筆資料 + $this->valueTextConv($key, $row, $listMismatchValue); } } @@ -729,8 +734,9 @@ public function contentValidate(Array $row) * 當次迴圈的Key值 * @param array $row * 當次迴圈的內容 + * @param array $mismatchValue List menu不匹配時回傳值 */ - public function valueTextConv($key, &$row) + public function valueTextConv($key, &$row, $mismatchValue = '') { // 遍歷資料,並轉換內容 foreach ($row as $k => &$v) { @@ -740,7 +746,7 @@ public function valueTextConv($key, &$row) } // 處理資料轉換 - $v = isset($this->_cache['valueTextMap'][$k][$v]) ? $this->_cache['valueTextMap'][$k][$v] : ''; + $v = isset($this->_cache['valueTextMap'][$k][$v]) ? $this->_cache['valueTextMap'][$k][$v] : $mismatchValue; } } @@ -755,6 +761,9 @@ public function valueTextConv($key, &$row) */ public function value2TextMapBuilder() { + // 下拉選單內容處理 - 去頭尾空白 + $this->trimMap(); + // 初始化暫存 $this->_cache['valueTextMap'] = array(); @@ -768,6 +777,9 @@ public function value2TextMapBuilder() */ public function text2ValueMapBuilder() { + // 下拉選單內容處理 - 去頭尾空白 + $this->trimMap(); + // 初始化暫存 $this->_cache['valueTextMap'] = array(); @@ -776,6 +788,20 @@ public function text2ValueMapBuilder() } } + /** + * 下拉選單內容處理 - 去頭尾空白 + * + * @return void + */ + public function trimMap() + { + foreach ($this->_listMap as &$lists) { + foreach ($lists as &$list) { + $list = array_map('trim', $list); + } + } + } + /** * ********************************************** * ************** Defined Function **************