我正在使用PHPExcel来根据no.of行读取其内容。
要查找no.of行,我使用以下函数。
$objSheet->getHighestRow();它在.xlsx文件中运行良好。
但这是而不是在.xls工作。
致命错误:调用非对象上的成员函数getHighestRow()
那么,我如何才能获得excel的no.of行呢?
PHP代码:
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
/** PHPExcel_IOFactory */
include 'www/PHPExcelReader/Classes/PHPExcel/IOFactory.php';
include 'www/PHPExcelReader/Classes/PHPExcel/Classes/PHPExcel.php';
try {
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setReadDataOnly(true);
$objReader->setLoadSheetsOnly( array("Sheet1") );
$objPHPExcel = $objReader->load($inputFileName);
$objSheet = $objPHPExcel->getActiveSheet();
$no_of_rows=$objSheet->getHighestRow();
//echo "no_of_rows=$no_of_rows";我希望xls和.xlsx都能得到支持.请引导我。
发布于 2014-03-02 06:42:28
我自己解决了这个问题。这是由于excel版本不兼容。
下面是解决此问题的代码。
/** Identify the type of $inputFileName **/
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
/** Create a new Reader of the type that has been identified **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);https://stackoverflow.com/questions/22119213
复制相似问题