Open specific column XLS and save to CSV

Topics: Developer Forum
Aug 9, 2012 at 7:13 AM

This is my code:



/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

/**$inputFileType = 'Excel5';
$inputFileName = './sampleData/prodotti.xls';

 $objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcelReader = $objReader->load($inputFileName);*/

class MyReadFilter implements PHPExcel_Reader_IReadFilter
	public function readCell($column, $row, $worksheetName = '') {
		// Read title row and rows 20 - 30
		if ($row == 1 || ($row >= 20 && $row <= 30)) {
			return true;
		return false;

$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setReadFilter( new MyReadFilter() );

$objPHPExcel = $objReader->load("prodotti.xls");

$loadedSheetNames = $objPHPExcel->getSheetNames();

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');

foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {



But dont save file


Aug 9, 2012 at 7:37 AM
Edited Aug 9, 2012 at 7:39 AM

Using Excel2007 reader to try and load an .xls file could be a good starter for 1... try using the correct reader for filetype, or let PHPExcel decide for you.

Check file permissions for your ./sampleData directory.

Add some error handling... e.g. try/catch blocks. Any error messages that you aren't catching should be displayed on screen anyway.

Aug 9, 2012 at 7:49 AM

The permission of ./sampleData directory is ok. The script whit green code in write work fine.

the error is this:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Aug 9, 2012 at 8:47 AM
Edited Aug 9, 2012 at 8:48 AM

Have you checked the server error logs?

The most likely causes are that you're hitting a memory limit or a timeout limit, though you're only reading a few rows from each worksheet

Aug 9, 2012 at 4:55 PM

Im sorry the path of file......