简体   繁体   中英

PHPExcel function getHighestRow() is NOT working for .xls but working for .xlsx

I am using PHPExcel to read its content based on no.of rows present.

To find no.of rows I am using following function.

$objSheet->getHighestRow();

It is working fine for .xlsx files.

But it is NOT working in .xls.

Fatal error: Call to a member function getHighestRow() on a non-object

So how i can get no.of rows of excel ?

PHP Code:

    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";

I want both xls & .xlsx to be supported... Please guide me.

I solved this problem myself. It is due excel version incompatibility.

Here is the code to resolve this issue.

/**  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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM