Phpexcel读取删除的行? [英] Phpexcel reads deleted rows?

查看:318
本文介绍了Phpexcel读取删除的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行一些QA之后,我发现PHPExcel仍然在Excel工作表中读取已删除的行(使用Delete / Backspace键删除),它不应该,就像它能够访问某种缓存一样。

当我尝试打印已删除行返回的内容时,它只是空白,但它仍包含导入结果中已删除的行。



我应该使用什么样的支票/条件才能跳过空行?



< b>我尝试了什么:



这是我的代码块,当选择文件时调用:



After performing some QA, I discovered that PHPExcel still reads the deleted rows (deleted using Delete/Backspace key) in an Excel worksheet which it shouldn't, as if it is able to access some sort of cache.
When I try to print what the deleted row returns, it's just blank, but it still includes that deleted row in the import results.

What kind of check/conditions should I use so it just skips the blank rows?

What I have tried:

Here's a block of my code that is called when a file is selected:

public function importTraining() {
        $is_imported = false;

        $read_sheet  = $this->obj_reader->getActiveSheet();
        $has_error   = false;

        $maxRow = $read_sheet->getHighestDataRow();

        foreach ($read_sheet->getRowIterator() as $row) {
            $this->emptyValues();
            $cellIterator = $row->getCellIterator();

            $employee_code;

            foreach ($cellIterator as $cell) {
                $current_row    = $cell->getRow();
                
                $cell_value     = $cell->getFormattedValue();
                $column         = $cell->getColumn();
                $current_column = PHPExcel_Cell::columnIndexFromString($cell->getColumn());

                if ($current_row == 1) {
                    $column_header[$column] = strtolower(trim($cell_value));
                }else{
                    $column_header_value = strtolower(trim($column_header[$column]));

                    switch ($column_header_value) {

                        case 'employee no.':
                            if( $cell_value != null){
                                $employee_code = trim($cell_value);
                                $ec = G_Employee_Finder::findByEmployeeCode($employee_code);
                                if ($ec)
                                {
                                  $employee_code = $ec->getId();
                                  $this->fields['employee_id'] = $employee_code;
                                }

                            }
                            break;

                        case 'training':
                            if( $cell_value != null ){
                                $this->fields['description'] = trim($cell_value);
                            }
                            break;

                        case 'from(date)':
                            if( $cell_value != null ){
                              $date_format = $this->convertToDate(trim($cell_value));
                              $this->fields['from_date'] = $date_format;

                              if( strtotime($date_format) <= 0 ){
                                  $has_error = true;
                              }
                            }
                            break;

                        case 'to (date)':
                            if( $cell_value != null){
                                $date_format = $this->convertToDate(trim($cell_value));
                                $this->fields['to_date'] = $date_format;

                                if( strtotime($date_format) <= 0 ){
                                    $has_error = true;
                                }
                            }
                            break;

                        case 'provider/trainor':
                            if( $cell_value != null){
                                $this->fields['provider'] = trim($cell_value);

                            }
                            break;
                        case 'location':
                            if( $cell_value != null ){
                                $this->fields['location'] = trim($cell_value);
                            }
                            break;

                        default:
                            break;
                    }
                }
            } //end of cell loop

            if( $current_row > 1 ){
              $has_error = false;
                if ((!isset($this->fields['employee_id']))) {
                    $this->addErrorMissingEmployeeCode($current_row); 
                    $has_error = true;
                }

                //check if training exists
                $from_date = $this->fields['from_date'];
                $to_date = $this->fields['to_date'];
                $provider = $this->fields['provider'];
                $location = $this->fields['location'];
                $description = $this->fields['description'];

                if (isset($this->fields['employee_id']))
                {
                  $employee_id = $this->fields['employee_id'];
                  $y = $this->doesTrainingExist($employee_id, $from_date, $to_date, $provider, $location, $description);
                  if ($y)
                  { 
                    $this->addErrorDuplicateTraining($current_row);
                    $has_error = true;
                  }
                }

                if (!$has_error) {
                    $this->addTraining();
                    $this->successful_import++;
                }
            } // if current row > 1
        } //end of row loop

        $has_error = false;
        $this->emptyValues();
        return true;
    }





导入结果显示如下:

1.成功导入

2.重复字段

3.无法识别的数据

- >删除后,在第一次成功导入后,删除的行将包含在此部分中。



The import results show the following:
1. Successful imports
2. Duplicate fields
3. Unrecognized data
--> The deleted row becomes included in this part after deleting it AFTER being able to successfully import it the first time.

推荐答案

is_imported = false;

is_imported = false;


read_sheet =
read_sheet =


this-> obj_reader-> getActiveSheet();
this->obj_reader->getActiveSheet();


这篇关于Phpexcel读取删除的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆