首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php中读取Excel空白列

问在php中读取Excel空白列
EN

Stack Overflow用户
提问于 2016-07-27 12:40:17
回答 1查看 73关注 0票数 0

我正在使用PHPExcel_IOFactory上传excel,在excel中有一些列应该强制填写,如B,D,I,J等。

我的需要是首先更改B列,如果它是空的,就会发生错误,否则检查D列,如果是空的错误,则检查其他列。

我已经写了下面的代码,但我不需要一次检查一列:

代码语言:javascript
复制
 $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
 $arrayCount = count($allDataInSheet); 
 for($i=2;$i<=$arrayCount;$i++){
    $b = $allDataInSheet[$i]["B"];
    $d = $allDataInSheet[$i]["D"];
    $i = $allDataInSheet[$i]["I"];
 }

几乎有20列是必须的,我如何一次检查每一列。

EN

回答 1

Stack Overflow用户

发布于 2016-07-27 12:57:13

注意。您在for($i=2...行中使用了$i,但是在使用$i = $allData...的循环中将其设置为其他值。

为了满足你的要求(包括从第二行开始),我会这样做

代码语言:javascript
复制
$firstK = key($allDataInSheet); //save the first key

foreach($allDataInSheet as $k => $row){
    if($k===$firstK) continue; //skip the first row

    if(empty($b = $row['B'])){
        // Error. column B is empty
    }elseif(empty($c = $row['C'])){
        // B is not empty. $b has its contents
        // however, Error: column C is empty
    }elseif(empty($i = $row['I'])){
        // B and C are not empty. $b and $c have their contents
        // however, Error: column I is empty
    ...
    }else{
        // All required columns have data
        // $b, $c ... $i ... hold the contents
    }

    //...continue processing the row. You can use variables $b, $c...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38603852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档