当前位置:网站首页>Tp5.1 upload excel file and read its contents
Tp5.1 upload excel file and read its contents
2022-06-22 23:22:00 【Juqi】
1. First set the PHPExcel Class to import , Use here composer
composer require phpoffice/phpexcel
Code :
// Need to introduce this
use PHPExcel_IOFactory;
public function importExcel(){
$filename = $_FILES['file_xls']['tmp_name'];
// Set up excel Format
$reader = PHPExcel_IOFactory::createReader('Excel2007');
// load ⼊excel⽂ Pieces of
$excel = $reader->load($filename);
// Read the first ⼀ A watch
$sheet = $excel->getSheet(0);
// Get the total ⾏ Count
$row_num = $sheet->getHighestRow();
// Get total number of columns
$col_num = $sheet->getHighestColumn();
$data = []; // Get table data in array form
for($col='A';$col<=$col_num;$col++)
{
// From ⼆⾏ Start , Remove the meter head ( if ⽆ The header starts from the ⼀⾏ Start )
for($row=2;$row<=$row_num;$row++)
{
$data[$row-2][] = $sheet->getCell($col.$row)->getValue();
}
}
//Array ( [0] => Array ( [0] => 77777 ) [1] => Array ( [0] => 88888 ) )
$error_code = array();
foreach($data as $item){
foreach($item as $code){
$ra = Db::table('apply_code')->field('*')->where('code',$code)->find();
if (!empty($ra)){
array_push($error_code,$code);
}else{
$arr = array(
'code'=>$code,
'createtime' => date('Y-m-d H:i:s'),
'updatetime' => date('Y-m-d H:i:s')
);
Db::table('apply_code')->insert($arr);
}
}
}
$error_msg = ' The following exchange code already exists :';
if(!empty($error_code)){
foreach($error_code as $item){
$error_msg.= ''.$item.',';
}
$this->success($error_msg);
}else{
$this->success(' All imported successfully ');
}
}边栏推荐
- js判断浏览器是否打开了控制台
- Phantomjs实用代码段(持续更新中……)
- Spark SQL Generic Load/Save Functions(2.4.3)
- 2021-07-27
- Relationship between adau1452 development system interface and code data
- MySQL master-slave synchronization and its basic process of database and table division
- Introduction to database access tools
- canvas生成海报
- OJ每日一练——跨越2020
- Reddit's discussion on lamda model: it is not stateless. It adopts a dual process. Compared with the way it edits Wikipedia, it doesn't matter whether it has feelings or not
猜你喜欢

程序员接私活兼职选择

2021-04-16

three.js模拟驾驶游览艺术展厅---打造超级相机控制器

Smart data won two annual awards at the second isig China Industrial Intelligence Conference

2021-03-06

同步电路与跨时钟域电路设计2——多bit信号的跨时钟域传输(FIFO)

10 Super VIM plug-ins, I can't put them down

2020-12-04

Practice brings true knowledge: the strongest seckill system architecture in the whole network is decrypted. Not all seckills are seckills!!

2021-04-14
随机推荐
Greedy distribution problem (1)
2021-03-06
wallys/WiFi6 MiniPCIe Module 2T2R 2 × 2.4GHz 2x5GHz
The breakthrough of key chips hindering Huawei 5g mobile phones has been achieved, and domestic chips have gained 10% share
剑指 Offer 11. 旋转数组的最小数字
【STM32技巧】使用STM32 HAL库的硬件I2C驱动RX8025T实时时钟芯片
2021-08-21
Zynq ultrascale + rfsoc zcu111 RF clock tree learning 1
C language -- 17 function introduction
Use full function simulation design method
JSBridge
Smart data won two annual awards at the second isig China Industrial Intelligence Conference
canvas生成海报
Phantomjs实用代码段(持续更新中……)
2021-08-21
Longest word in output string
Digital data depth | about software self-control, source code left, no code right
2020-12-20
Spark SQL Start(2.4.3)
一个spark app demo