Php xlsx中的getHighestColumn不工作
使用PHPExcel获取此代码Php xlsx中的getHighestColumn不工作,php,phpexcel,Php,Phpexcel,使用PHPExcel获取此代码 public function getHighestColumn() { return $this->objPHPExcel->setActiveSheetIndex(0)->getHighestColumn(); } public function getHighestRow() { return $this->objPHPExcel->setActiveSheetI
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我得到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\u dump
,在每种情况下,我都使用了正确的阅读器
PHP5.3.5、PHPExcel 1.7.8、Symfony 1.4行和列按
getHighestColumn()
和getHighestRow()
计数,如果它们包含任何内容(包括样式信息),而不是简单地包含内容。加载电子表格时也会计算这些值,因此如果随后向工作表中添加新行或新列,这些值可能不准确
相反,使用
getHighestDataColumn()
和getHighestDataRow()
方法返回实际包含单元格中数据值的最高行和列。虽然效率较低,但它们在调用时实际计算最高单元格引用,速度较慢,但总是准确的如果列“K”中有数据,则xls文件中最高列不应得到“B”。。。。但是,在MS EXcel中打开xlsx文件并执行Ctrl End以查看它认为最后一个单元格也是如此,因为行和列是由getHighestColumn()和getHighestRow()计算的,如果它们包含任何内容(包括样式信息),而不是简单地包含内容,请查看getHighestDataColumn()和getHighestDataRow()方法,这意味着获得“K”,这是个打字错误。检查一下methods@MarkBaker它就像一个符咒!!谢谢,请将其作为答案发布,这样我可以打勾,因为提供的代码可能会有所帮助,但为了使其成为一个好的答案,您还应该描述/解释您的代码解决问题的原因/方式。
$highestColumn = $sheet->getHighestColumn();
$colNumber = PHPExcel_Cell::columnIndexFromString($highestColumn);