Passed
Push — master ( 88ba49...d8dd24 )
by ma
02:11
created
config/TSpreadSheet.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 return [
4
-    'creator'=>'tinymeng',                  //文件创建者
5
-    'pathName'=>null,                       //文件存储位置
6
-    'fileName'=>null,                       //文件名称
7
-    'horizontalCenter'=>true,               //是否居中
8
-    'titleHeight'=>null,                    //定义表头行高,常用22
9
-    'titleWidth'=>null,                     //定义表头列宽(未设置则自动计算宽度),常用20
10
-    'height'=>null,                         //定义数据行高,常用22
11
-    'autoFilter'=>false,                    //自动筛选(是否开启)
12
-    'autoDataType'=>true,                   //自动适应文本类型
13
-    'freezePane'=>false,                    //冻结窗格(要冻结的首行首列"B2",false不开启)
4
+    'creator'=>'tinymeng', //文件创建者
5
+    'pathName'=>null, //文件存储位置
6
+    'fileName'=>null, //文件名称
7
+    'horizontalCenter'=>true, //是否居中
8
+    'titleHeight'=>null, //定义表头行高,常用22
9
+    'titleWidth'=>null, //定义表头列宽(未设置则自动计算宽度),常用20
10
+    'height'=>null, //定义数据行高,常用22
11
+    'autoFilter'=>false, //自动筛选(是否开启)
12
+    'autoDataType'=>true, //自动适应文本类型
13
+    'freezePane'=>false, //冻结窗格(要冻结的首行首列"B2",false不开启)
14 14
 ];
Please login to merge, or discard this patch.
src/Gateways/Import.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@
 block discarded – undo
30 30
      * @return $this
31 31
      * @throws Exception
32 32
      */
33
-    public function initWorkSheet($filename='')
33
+    public function initWorkSheet($filename = '')
34 34
     {
35
-        if(!empty($filename)){
35
+        if (!empty($filename)) {
36 36
             $this->setFileName($filename);
37 37
         }
38 38
         $this->spreadSheet = IOFactory::load($this->fileName);
Please login to merge, or discard this patch.
src/Gateways/Export.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     /**
34 34
      * __construct
35 35
      */
36
-    public function __construct($config=[]){
36
+    public function __construct($config = []) {
37 37
         $this->setConfig($config);
38 38
 
39 39
         $this->spreadSheet = new Spreadsheet();
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      * @param $config
47 47
      * @return $this
48 48
      */
49
-    public function setConfig($config){
49
+    public function setConfig($config) {
50 50
         foreach ($config as $key => $value) {
51 51
             if (property_exists($this, $key)) {
52 52
                 $this->$key = $value;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     {
65 65
         /** 实例化定义默认excel **/
66 66
         $this->spreadSheet->getProperties()->setCreator($this->creator)->setLastModifiedBy($this->creator);
67
-        if($this->horizontalCenter){
67
+        if ($this->horizontalCenter) {
68 68
             $this->spreadSheet->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); //默认水平居中
69 69
             $this->spreadSheet->getDefaultStyle()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); //默认垂直居中
70 70
             $this->spreadSheet->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::VERTICAL_CENTER); //默认垂直居中
@@ -77,19 +77,19 @@  discard block
 block discarded – undo
77 77
      * @return $this
78 78
      * @throws \PhpOffice\PhpSpreadsheet\Exception
79 79
      */
80
-    public function createWorkSheet($sheetName="Worksheet")
80
+    public function createWorkSheet($sheetName = "Worksheet")
81 81
     {
82 82
         $this->sheetName = $sheetName;
83 83
         /** @var workSheet */
84 84
         $this->workSheet = $this->greateWorkSheet($sheetName);
85
-        if($this->workSheet == null){
86
-            if($this->sheetCount==1){
85
+        if ($this->workSheet == null) {
86
+            if ($this->sheetCount == 1) {
87 87
                 $this->workSheet = $this->spreadSheet->getActiveSheet();
88
-            }else{
88
+            } else {
89 89
                 $this->workSheet = $this->spreadSheet->createSheet();
90 90
             }
91
-            $this->sheetCount += 1;//总sheet数量
92
-            $this->workSheet->setTitle($sheetName);//设置sheet名称
91
+            $this->sheetCount += 1; //总sheet数量
92
+            $this->workSheet->setTitle($sheetName); //设置sheet名称
93 93
         }
94 94
 
95 95
         /** 初始化当前workSheet */
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
     public function generate()
116 116
     {
117 117
         /** 开启自动筛选 **/
118
-        if($this->autoFilter){
118
+        if ($this->autoFilter) {
119 119
             $this->spreadSheet->getActiveSheet()->setAutoFilter(
120 120
                 $this->spreadSheet->getActiveSheet()->calculateWorksheetDimension()
121 121
             );
122 122
         }
123 123
         //文件存储
124
-        if(empty($this->fileName)){
124
+        if (empty($this->fileName)) {
125 125
             $this->getFileName($this->sheetName);
126 126
         }
127 127
         return $this;
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
      * @param $file_name
133 133
      * @return string
134 134
      */
135
-    private function getFileName($sheetName){
136
-        $this->fileName = $sheetName.'_'.date('Y-m-d').'_'.rand(111,999).'.xlsx';
135
+    private function getFileName($sheetName) {
136
+        $this->fileName = $sheetName.'_'.date('Y-m-d').'_'.rand(111, 999).'.xlsx';
137 137
         return $this->fileName;
138 138
     }
139 139
 
@@ -143,18 +143,18 @@  discard block
 block discarded – undo
143 143
      * @return void
144 144
      * @throws ExceptionAlias
145 145
      */
146
-    public function download($filename=''){
147
-        if(empty($filename)){
146
+    public function download($filename = '') {
147
+        if (empty($filename)) {
148 148
             $filename = $this->fileName;
149
-        }else{
149
+        } else {
150 150
             $filename = $this->getFileName($filename);
151 151
         }
152 152
 
153 153
         /** 输出下载 **/
154
-        ob_end_clean();//清除缓冲区,避免乱码
155
-        header( 'Access-Control-Allow-Headers:responsetype,content-type,usertoken');
156
-        header( 'Access-Control-Allow-Methods:GET,HEAD,PUT,POST,DELETE,PATCH');
157
-        header( 'Access-Control-Allow-Origin:*');
154
+        ob_end_clean(); //清除缓冲区,避免乱码
155
+        header('Access-Control-Allow-Headers:responsetype,content-type,usertoken');
156
+        header('Access-Control-Allow-Methods:GET,HEAD,PUT,POST,DELETE,PATCH');
157
+        header('Access-Control-Allow-Origin:*');
158 158
         header('Content-Type: application/vnd.ms-excel');
159 159
         header('Content-Disposition: attachment;filename="'.$filename);
160 160
         header('Cache-Control: max-age=0');
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
      * @return string
172 172
      * @throws ExceptionAlias
173 173
      */
174
-    public function save($filename='',$pathName=''): string
174
+    public function save($filename = '', $pathName = ''): string
175 175
     {
176 176
         $pathName = $this->getPathName($pathName);
177
-        if(empty($filename)){
177
+        if (empty($filename)) {
178 178
             $filename = $this->fileName;
179
-        }else{
179
+        } else {
180 180
             $filename = $this->getFileName($filename);
181 181
         }
182 182
         FileTool::mkdir($pathName);
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         if($this->workSheet == null){
86 86
             if($this->sheetCount==1){
87 87
                 $this->workSheet = $this->spreadSheet->getActiveSheet();
88
-            }else{
88
+            } else{
89 89
                 $this->workSheet = $this->spreadSheet->createSheet();
90 90
             }
91 91
             $this->sheetCount += 1;//总sheet数量
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     public function download($filename=''){
147 147
         if(empty($filename)){
148 148
             $filename = $this->fileName;
149
-        }else{
149
+        } else{
150 150
             $filename = $this->getFileName($filename);
151 151
         }
152 152
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         $pathName = $this->getPathName($pathName);
177 177
         if(empty($filename)){
178 178
             $filename = $this->fileName;
179
-        }else{
179
+        } else{
180 180
             $filename = $this->getFileName($filename);
181 181
         }
182 182
         FileTool::mkdir($pathName);
Please login to merge, or discard this patch.
src/Connector/Gateway.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
      * @author: Tinymeng <[email protected]>
44 44
      * @time: 2022/4/24 17:35
45 45
      */
46
-    protected function cellName($columnIndex){
47
-        $columnIndex =(int)$columnIndex+1;
46
+    protected function cellName($columnIndex) {
47
+        $columnIndex = (int) $columnIndex + 1;
48 48
         static $indexCache = [];
49 49
 
50 50
         if (!isset($indexCache[$columnIndex])) {
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             do {
54 54
                 $characterValue = ($indexValue % 26) ?: 26;
55 55
                 $indexValue = ($indexValue - $characterValue) / 26;
56
-                $base26 = chr($characterValue + 64) . ($base26 ?: '');
56
+                $base26 = chr($characterValue + 64).($base26 ?: '');
57 57
             } while ($indexValue > 0);
58 58
             $indexCache[$columnIndex] = $base26;
59 59
         }
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
      * @param string
67 67
      * @return mixed
68 68
      */
69
-    protected function formatValue($v){
70
-        if($this->format === false) return $v;
71
-        if(is_numeric($v) && strlen($v)===10){
72
-            $v = date($this->format_date,$v);//时间戳转时间格式
69
+    protected function formatValue($v) {
70
+        if ($this->format === false) return $v;
71
+        if (is_numeric($v) && strlen($v) === 10) {
72
+            $v = date($this->format_date, $v); //时间戳转时间格式
73 73
         }
74 74
         return $v;
75 75
     }
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
      * @param $lastCell
80 80
      * @return array
81 81
      */
82
-    protected function getCellName($lastCell){
82
+    protected function getCellName($lastCell) {
83 83
         $cellName = array();
84
-        for($i='A'; $i!=$lastCell; $i++) {
84
+        for ($i = 'A'; $i != $lastCell; $i++) {
85 85
             $cellName[] = $i;
86 86
         }
87 87
         $cellName[] = $i++;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @return array|string|string[]
96 96
      * @throws PhpSpreadsheetException
97 97
      */
98
-    protected function verifyFile($path, $verifyFile = true, $zip = null){
98
+    protected function verifyFile($path, $verifyFile = true, $zip = null) {
99 99
         if ($verifyFile && preg_match('~^data:image/[a-z]+;base64,~', $path) !== 1) {
100 100
             // Check if a URL has been passed. https://stackoverflow.com/a/2058596/1252979
101 101
             if (filter_var($path, FILTER_VALIDATE_URL)) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,9 @@
 block discarded – undo
67 67
      * @return mixed
68 68
      */
69 69
     protected function formatValue($v){
70
-        if($this->format === false) return $v;
70
+        if($this->format === false) {
71
+            return $v;
72
+        }
71 73
         if(is_numeric($v) && strlen($v)===10){
72 74
             $v = date($this->format_date,$v);//时间戳转时间格式
73 75
         }
Please login to merge, or discard this patch.
src/Util/TConfig.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 namespace tinymeng\spreadsheet\Util;
9 9
 
10
-trait TConfig{
10
+trait TConfig {
11 11
 
12 12
     /**
13 13
      * 文件创建者
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
      */
245 245
     private function getPathName($pathName)
246 246
     {
247
-        if(!empty($pathName)){
247
+        if (!empty($pathName)) {
248 248
             return $pathName;
249 249
         }
250
-        if($this->pathName){
250
+        if ($this->pathName) {
251 251
             return $this->pathName;
252 252
         }
253
-        $pathName = dirname( dirname(dirname(SPREADSHEET_ROOT_PATH))).DIRECTORY_SEPARATOR."public".DIRECTORY_SEPARATOR."export".DIRECTORY_SEPARATOR.date('Ymd').DIRECTORY_SEPARATOR;
253
+        $pathName = dirname(dirname(dirname(SPREADSHEET_ROOT_PATH))).DIRECTORY_SEPARATOR."public".DIRECTORY_SEPARATOR."export".DIRECTORY_SEPARATOR.date('Ymd').DIRECTORY_SEPARATOR;
254 254
         return $pathName;
255 255
     }
256 256
 
Please login to merge, or discard this patch.
src/Excel/SpreadSheet.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
13 13
 use tinymeng\tools\FileTool;
14 14
 
15
-trait SpreadSheet{
15
+trait SpreadSheet {
16 16
 
17 17
     /**
18 18
      * sheet名称
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * 文件信息
30 30
      * @var array
31 31
      */
32
-    private $fileTitle=[];
32
+    private $fileTitle = [];
33 33
 
34 34
     /**
35 35
      * 标题占用行数
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public $image_path = '/images';
92 92
 
93
-    public function setTitle($title){
93
+    public function setTitle($title) {
94 94
         $this->title = $title;
95 95
         $this->getTitleFields();
96 96
         return $this;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      * @param $value
101 101
      * @return $this
102 102
      */
103
-    public function setRelativePath($value){
103
+    public function setRelativePath($value) {
104 104
         $this->relative_path = $value;
105 105
         return $this;
106 106
     }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      * @param $value
110 110
      * @return $this
111 111
      */
112
-    public function setImagePath($value){
112
+    public function setImagePath($value) {
113 113
         $this->image_path = $value;
114 114
         return $this;
115 115
     }
@@ -121,40 +121,40 @@  discard block
 block discarded – undo
121 121
      * @author: Tinymeng <[email protected]>
122 122
      * @time: 2022/2/22 11:30
123 123
      */
124
-    public function getExcelData(){
124
+    public function getExcelData() {
125 125
         /* 循环读取每个单元格的数据 */
126 126
         $result = [];
127
-        $dataRow = $this->titleFieldsRow+1;
127
+        $dataRow = $this->titleFieldsRow + 1;
128 128
 
129 129
         //行数循环
130
-        for ($row = $dataRow; $row <= $this->rowCount; $row++){
131
-            $rowFlog = false;//行是否有内容(过滤空行)
130
+        for ($row = $dataRow; $row <= $this->rowCount; $row++) {
131
+            $rowFlog = false; //行是否有内容(过滤空行)
132 132
             //列数循环 , 列数是以A列开始
133 133
             $data = [];
134
-            foreach ($this->cellName as $column){
134
+            foreach ($this->cellName as $column) {
135 135
                 $cell = $this->workSheet->getCell($column.$row);
136 136
                 $value = trim($cell->getFormattedValue());
137
-                if(isset($this->title_fields[$column])){
137
+                if (isset($this->title_fields[$column])) {
138 138
                     $data[$this->title_fields[$column]] = $value;
139
-                    if(!empty($value)) $rowFlog = true;//有内容
139
+                    if (!empty($value)) $rowFlog = true; //有内容
140 140
                 }
141 141
             }
142
-            if($rowFlog) $result[] = $data;
142
+            if ($rowFlog) $result[] = $data;
143 143
         }
144 144
 
145 145
         /*
146 146
          * 读取表格图片数据
147 147
          * (如果为空右击图片转为浮动图片)
148 148
          */
149
-        $image_filename_prefix = time().rand(100,999).$this->sheet;
149
+        $image_filename_prefix = time().rand(100, 999).$this->sheet;
150 150
         foreach ($this->workSheet->getDrawingCollection() as $drawing) {
151 151
             /**@var $drawing Drawing* */
152 152
             list($column, $row) = Coordinate::coordinateFromString($drawing->getCoordinates());
153
-            $image_filename = "/{$image_filename_prefix}-" . $drawing->getCoordinates();
153
+            $image_filename = "/{$image_filename_prefix}-".$drawing->getCoordinates();
154 154
             $image_suffix = $this->saveImage($drawing, $image_filename);
155
-            $image_name = ltrim($this->relative_path, '/') . "{$image_filename}.{$image_suffix}";
156
-            if(isset($this->title_fields[$column])) {
157
-                $result[$row-($this->titleFieldsRow+1)][$this->title_fields[$column]] = $image_name;
155
+            $image_name = ltrim($this->relative_path, '/')."{$image_filename}.{$image_suffix}";
156
+            if (isset($this->title_fields[$column])) {
157
+                $result[$row - ($this->titleFieldsRow + 1)][$this->title_fields[$column]] = $image_name;
158 158
             }
159 159
         }
160 160
         return $result;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      * @author: Tinymeng <[email protected]>
167 167
      * @time: 2022/2/22 11:30
168 168
      */
169
-    public function getTitle(){
169
+    public function getTitle() {
170 170
         return $this->title;
171 171
     }
172 172
 
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
      * @author: Tinymeng <[email protected]>
177 177
      * @time: 2022/2/22 11:30
178 178
      */
179
-    public function getTitleFields(){
179
+    public function getTitleFields() {
180 180
         $title = $this->getTitle();
181 181
 
182 182
         $row = $this->titleFieldsRow;
183 183
         $titleDataArr = [];
184 184
 
185
-        foreach ($this->cellName as $column){
185
+        foreach ($this->cellName as $column) {
186 186
             $value = trim($this->workSheet->getCell($column.$row)->getValue());
187
-            if(!empty($value)){
187
+            if (!empty($value)) {
188 188
                 $titleDataArr[$value] = $column;
189 189
             }
190 190
         }
191 191
         $title_fields = [];
192 192
         foreach ($title as $key=>$value) {
193
-            if(isset($titleDataArr[$key])){
193
+            if (isset($titleDataArr[$key])) {
194 194
                 $title_fields[$titleDataArr[$key]] = $value;
195 195
             }
196 196
         }
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
     protected function saveImage(Drawing $drawing, $image_filename)
209 209
     {
210 210
         FileTool::mkdir($this->image_path);
211
-        $image_filename .= '.' . $drawing->getExtension();
211
+        $image_filename .= '.'.$drawing->getExtension();
212 212
         switch ($drawing->getExtension()) {
213 213
             case 'jpg':
214 214
             case 'jpeg':
215 215
                 $source = imagecreatefromjpeg($drawing->getPath());
216
-                imagejpeg($source, $this->image_path . $image_filename);
216
+                imagejpeg($source, $this->image_path.$image_filename);
217 217
                 break;
218 218
             case 'gif':
219 219
                 $source = imagecreatefromgif($drawing->getPath());
220
-                imagegif($source, $this->image_path . $image_filename);
220
+                imagegif($source, $this->image_path.$image_filename);
221 221
                 break;
222 222
             case 'png':
223 223
                 $source = imagecreatefrompng($drawing->getPath());
224
-                imagepng($source, $this->image_path . $image_filename);
224
+                imagepng($source, $this->image_path.$image_filename);
225 225
                 break;
226 226
             default:
227 227
                 throw new Exception('image format error!');
Please login to merge, or discard this patch.
Braces   +7 added lines, -2 removed lines patch added patch discarded remove patch
@@ -136,10 +136,15 @@
 block discarded – undo
136 136
                 $value = trim($cell->getFormattedValue());
137 137
                 if(isset($this->title_fields[$column])){
138 138
                     $data[$this->title_fields[$column]] = $value;
139
-                    if(!empty($value)) $rowFlog = true;//有内容
139
+                    if(!empty($value)) {
140
+                        $rowFlog = true;
141
+                    }
142
+                    //有内容
140 143
                 }
141 144
             }
142
-            if($rowFlog) $result[] = $data;
145
+            if($rowFlog) {
146
+                $result[] = $data;
147
+            }
143 148
         }
144 149
 
145 150
         /*
Please login to merge, or discard this patch.
src/Excel/TWorkSheet.php 2 patches
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use tinymeng\tools\exception\StatusCode;
12 12
 use tinymeng\tools\exception\TinymengException;
13 13
 
14
-trait TWorkSheet{
14
+trait TWorkSheet {
15 15
 
16 16
     /**
17 17
      * sheet名称
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * 文件信息
55 55
      * @var array
56 56
      */
57
-    private $fileTitle=[];
57
+    private $fileTitle = [];
58 58
 
59 59
 
60 60
     /**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      * @param $data
75 75
      * @return $this
76 76
      */
77
-    public function setData($data){
77
+    public function setData($data) {
78 78
         $this->data = $data;
79 79
         return $this;
80 80
     }
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      * @param $data
84 84
      * @return $this
85 85
      */
86
-    public function getData(){
86
+    public function getData() {
87 87
         return $this->data;
88 88
     }
89 89
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         $this->fileTitle = [];
100 100
         $this->data = [];
101 101
         $this->field = [];
102
-        if($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格
102
+        if ($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格
103 103
     }
104 104
 
105 105
     /**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
      * @throws TinymengException
110 110
      * @throws \PhpOffice\PhpSpreadsheet\Exception
111 111
      */
112
-    public function setWorkSheetData($fileTitle,$data)
112
+    public function setWorkSheetData($fileTitle, $data)
113 113
     {
114
-        if(isset($fileTitle['title_row']) || isset($fileTitle['group_left'])){
114
+        if (isset($fileTitle['title_row']) || isset($fileTitle['group_left'])) {
115 115
             /**
116 116
              * $fileTitle = [
117 117
              *       'title_row'=>1,
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
              *       ],
122 122
              *  ];
123 123
              */
124
-            $this->title_row = $fileTitle['title_row']??1;
125
-            $this->group_left = $fileTitle['group_left']??[];
126
-            $this->fileTitle = $fileTitle['title']??[];
127
-        }else{
124
+            $this->title_row = $fileTitle['title_row'] ?? 1;
125
+            $this->group_left = $fileTitle['group_left'] ?? [];
126
+            $this->fileTitle = $fileTitle['title'] ?? [];
127
+        } else {
128 128
             /**
129 129
              *  $fileTitle = [
130 130
              *       '姓名'=>'name',
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $this->data = $data;
136 136
 
137 137
         /** 设置第一行格式 */
138
-        if($this->mainTitleLine == true){
138
+        if ($this->mainTitleLine == true) {
139 139
             $this->excelHeader();
140 140
         }
141 141
 
@@ -143,17 +143,17 @@  discard block
 block discarded – undo
143 143
         $this->excelTitle();
144 144
 
145 145
         /** 获取列表里所有字段 **/
146
-        foreach ($this->fileTitle as $key => $val){
147
-            if(is_array($val)){
148
-                foreach ($val as $k => $v){
146
+        foreach ($this->fileTitle as $key => $val) {
147
+            if (is_array($val)) {
148
+                foreach ($val as $k => $v) {
149 149
                     $this->field[] = $v;
150 150
                 }
151
-            }else{
151
+            } else {
152 152
                 $this->field[] = $val;
153 153
             }
154 154
         }
155 155
         /** 查询结果赋值 **/
156
-        if(!empty($this->data)){
156
+        if (!empty($this->data)) {
157 157
             $this->excelSetValue();
158 158
         }
159 159
         return $this;
@@ -164,33 +164,33 @@  discard block
 block discarded – undo
164 164
      * @author: Tinymeng <[email protected]>
165 165
      * @time: 2022/2/22 11:43
166 166
      */
167
-    public function excelSetValue(){
168
-        if(empty($this->group_left)){ //判断左侧是否分组
169
-            foreach ($this->data as $key => $val){
167
+    public function excelSetValue() {
168
+        if (empty($this->group_left)) { //判断左侧是否分组
169
+            foreach ($this->data as $key => $val) {
170 170
                 $this->excelSetCellValue($val);
171 171
             }
172
-        }else{   //根据设置分组字段进行分组
172
+        } else {   //根据设置分组字段进行分组
173 173
             /** 数据分组 **/
174 174
             $data = [];
175 175
             $group_left_count = count($this->group_left);
176
-            if($group_left_count == 1){
177
-                foreach ($this->data as $k => $v){
176
+            if ($group_left_count == 1) {
177
+                foreach ($this->data as $k => $v) {
178 178
                     $data[$v[$this->group_left[0]]][] = $v;
179 179
                 }
180
-                foreach ($data as $k =>$v){
180
+                foreach ($data as $k =>$v) {
181 181
                     $data[$k] = [
182 182
                         'data' => $v,
183 183
                         'count' => count($v)
184 184
                     ];
185 185
                 }
186 186
                 $this->excelGroupLeft($data, 0, $group_left_count);
187
-            }elseif($group_left_count == 2){
187
+            }elseif ($group_left_count == 2) {
188 188
                 foreach ($this->data as $v) {
189 189
                     $data[$v[$this->group_left[0]]][$v[$this->group_left[1]]][] = $v;
190 190
                 }
191 191
                 $this->data = $this->arrayCount($data);
192 192
                 $this->excelGroupLeft($this->data, 0, $group_left_count);
193
-            }else{
193
+            } else {
194 194
                 throw new TinymengException(StatusCode::COMMON_PARAM_INVALID,
195 195
                     '左侧分组过多,导出失败!'
196 196
                 );
@@ -202,36 +202,36 @@  discard block
 block discarded – undo
202 202
      * @return void
203 203
      * @throws \PhpOffice\PhpSpreadsheet\Exception
204 204
      */
205
-    public function excelHeader(){
205
+    public function excelHeader() {
206 206
         $row = 1;
207 207
         $this->workSheet->setCellValue('A'.$row, $this->mainTitle);
208
-        $this->workSheet->mergeCells('A'.$row.':'.$this->cellName($this->_col-1).$row);
208
+        $this->workSheet->mergeCells('A'.$row.':'.$this->cellName($this->_col - 1).$row);
209 209
     }
210 210
 
211 211
     /**
212 212
      * @return void
213 213
      * @throws \PhpOffice\PhpSpreadsheet\Exception
214 214
      */
215
-    private function excelTitle(){
216
-        if($this->mainTitleLine == true){
217
-            $this->_row ++;//当前行数
215
+    private function excelTitle() {
216
+        if ($this->mainTitleLine == true) {
217
+            $this->_row++; //当前行数
218 218
         }
219 219
 
220 220
         $_merge = $this->cellName($this->_col);
221 221
         foreach ($this->fileTitle as $key => $val) {
222
-            if(!empty($this->titleHeight)) {
223
-                $this->workSheet->getRowDimension($this->_col)->setRowHeight($this->titleHeight);//行高度
222
+            if (!empty($this->titleHeight)) {
223
+                $this->workSheet->getRowDimension($this->_col)->setRowHeight($this->titleHeight); //行高度
224 224
             }
225 225
             $rowName = $this->cellName($this->_col);
226
-            $this->workSheet->getStyle($rowName . $this->_row)->getAlignment()->setWrapText(true);//自动换行
226
+            $this->workSheet->getStyle($rowName.$this->_row)->getAlignment()->setWrapText(true); //自动换行
227 227
             if (is_array($val)) {
228 228
                 $num = 1;
229 229
                 $_cols = $this->_col;
230 230
                 foreach ($val as $k => $v) {
231
-                    $this->workSheet->setCellValue($this->cellName($_cols) . ($this->_row+1), $k);
232
-                    if(!empty($this->titleWidth)) {
231
+                    $this->workSheet->setCellValue($this->cellName($_cols).($this->_row + 1), $k);
232
+                    if (!empty($this->titleWidth)) {
233 233
                         $this->workSheet->getColumnDimension($this->cellName($_cols))->setWidth($this->titleWidth); //列宽度
234
-                    }else{
234
+                    } else {
235 235
                         $this->workSheet->getColumnDimension($this->cellName($_cols))->setAutoSize(true); //自动计算宽度
236 236
                     }
237 237
                     if ($num < count($val)) {
@@ -240,23 +240,23 @@  discard block
 block discarded – undo
240 240
                     }
241 241
                     $_cols++;
242 242
                 }
243
-                $this->workSheet->mergeCells($_merge . $this->_row.':' . $this->cellName($this->_col) .$this->_row);
244
-                $this->workSheet->setCellValue($_merge . $this->_row, $key);//设置值
243
+                $this->workSheet->mergeCells($_merge.$this->_row.':'.$this->cellName($this->_col).$this->_row);
244
+                $this->workSheet->setCellValue($_merge.$this->_row, $key); //设置值
245 245
             } else {
246 246
                 if ($this->title_row != 1) {
247
-                    $this->workSheet->mergeCells($rowName . $this->_row.':' . $rowName . ($this->_row + $this->title_row - 1));
247
+                    $this->workSheet->mergeCells($rowName.$this->_row.':'.$rowName.($this->_row + $this->title_row - 1));
248 248
                 }
249
-                $this->workSheet->setCellValue($rowName . $this->_row, $key);//设置值
250
-                if(!empty($this->titleWidth)){
249
+                $this->workSheet->setCellValue($rowName.$this->_row, $key); //设置值
250
+                if (!empty($this->titleWidth)) {
251 251
                     $this->workSheet->getColumnDimension($rowName)->setWidth($this->titleWidth); //列宽度
252
-                }else{
252
+                } else {
253 253
                     $this->workSheet->getColumnDimension($rowName)->setAutoSize(true); //自动计算宽度
254 254
                 }
255 255
             }
256 256
             $this->_col++;
257 257
             $_merge = $this->cellName($this->_col);
258 258
         }
259
-        $this->_row += $this->title_row;//当前行数
259
+        $this->_row += $this->title_row; //当前行数
260 260
     }
261 261
 
262 262
     /**
@@ -267,60 +267,60 @@  discard block
 block discarded – undo
267 267
     private function excelSetCellValue($val)
268 268
     {
269 269
         //设置单元格行高
270
-        if(!empty($this->height)){
270
+        if (!empty($this->height)) {
271 271
             $this->workSheet->getRowDimension($this->_row)->setRowHeight($this->height);
272 272
         }
273 273
         $_lie = 0;
274
-        foreach ($this->field as $v){
274
+        foreach ($this->field as $v) {
275 275
             $rowName = $this->cellName($_lie);
276 276
 
277
-            if(strpos($v,'.') !== false){
278
-                $v = explode('.',$v);
277
+            if (strpos($v, '.') !== false) {
278
+                $v = explode('.', $v);
279 279
                 $content = $val;
280
-                for ($i=0;$i<count($v);$i++){
281
-                    $content = $content[$v[$i]]??'';
280
+                for ($i = 0; $i < count($v); $i++) {
281
+                    $content = $content[$v[$i]] ?? '';
282 282
                 }
283
-            }elseif($v == '_id'){
284
-                $content = $this->_row-$this->title_row;//自增序号列
285
-            }else{
286
-                $content = ($val[$v]??'');
283
+            }elseif ($v == '_id') {
284
+                $content = $this->_row - $this->title_row; //自增序号列
285
+            } else {
286
+                $content = ($val[$v] ?? '');
287 287
             }
288
-            if(is_array($content) && isset($content['type']) && isset($content['content'])){
289
-                if($content['type'] == 'image'){
288
+            if (is_array($content) && isset($content['type']) && isset($content['content'])) {
289
+                if ($content['type'] == 'image') {
290 290
                     $path = $this->verifyFile($content['content']);
291 291
                     $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
292 292
                     $drawing->setPath($path);
293
-                    if(!empty($content['height'])) {
293
+                    if (!empty($content['height'])) {
294 294
                         $drawing->setHeight($content['height']);
295 295
                     }
296
-                    if(!empty($content['width'])) {
297
-                        $drawing->setWidth($content['width']);//只设置高,宽会自适应,如果设置宽后,高则失效
296
+                    if (!empty($content['width'])) {
297
+                        $drawing->setWidth($content['width']); //只设置高,宽会自适应,如果设置宽后,高则失效
298 298
                     }
299
-                    if(!empty($content['offsetX'])) {
300
-                        $drawing->setOffsetX($content['offsetX']);//设置X方向偏移量
299
+                    if (!empty($content['offsetX'])) {
300
+                        $drawing->setOffsetX($content['offsetX']); //设置X方向偏移量
301 301
                     }
302
-                    if(!empty($content['offsetY'])) {
303
-                        $drawing->setOffsetY($content['offsetY']);//设置Y方向偏移量
302
+                    if (!empty($content['offsetY'])) {
303
+                        $drawing->setOffsetY($content['offsetY']); //设置Y方向偏移量
304 304
                     }
305 305
 
306 306
                     $drawing->setCoordinates($rowName.$this->_row);
307 307
                     $drawing->setWorksheet($this->workSheet);
308 308
                 }
309
-            }else {
310
-                $content = $this->formatValue($content);//格式化数据
311
-                if (is_numeric($content)){
312
-                    if($this->autoDataType && strlen($content)<11){
313
-                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_NUMERIC);
314
-                    }else{
315
-                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2);
309
+            } else {
310
+                $content = $this->formatValue($content); //格式化数据
311
+                if (is_numeric($content)) {
312
+                    if ($this->autoDataType && strlen($content) < 11) {
313
+                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content, DataType::TYPE_NUMERIC);
314
+                    } else {
315
+                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content, DataType::TYPE_STRING2);
316 316
                     }
317
-                }else{
318
-                    $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2);
317
+                } else {
318
+                    $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content, DataType::TYPE_STRING2);
319 319
                 }
320 320
             }
321
-            $_lie ++;
321
+            $_lie++;
322 322
         }
323
-        $this->_row ++;
323
+        $this->_row++;
324 324
     }
325 325
 
326 326
     /**
@@ -333,22 +333,22 @@  discard block
 block discarded – undo
333 333
     private function excelGroupLeft(array $data, int $_lie, $group_left_count)
334 334
     {
335 335
         $group_start = $this->_col; //二级合并单元格开始
336
-        foreach ($data as $key => $val){
336
+        foreach ($data as $key => $val) {
337 337
             $rowName = $this->cellName($_lie);
338
-            $coordinate = $rowName.$this->_col.':'.$rowName.($this->_col+$val['count']-1);
338
+            $coordinate = $rowName.$this->_col.':'.$rowName.($this->_col + $val['count'] - 1);
339 339
             $this->workSheet->mergeCells($coordinate);
340
-            if($group_left_count == 1){
341
-                foreach ($val['data'] as $data){
340
+            if ($group_left_count == 1) {
341
+                foreach ($val['data'] as $data) {
342 342
                     $this->excelSetCellValue($data);
343 343
                 }
344
-            }else{
345
-                $rowName = $this->cellName($_lie+1);  //对应的列值
346
-                foreach ($val['data'] as $k => $v){
347
-                    $group_end_col = $group_start + $v['count']-1;
344
+            } else {
345
+                $rowName = $this->cellName($_lie + 1); //对应的列值
346
+                foreach ($val['data'] as $k => $v) {
347
+                    $group_end_col = $group_start + $v['count'] - 1;
348 348
                     $coordinate = $rowName.$group_start.':'.$rowName.$group_end_col;
349 349
                     $this->workSheet->mergeCells($coordinate);
350
-                    $group_start = $group_end_col+1;
351
-                    foreach ($v['data'] as $data){
350
+                    $group_start = $group_end_col + 1;
351
+                    foreach ($v['data'] as $data) {
352 352
                         $this->excelSetCellValue($data);
353 353
                     }
354 354
                 }
@@ -363,13 +363,13 @@  discard block
 block discarded – undo
363 363
      * @param array $data 二维数组原始数据
364 364
      * @return array
365 365
      */
366
-    private function arrayCount($data=[])
366
+    private function arrayCount($data = [])
367 367
     {
368
-        foreach ($data as $key => $val){
368
+        foreach ($data as $key => $val) {
369 369
             $num = 0;
370
-            foreach ($val as $k => $v){
370
+            foreach ($val as $k => $v) {
371 371
                 $sub_num = count($v);
372
-                $num = $num+$sub_num;
372
+                $num = $num + $sub_num;
373 373
                 $val[$k] = [
374 374
                     'count' => $sub_num,
375 375
                     'data' => $v
Please login to merge, or discard this patch.
Braces   +17 added lines, -14 removed lines patch added patch discarded remove patch
@@ -99,7 +99,10 @@  discard block
 block discarded – undo
99 99
         $this->fileTitle = [];
100 100
         $this->data = [];
101 101
         $this->field = [];
102
-        if($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格
102
+        if($this->freezePane) {
103
+            $this->workSheet->freezePane($this->freezePane);
104
+        }
105
+        //冻结窗格
103 106
     }
104 107
 
105 108
     /**
@@ -124,7 +127,7 @@  discard block
 block discarded – undo
124 127
             $this->title_row = $fileTitle['title_row']??1;
125 128
             $this->group_left = $fileTitle['group_left']??[];
126 129
             $this->fileTitle = $fileTitle['title']??[];
127
-        }else{
130
+        } else{
128 131
             /**
129 132
              *  $fileTitle = [
130 133
              *       '姓名'=>'name',
@@ -148,7 +151,7 @@  discard block
 block discarded – undo
148 151
                 foreach ($val as $k => $v){
149 152
                     $this->field[] = $v;
150 153
                 }
151
-            }else{
154
+            } else{
152 155
                 $this->field[] = $val;
153 156
             }
154 157
         }
@@ -169,7 +172,7 @@  discard block
 block discarded – undo
169 172
             foreach ($this->data as $key => $val){
170 173
                 $this->excelSetCellValue($val);
171 174
             }
172
-        }else{   //根据设置分组字段进行分组
175
+        } else{   //根据设置分组字段进行分组
173 176
             /** 数据分组 **/
174 177
             $data = [];
175 178
             $group_left_count = count($this->group_left);
@@ -184,13 +187,13 @@  discard block
 block discarded – undo
184 187
                     ];
185 188
                 }
186 189
                 $this->excelGroupLeft($data, 0, $group_left_count);
187
-            }elseif($group_left_count == 2){
190
+            } elseif($group_left_count == 2){
188 191
                 foreach ($this->data as $v) {
189 192
                     $data[$v[$this->group_left[0]]][$v[$this->group_left[1]]][] = $v;
190 193
                 }
191 194
                 $this->data = $this->arrayCount($data);
192 195
                 $this->excelGroupLeft($this->data, 0, $group_left_count);
193
-            }else{
196
+            } else{
194 197
                 throw new TinymengException(StatusCode::COMMON_PARAM_INVALID,
195 198
                     '左侧分组过多,导出失败!'
196 199
                 );
@@ -231,7 +234,7 @@  discard block
 block discarded – undo
231 234
                     $this->workSheet->setCellValue($this->cellName($_cols) . ($this->_row+1), $k);
232 235
                     if(!empty($this->titleWidth)) {
233 236
                         $this->workSheet->getColumnDimension($this->cellName($_cols))->setWidth($this->titleWidth); //列宽度
234
-                    }else{
237
+                    } else{
235 238
                         $this->workSheet->getColumnDimension($this->cellName($_cols))->setAutoSize(true); //自动计算宽度
236 239
                     }
237 240
                     if ($num < count($val)) {
@@ -249,7 +252,7 @@  discard block
 block discarded – undo
249 252
                 $this->workSheet->setCellValue($rowName . $this->_row, $key);//设置值
250 253
                 if(!empty($this->titleWidth)){
251 254
                     $this->workSheet->getColumnDimension($rowName)->setWidth($this->titleWidth); //列宽度
252
-                }else{
255
+                } else{
253 256
                     $this->workSheet->getColumnDimension($rowName)->setAutoSize(true); //自动计算宽度
254 257
                 }
255 258
             }
@@ -280,9 +283,9 @@  discard block
 block discarded – undo
280 283
                 for ($i=0;$i<count($v);$i++){
281 284
                     $content = $content[$v[$i]]??'';
282 285
                 }
283
-            }elseif($v == '_id'){
286
+            } elseif($v == '_id'){
284 287
                 $content = $this->_row-$this->title_row;//自增序号列
285
-            }else{
288
+            } else{
286 289
                 $content = ($val[$v]??'');
287 290
             }
288 291
             if(is_array($content) && isset($content['type']) && isset($content['content'])){
@@ -306,15 +309,15 @@  discard block
 block discarded – undo
306 309
                     $drawing->setCoordinates($rowName.$this->_row);
307 310
                     $drawing->setWorksheet($this->workSheet);
308 311
                 }
309
-            }else {
312
+            } else {
310 313
                 $content = $this->formatValue($content);//格式化数据
311 314
                 if (is_numeric($content)){
312 315
                     if($this->autoDataType && strlen($content)<11){
313 316
                         $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_NUMERIC);
314
-                    }else{
317
+                    } else{
315 318
                         $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2);
316 319
                     }
317
-                }else{
320
+                } else{
318 321
                     $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2);
319 322
                 }
320 323
             }
@@ -341,7 +344,7 @@  discard block
 block discarded – undo
341 344
                 foreach ($val['data'] as $data){
342 345
                     $this->excelSetCellValue($data);
343 346
                 }
344
-            }else{
347
+            } else{
345 348
                 $rowName = $this->cellName($_lie+1);  //对应的列值
346 349
                 foreach ($val['data'] as $k => $v){
347 350
                     $group_end_col = $group_start + $v['count']-1;
Please login to merge, or discard this patch.
src/TSpreadSheet.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,17 +28,17 @@  discard block
 block discarded – undo
28 28
      * @return mixed
29 29
      * @throws \Exception
30 30
      */
31
-    protected static function init($gateway, $config=[])
31
+    protected static function init($gateway, $config = [])
32 32
     {
33 33
         $gateway = StringTool::uFirst($gateway);
34
-        $class = __NAMESPACE__ . '\\Gateways\\' . $gateway;
34
+        $class = __NAMESPACE__.'\\Gateways\\'.$gateway;
35 35
         if (class_exists($class)) {
36 36
             $configFile = SPREADSHEET_ROOT_PATH."/config/TSpreadSheet.php";
37 37
             if (!file_exists($configFile)) {
38 38
                 return false;
39 39
             }
40 40
             $baseConfig = require $configFile;
41
-            $app = new $class(array_replace_recursive($baseConfig,$config));
41
+            $app = new $class(array_replace_recursive($baseConfig, $config));
42 42
             if ($app instanceof GatewayInterface) {
43 43
                 return $app;
44 44
             }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * @param $config
56 56
      * @return mixed
57 57
      */
58
-    public static function __callStatic($gateway, $config=[])
58
+    public static function __callStatic($gateway, $config = [])
59 59
     {
60 60
         return self::init($gateway, ...$config);
61 61
     }
Please login to merge, or discard this patch.
example/import.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@
 block discarded – undo
20 20
 
21 21
 //读取并初始化表格内容数据
22 22
 $TSpreadSheet = TSpreadSheet::import()
23
-    ->initWorkSheet($filename);//读取并初始化表格内容数据
23
+    ->initWorkSheet($filename); //读取并初始化表格内容数据
24 24
 
25 25
 //设置title对应字段,获取表格内容
26 26
 $data = $TSpreadSheet->setTitle($title)->getExcelData();
27
-var_dump($data);die;
27
+var_dump($data); die;
28 28
 /**
29 29
  * array(3) {
30 30
  * [0]=>
Please login to merge, or discard this patch.