How to get the number of columns of worksheet as integer (28) instead of Excel-letters (“AB”)?

后端 未结 6 401
一生所求
一生所求 2020-12-12 22:19

Given:

$this->objPHPExcelReader = PHPExcel_IOFactory::createReaderForFile($this->config[\'file\']);
$this->objPHPExcelReader->setLoadSheetsOnly(a         


        
6条回答
  •  渐次进展
    2020-12-12 23:19

    I suggest to convert excel to array, clean it from empty elements and then count the number of columns:

    protected function getColumnsCheck($file, $col_number) {
            if (strstr($file, ".xls") != false && strstr($file, ".xlsx") != false) {
                $fileType = PHPExcel_IOFactory::identify($file);
                $objReader = PHPExcel_IOFactory::createReader($fileType);
                $objPHPExcel = $objReader->load($file);
                $columns_empty = $objPHPExcel->getActiveSheet(0)->toArray()[0]; 
    
                $columns = array_filter($columns_empty);
    
                return ($col_number==count($columns));
            }
            return false;
        }
    

提交回复
热议问题