PHPexcel怎么导入日志

发布时间:2021-08-20 09:17:53 作者:chen
来源:亿速云 阅读:155

这篇文章主要介绍“PHPexcel怎么导入日志”,在日常操作中,相信很多人在PHPexcel怎么导入日志问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”PHPexcel怎么导入日志”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

直接上代码:

html:

<tr>
   <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="10%" height="30" align="right" bgcolor="#f2f2f2" class="left_txt2">上传文件</td>
                <td width="1%" bgcolor="#f2f2f2">&nbsp;</td>
                <td width="32%" height="30" bgcolor="#f2f2f2">
                    <input type="file" name="excelPacket" class="file">
                </td>
            </tr>
            <tr>
                <td height="30" colspan="4" align="center" class="left_txt"><input type="submit" name="button" id="button" value="创建" />
                    &nbsp;
                    <input type="reset" name="button2" id="button2" value="重置" /></td>
            </tr>
        </table</td>

php:(另外在该文件包上一级建立一个文件夹用于存放要导入的excel表)

记得引入PHPexcel类包

header("Content-type:text/html;charset=utf-8");
require_once 'backend_islogin.php';
require_once '../db/Db.php';
require_once '../backend/PHPExcel/PHPExcel.php';
$PHPReader = new PHPExcel_Reader_Excel2007();
//print_r ($_SESSION);exit;
$fileExtArr = explode(".",$_FILES['excelPacket']['name']);
$fileExt = ".".$fileExtArr[1];
$path=$_SERVER['DOCUMENT_ROOT'].'/excelupload/'.time().md5($_FILES['excelPacket']['name'].rand()).$fileExt;
move_uploaded_file($_FILES['excelPacket']['tmp_name'],$path);
if( ! $PHPReader->canRead($path))
{
    $PHPReader = new PHPExcel_Reader_Excel5();
    if( ! $PHPReader->canRead($path)){
        echo 'no Excel';
        return ;
    }
}

$PHPExcel = $PHPReader->load($path); //读取文件
$currentSheet = $PHPExcel->getSheet(0); //读取第一个工作簿
$allColumn = $currentSheet->getHighestColumn(); // 所有列数
$allRow = $currentSheet->getHighestRow(); // 所有行数

$data = array(); //下面是读取想要获取的列的内容

for ($rowIndex = 2; $rowIndex <= $allRow; $rowIndex++)
{
    $data[] = array(
        'name' =>  $currentSheet->getCell('A'.$rowIndex)->getValue(),
        'brand' =>  $currentSheet->getCell('B'.$rowIndex)->getValue(),
        'goods_code' =>  $currentSheet->getCell('C'.$rowIndex)->getValue(),
        'credit_code' =>  $currentSheet->getCell('D'.$rowIndex)->getValue(),
        'f_code' =>  $currentSheet->getCell('E'.$rowIndex)->getValue(),
        'c_code' =>  $currentSheet->getCell('F'.$rowIndex)->getValue(),
        'adapt_mod' =>  $currentSheet->getCell('G'.$rowIndex)->getValue(),
        'oe_code' =>  $currentSheet->getCell('H'.$rowIndex)->getValue(),
        'img_code' =>  $currentSheet->getCell('I'.$rowIndex)->getValue(),
        'acc_info' =>  $currentSheet->getCell('J'.$rowIndex)->getValue(),
        'user_id' =>  $_SESSION['session_id'],
        'audit' =>  0,
    );
}

$dbObj = new DB();
foreach($data as $row){
    $oe_code = $row["oe_code"];
    $oe_code = $dbObj->get_one("select 'oe_code' from tb_goods where oe_code = '$oe_code'");
    if(!empty($oe_code)){
        echo "<script>
      alert('商品重复请重新上传');
      location.href = 'backend_product.php';
      </script>";
        break;
    }else{
        $re = $dbObj -> insert("tb_goods",$row);
        if($re){
            echo "<script>alert('编辑成功');location.href='backend_product.php';</script>";
        }
    }

}

到此,关于“PHPexcel怎么导入日志”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. PHPexcel笔记
  2. thinkphp中怎样使用PHPExcel导入Excel

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php phpexcel

上一篇:spark中的RDD是什么

下一篇:python语言基础知识有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》