Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: Getting 'Active sheet index is out of bounds.' error

$
0
0

I am using Windows XP SP3 with PHPExcel 1.76.

I am writing an application that reads in an XLS file that was created by another program.  Whenever I get to the line:

$objWorksheet = $objPHPExcel->setActiveSheetIndex('0');

it errors out on me with this error: "PHP Fatal error:  Uncaught exception 'Exception' with message 'Active sheet index is out of bounds.'"

After much tinkering, I found that if I open that XLS file in Excel and resave it, the application will have no problem with the file.  I noticed that it does add a few KB when I resave it, so it must be changing something.  Any ideas of how I can get around this?  I tried to open and save it using PHPExcel, but it corrupted the file instead.  Here is the code I tried to do that with.

$objPHPExcel = $objReader->load($filename);
	try {
		$objWorksheet = $objPHPExcel->setActiveSheetIndex('0');
	} catch(Exception $e) {
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save($filename);
		$objPHPExcel = $objReader->load($filename);
		$objWorksheet = $objPHPExcel->setActiveSheetIndex('0');
	}

Any help would be appreciated.

Thanks

Mike


Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>