简体   繁体   中英

Read cells from Excel file in laravel

i am using Laravel Excel v2.1.* for Laravel 5

https://github.com/Maatwebsite/Laravel-Excel

Route::get('/', function () {

    $rows = Excel::load('storage\\app\\demo.xlsx')->ignoreEmpty()->skip(1)->get();
  echo "<pre>";
        print_r($rows->toArray());
        echo "</pre>";
  });

if my excel file have first row as heading and then values then its working fine.

在此输入图像描述

but i have excel file where first row of the excel file are have merged cells .so is there any option to read cell by cell

but my excel files first row is having

在此输入图像描述

You'll have to read this file out differently, you can't use the simple import methods. You have to read it out per coordinate, example of the native PHPExcel methods:

http://docs.typo3.org/typo3cms/extensions/phpexcel_library/1.7.4/manual.html#_Toc237519900

Maybe this can help you. This is from the link that Reiah Paul Sam wrote. It's a loop to read all the cells of the excel file.

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load('storage\\app\\demo.xlsx');
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
    echo '<tr>' . "\n";

    $cellIterator = $row->getCellIterator();

    $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
    // even if it is not set.
    // By default, only cells
    // that are set will be
    // iterated.
    foreach ($cellIterator as $cell) {

        echo '<td>' . $cell->getValue() . '</td>' . "\n";

    }

     echo '</tr>' . "\n";

}

echo '</table>' . "\n";

Note that maybe you will need the zip extension enable in your php.ini

I hope that this help. Best Regards.

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