日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php excel 导入 显示,php Excel 导入

發(fā)布時間:2024/1/23 php 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php excel 导入 显示,php Excel 导入 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

php Excel 導入

public function storeSql()

{

$file = input('file.excel');

$path = ROOT_PATH . 'public' . DS . 'uploads';

if ($file) {

$info = $file->move($path);

if ($info) {

$this->dataStore($info->getPathname());

} else {

$this->error($file->getError());

}

}

}

//數(shù)據(jù)導入

public function dataStore($filePath)

{

import('phpoffice.phpexcel.Classes.PHPExcel');

import('phpoffice.phpexcel.Classes.IOFactory');

import('phpoffice.phpexcel.Classes.Reader.Excel2007');

$PHPExcel = new \PHPExcel();

$PHPReader = new \PHPExcel_Reader_Excel2007();

if (!$PHPReader->canRead($filePath)) {

$PHPReader = new \PHPExcel_Reader_Excel5();

if (!$PHPReader->canRead($filePath)) {

$this->error('上傳失敗!');

}

}

//讀取Excel文件

$PHPExcel = $PHPReader->load($filePath);

//讀取excel文件中的第一個工作表

$sheet = $PHPExcel->getSheet(0);

//取得最大的列號

$allColumn = $sheet->getHighestColumn();

//取得最大的行號

$allRow = $sheet->getHighestRow();

$user = new UserOff;

$phones = $user->where('merchant_id', $this->userID)->column('phone');

$all = [];

//從第二行開始插入,第一行是列名

for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {

$data['phone'] = $PHPExcel->getActiveSheet()->getCell("A" . $currentRow)->getValue();

$data['point'] = $PHPExcel->getActiveSheet()->getCell("B" . $currentRow)->getValue();

$data['growth'] = $PHPExcel->getActiveSheet()->getCell("C" . $currentRow)->getValue();

$data['card_num'] = $PHPExcel->getActiveSheet()->getCell("D" . $currentRow)->getValue();

$data['user_name'] = $PHPExcel->getActiveSheet()->getCell("E" . $currentRow)->getValue();

$data['merchant_id'] = $this->userID;

$data['add_time'] = time();

$data['phone_no'] = $data['phone'] . $this->userID . "AcDE"; //編號

empty($data['card_num']) && $data['card_num'] = 0;

empty($data['user_name']) && $data['user_name'] = "";

empty($data['phone']) && $data['user_name'] = "";

empty($data['point']) && $data['point'] = 0;

empty($data['growth']) && $data['growth'] = 0;

array_push($all,$data);

}

$allData =$this->diffArr($all,$phones);

$update = $user->saveAll($allData['allDataUp'], true);

//$update = true;

$insert = $user->saveAll($allData['allDataIn'], false);

if ($update || $insert) {

$this->success('數(shù)據(jù)導入成功!', url('dump/index'));

} else {

$this->error('數(shù)據(jù)導入失敗!');

}

}

總結

以上是生活随笔為你收集整理的php excel 导入 显示,php Excel 导入的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。