$path['dirname']]; $excel = new \Vtiful\Kernel\Excel($config); // 读取测试文件 $excel->openFile($path['basename']) ->openSheet(); $row = $excel->nextRow(); $type = array_pad([], count($row), \Vtiful\Kernel\Excel::TYPE_STRING); foreach($this->column_date_cnt as $k => $v) { $type[$v-1] = \Vtiful\Kernel\Excel::TYPE_TIMESTAMP; } $excel->setType($type); $this->data = array(); $this->data[] = $row; while ($length--) { $row = $excel->nextRow(); if($row === NULL) { break; } if(empty($row)) { continue; } foreach($this->column_date_cnt as $k => $v) { if($row[$v-1] && is_int($row[$v-1])) $row[$v-1] = date('Y-m-d H:i:s', $row[$v-1]); } $this->data[]=$row; $this->writeData(false,$compatible_csv); } $this->writeData(true,$compatible_csv); return $this->data; } catch (\Exception $e) { throw $e; } } /** * writeData * @param mixed $is_force is_force * @param mixed $compatible_csv compatible_csv * @return mixed 返回值 */ public function writeData($is_force = false, $compatible_csv = false ) { if(!$this->is_write_file) return; if(!$this->file_prefix) $this->file_prefix = md5(time()); $file_name = sprintf("%s_%d.json",$this->file_prefix,$this->file_id); $local_file = $this->local_path.$file_name; if( $is_force || $this->page_size <= count($this->data) ) { if($compatible_csv) { $this->data = array_values($this->data); foreach ($this->data as $k=>$v) $this->data[$k] = array_values($v); } if(file_put_contents($local_file, json_encode($this->data,JSON_UNESCAPED_UNICODE))) { $this->file_data[] = $local_file; } $this->data = array(); $this->file_id++; } } /** * 设置PageSize * @param mixed $num num * @return mixed 返回操作结果 */ public function setPageSize($num) { $this->page_size = $num; } /** * 设置LocalPath * @param mixed $path path * @return mixed 返回操作结果 */ public function setLocalPath($path) { $this->local_path = $path; } /** * 设置FilePrefix * @param mixed $file_prefix file_prefix * @return mixed 返回操作结果 */ public function setFilePrefix($file_prefix) { $this->file_prefix = $file_prefix; } /** * 设置WriteFile * @param mixed $is_write_file is_write_file * @return mixed 返回操作结果 */ public function setWriteFile($is_write_file) { $this->is_write_file = $is_write_file; } public function setCellDateCnt($column_date_cnt=array(),$time_diff=0) { $this->column_date_cnt = $column_date_cnt; $this->date_time_diff = $time_diff; } }