xlsx 中的 getHighestColumn 不起作用 [英] getHighestColumn in xlsx not working

查看:74
本文介绍了xlsx 中的 getHighestColumn 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这个代码,使用PHPExcel

Have this code, using PHPExcel

    public function getHighestColumn()
    {
      return $this->objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
    }

    public function getHighestRow()
    {
      return $this->objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
    }

我在 .xls 和 .xlsx 中保存了相同的 excel 文件它有 10 列(从 B 到 K)和 10 行

I have the same excel file saved in .xls and .xlsx It has 10 columns (From B to K), and 10 rows

当我使用 getHighestColumn 时,在 .xls 中我得到K"(正确),但在 .xlsx 中我得到 AMK(所有 Excel 工作表中的最后一列)关于这一行,使用 .xls 得到 10,但在 .xlsx 中得到 1024.我很确定,除了表格之外,工作表的其余部分都是空白的.

When I use getHighestColumn, in .xls I'm getting 'K' (correct), but in .xlsx I'm getting AMK (the last column in all excel worksheet) About the row, using .xls I'm getting 10, but in .xlsx I'm getting 1024. I'm pretty sure that, except the table, the rest of the worksheet is in blank.

知道为什么我得到不同的结果吗?

Any ideas why I'm getting different result?

这是我正在使用的阅读器

Here are the readers I'm using

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 并且在每种情况下我都使用了正确的阅读器.

I've checked with var_dump and in each case I'm using the right reader.

php 5.3.5、PHPExcel 1.7.8、Symfony 1.4

php 5.3.5, PHPExcel 1.7.8, Symfony 1.4

推荐答案

如果行和列包含任何内容(包括样式信息)而不是简单的内容.这些值也在加载电子表格时计算,因此如果您随后向工作表添加新行或列,则可能不准确.

Rows and columns are counted by getHighestColumn() and getHighestRow() if they contain anything (including style information) rather than simply having content. These values are also calculated when the spreadsheet is loaded, so may not be accurate if you subsequently add new rows or columns to the worksheet.

相反,使用 getHighestDataColumn()getHighestDataRow() 方法返回实际包含单元格中数据值的最高行和列.虽然效率较低,但它们实际上在调用时计算最高单元格引用,虽然速度较慢,但​​始终准确

Instead, use the getHighestDataColumn() and getHighestDataRow() methods to return the highest row and column that actually contain data values in cells. While less efficient, they actually calculate the highest cell reference when called, which is slower, but always accurate

这篇关于xlsx 中的 getHighestColumn 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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