有这样的代码,使用PHPExcelgetHighestColumn在XLSX工作不
public function getHighestColumn()
{
return $this->objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
}
public function getHighestRow()
{
return $this->objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
}
我已经在同一个excel文件保存在.xls和原来的.xlsx 它有10列(从B到K)和10行
当我使用getHighestColumn
,在.xls中,我得到'K'(正确),但在.xlsx中我得到AMK(所有excel工作表中的最后一列) 关于该行,使用.xls I' m得到10,但在.xlsx我得到1024. 我很确定,除了表格,其余的工作表是空白的。
任何想法,为什么我得到不同的结果?
下面是我使用
public function openReader($filePath)
{
//aca determinamos cual tipo es para saber que reader es
$reader_5 = new PHPExcel_Reader_Excel5();
$reader_07 = new PHPExcel_Reader_Excel2007();
$inputFileType = $this->canRead(new PHPExcel_Reader_Excel5(), $filePath, self::EXCEL5);
if($inputFileType === '')
$inputFileType = $this->canRead(new PHPExcel_Reader_Excel2007(), $filePath, self::EXCEL2007);
else
{
throw new Exception("No se puede procesar el archivo; el formato no es correcto");
}
return PHPExcel_IOFactory::createReader($inputFileType);
}
private function canRead($reader, $path, $readerType)
{
return $reader->canRead($path) ? $readerType: '';
}
public function persist($fileName)
{
$filePath = sfConfig::get('sf_upload_dir').'\\'.$fileName;
$this->objReader = $this->openReader($filePath);
//Set only first Sheet
$this->setOnlyFirstSheet();
$this->createObjPHPExcel($filePath);
echo $this->getHighestColumn();
echo $this->getHighestRow();
}
我已经var_dump
检查,并在每种情况下我使用恰当的读者以飨读者。
PHP 5.3.5,1.7.8 PHPExcel,Symfony的1.4
你不应该得到的XLS文件中的最高列“B”,如果你有在列数据'K'....但在MS EXcel中打开xlsx文件,然后按Ctrl-End来查看它认为最后一个单元格是什么 – 2013-04-09 13:40:01
另外,因为行和列由getHighestColumn()和getHighestRow()计算,如果它们包含_anything_ (包括样式信息)而不是简单地包含内容,请查看getHighestDataColumn()和getHighestDataRow()方法 – 2013-04-09 13:42:47
我的意思是,获得'K'是一个错字。检查方法 – 2013-04-09 13:45:11