Question

I have an excel sheet having three worksheets, I am having trouble in fetching records from second worksheet.

All three worksheet is having different kind of records and with different fields, I try to google it but couldn't find a solution.

Was it helpful?

Solution

You can refer,

http://phpexcel.codeplex.com/

This is good project developed for excel reader and writer. You can use it for your project. It has all necessary methods that are required for excel.

OTHER TIPS

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';
$file = '/media/sf_E_DRIVE/om/newData.xlsx';
$inputFileType = PHPExcel_IOFactory::identify($file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file);
$objWorksheet = $objPHPExcel->getActiveSheet();
$CurrentWorkSheetIndex = 0;

foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
    // echo 'WorkSheet' . $CurrentWorkSheetIndex++ . "\n";
    echo 'Worksheet number - ', $objPHPExcel->getIndex($worksheet), PHP_EOL;
    $highestRow = $worksheet->getHighestDataRow();
    $highestColumn = $worksheet->getHighestDataColumn();
    $headings = $worksheet->rangeToArray('A1:' . $highestColumn . 1,
        NULL,
        TRUE,
        FALSE);

    for ($row = 2; $row <= $highestRow; $row++) {

        $rowData = $worksheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
        $rowData[0] = array_combine($headings[0], $rowData[0]);
        print_r($rowData);


    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top