【问题标题】:Read cells from Excel file in laravel从 laravel 中的 Excel 文件中读取单元格
【发布时间】:2017-12-12 03:39:40
【问题描述】:

我正在为 Laravel 5 使用 Laravel Excel v2.1.*

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>";
  });

如果我的 excel 文件有第一行作为标题,然后是值,那么它工作正常。

但我有 excel 文件,其中 excel 文件的第一行已合并单元格。所以有任何选项可以逐个单元格读取

但我的 excel 文件第一行有

【问题讨论】:

    标签: php laravel laravel-5.3 phpexcel


    【解决方案1】:

    你必须以不同的方式读出这个文件,你不能使用简单的导入方法。您必须按坐标读取它,本机 PHPExcel 方法的示例:

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

    【讨论】:

      【解决方案2】:

      也许这可以帮助你。这是来自 Reiah Paul Sam 写的链接。循环读取excel文件的所有单元格。

      $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";
      

      请注意,您可能需要在 php.ini 中启用 zip 扩展

      希望对您有所帮助。 最好的问候。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        • 1970-01-01
        • 2012-03-02
        • 1970-01-01
        相关资源
        最近更新 更多