验证中...
Languages: PHP
Categories: Web开发技术
Latest update 2019-01-19 08:01
gistfile1.txt
Raw Copy
public function importMate()
{
set_time_limit(0);
exit;
$file_name = request()->get('file_name');
if(empty($file_name))
{
echo '文件路径错误';
exit;
}
//按文件夹导入
$filePath = realpath('D:/excelTest/'.iconv('UTF-8', 'GBK', $file_name));
//字段转换统一
$filedConf = [
'公司名称'=> 'company_name',
'统一社会信用代码注册号'=> 'credit_code',
'省份'=> 'province',
'市'=> 'city',
'法定代表人'=> 'contact_name',
'注册资本'=> 'capital',
'成立日期'=> 'company_build_at',
'经营范围'=> 'business_range',
'联系电话'=> 'mobile',
'地址'=> 'address',
'邮箱' => 'email',
'企业网址'=> 'website'
];
Excel::batch($filePath, function($rows, $file) use ($filedConf){
//这里是生成器迭代
$rows->each(function($row) use ($filedConf){
$row = $row->toArray();
$new_row = [];
foreach($row as $key=>$val)
{
$key = trim($key);
if(!isset($filedConf[$key]))
{
continue;
}
$new_row[$filedConf[$key]] = $val;
}
unset($row);
$this->importRow($new_row);
});
});
print '结束';
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025