Take the 2-minute tour ×

Here's my code I copied from the documentation of PHPExcel. I'm trying to read specific cell values. Any help will be appreciated.


$inputFileType = 'Excel2007';
$inputFileName = 'cohort1.xlsx';
$sheetname = 'Sheet1';

/**  Define a Read Filter class implementing PHPExcel_Reader_IReadFilter  */ 
class MyReadFilter implements PHPExcel_Reader_IReadFilter
    public function readCell($column, $row, $worksheetName = 'Sheet1') {
        //  Read rows 1 to 7 and columns A to E only 
        if ($row >= 1 && $row <= 7) {
            if (in_array($column,range('A','E'))) {
                return true;
        return false; 

/**  Create an Instance of our Read Filter  **/ 
$filterSubset = new MyReadFilter(); 

/**  Create a new Reader of the type defined in $inputFileType  **/ 
$objReader = PHPExcel_IOFactory::createReader($inputFileType); 
/**  Tell the Reader that we want to use the Read Filter  **/ 
/**  Load only the rows and columns that match our filter to PHPExcel  **/ 
$objPHPExcel = $objReader->load($inputFileName); 


I have an excel file that I want to read using PHP. It's a pretty big table that's why I decided to use excel instead of database tables.

I would also like to know if there is any other better way of doing this. Thanks.

share|improve this question
add comment

2 Answers

You might want to include() the file that defines the PHPExcel_Reader class.

If you want to read a lot of data, you might consider saving the Excel file in .csv format (comma separated value). Then you can use fgetcsv() and fputcsv() and iterate across the file one row at a time.

If you want anything more specific, we'll need more detail on what you're trying to accomplish.

share|improve this answer
add comment

Include the PHPExcel class itself before defining your read filter: that will enable the autoloader, which should then be able to find all the core PHPExcel class files, including PHPExcel_Reader_IReadFilter.

share|improve this answer
add comment

Your Answer


