Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除PHPexcel中的空第一行_Php_Sql_Database_Phpmyadmin_Phpexcel - Fatal编程技术网

删除PHPexcel中的空第一行

删除PHPexcel中的空第一行,php,sql,database,phpmyadmin,phpexcel,Php,Sql,Database,Phpmyadmin,Phpexcel,我正在使用phpexcel将excel文件上传到网站上的数据库中。 但第一行被跳过并输入了我的数据。 结果如下图所示 我需要帮助 我怎样才能解决这个问题 我有以下代码 <? include_once('./_common.php'); //database option include 'Classes/PHPExcel.php'; include 'Classes/PHPExcel/IOFactory.php'; //load phpexcel $

我正在使用phpexcel将excel文件上传到网站上的数据库中。 但第一行被跳过并输入了我的数据。 结果如下图所示

我需要帮助

我怎样才能解决这个问题

我有以下代码

<?
    include_once('./_common.php'); //database option 
    include 'Classes/PHPExcel.php'; 
    include 'Classes/PHPExcel/IOFactory.php'; //load phpexcel

    $up_file = "aaa.xlsx";
    try {
        $objReader = PHPExcel_IOFactory::createReaderForFile($up_file);

        //set the read only
        $objReader->setReadDataOnly(true);

        //read a excel file
        $objExcel = $objReader->load($up_file);

        // select first cell
        $objExcel->setActiveSheetIndex(0);

        $objWorksheet = $objExcel->getActiveSheet();

        $rowIterator = $objWorksheet->getRowIterator();


        foreach ($rowIterator as $row) {
                   $cellIterator = $row->getCellIterator();
                   $cellIterator->setIterateOnlyExistingCells(false);
        }

        $maxRow = $objWorksheet->getHighestRow();
        $maxCell = $objWorksheet->getHighestColumn();
         for ($i = 0 ; $i <= $maxRow; $i++) {

                 $acell = $objWorksheet->getCell('A' . $i)->getValue(); // A
                 $bcell = $objWorksheet->getCell('B' . $i)->getValue(); // B

                 $acell  = addslashes($acell);
                 $bcell  = addslashes($bcell);

              //$sql = "insert into echo_test (a,b,c,d,e) values ('$a','$b','$c','$d','$e')";
                $sql = "insert into echo_excel set 
                bcat = '$acell',
                scat = '$bcell',

              ";
              sql_query($sql);
          }
       echo $maxRow . " Data inserting finished !";



    } catch (exception $e) {
        echo 'error!';
    }

    ?>

在尝试将数据插入表之前,只需测试
$bcat
变量,看看它是否为空

$acell = $objWorksheet->getCell('A' . $i)->getValue(); // A
$bcell = $objWorksheet->getCell('B' . $i)->getValue(); // B

if (empty($bcell)) {continue;}  // no value for bcat so go to the next row

$acell  = addslashes($acell);
$bcell  = addslashes($bcell);