企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## html ``` <form enctype="multipart/form-data" action="/web/merchant.php?c=site&a=entry&m=ewei_shopv2&do=web&r=goods.daoru" method="post"> <div style="display: flex;"> <input type="file" name="myfile" /> <input type="submit" class='btn btn-sm btn-primary' value="导入商品" /> </div> </form> ``` ## php ``` public function daoru() { global $_W; global $_GPC; require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php'; require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/IOFactory.php'; require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/Reader/Excel5.php'; $objReader = PHPExcel_IOFactory::createReader('Excel5'); //接收存在缓存中的excel表格 $filename = $_FILES['myfile']['tmp_name']; $objPHPExcel = $objReader->load($filename); //$filename可以是上传的表格,或者是指定的表格 $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumn = $sheet->getHighestColumn(); // 取得总列数 //循环读取excel表格,读取一条,插入一条 //j表示从哪一行开始读取 从第二行开始读取,因为第一行是标题不保存 //$a表示列号 for($j=2;$j<=$highestRow;$j++) { $h1 = $objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();//获取B(密码)列的值 $h2 = $objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();//获取B(密码)列的值 $h3 = $objPHPExcel->getActiveSheet()->getCell("D".$j)->getValue();//获取B(密码)列的值 $h4 = $objPHPExcel->getActiveSheet()->getCell("E".$j)->getValue();//获取B(密码)列的值 $h5 = $objPHPExcel->getActiveSheet()->getCell("F".$j)->getValue();//获取B(密码)列的值 $h6 = $objPHPExcel->getActiveSheet()->getCell("G".$j)->getValue();//获取B(密码)列的值 $h7 = $objPHPExcel->getActiveSheet()->getCell("H".$j)->getValue();//获取B(密码)列的值 $h8 = $objPHPExcel->getActiveSheet()->getCell("I".$j)->getValue();//获取B(密码)列的值 $h9 = $objPHPExcel->getActiveSheet()->getCell("J".$j)->getValue();//获取B(密码)列的值 $h10 = $objPHPExcel->getActiveSheet()->getCell("K".$j)->getValue();//获取B(密码)列的值 $h11 = $objPHPExcel->getActiveSheet()->getCell("L".$j)->getValue();//获取B(密码)列的值 $h12 = $objPHPExcel->getActiveSheet()->getCell("M".$j)->getValue();//获取B(密码)列的值 $h13 = $objPHPExcel->getActiveSheet()->getCell("N".$j)->getValue();//获取B(密码)列的值 $h14 = $objPHPExcel->getActiveSheet()->getCell("O".$j)->getValue();//获取B(密码)列的值 $h15 = $objPHPExcel->getActiveSheet()->getCell("P".$j)->getValue();//获取B(密码)列的值 $h16 = $objPHPExcel->getActiveSheet()->getCell("Q".$j)->getValue();//获取B(密码)列的值 $h17 = $objPHPExcel->getActiveSheet()->getCell("R".$j)->getValue();//获取B(密码)列的值 $h18 = $objPHPExcel->getActiveSheet()->getCell("S".$j)->getValue();//获取B(密码)列的值 $h19 = $objPHPExcel->getActiveSheet()->getCell("T".$j)->getValue();//获取B(密码)列的值 $h20 = $objPHPExcel->getActiveSheet()->getCell("U".$j)->getValue();//获取B(密码)列的值 $h21 = $objPHPExcel->getActiveSheet()->getCell("V".$j)->getValue();//获取B(密码)列的值 $h22 = $objPHPExcel->getActiveSheet()->getCell("W".$j)->getValue();//获取B(密码)列的值 $h23 = $objPHPExcel->getActiveSheet()->getCell("X".$j)->getValue();//获取B(密码)列的值 $h24 = $objPHPExcel->getActiveSheet()->getCell("Y".$j)->getValue();//获取B(密码)列的值 $h25 = $objPHPExcel->getActiveSheet()->getCell("Z".$j)->getValue();//获取B(密码)列的值 $user_data = array( 'uniacid' => $h1, 'pcate' => $h2, 'ccate' => $h3, 'type' => $h4, 'status' => $h5, 'title' => $h6, 'thumb' => $h7, 'content' => $h8, 'productprice' => $h9, 'marketprice' => $h10, 'costprice' => $h11, 'originalprice' => $h12, 'total' => $h13, 'createtime' => $h14, 'weight' => $h15, 'maxprice' => $h16, 'minprice' => $h17, 'cates' => $h18, 'hasoption' => $h19, 'thumb_url' => $h20, 'isverify' => $h21, 'tcate' => $h22, 'discounts' => $h23, 'tcates' => $h24, 'keywords' => $h25, 'merchid'=> $_W['merchid'] ); $result = pdo_insert('ewei_shop_goods', $user_data); } echo "<script>alert('导入完成!!!');</script>"; header('Location: /web/merchant.php?c=site&a=entry&m=ewei_shopv2&do=web&r=goods'); } ```