有這樣的代碼,使用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