【问题标题】:How to read a table from an Excel document that has empty rows using Laravel如何使用 Laravel 从具有空行的 Excel 文档中读取表格
【发布时间】:2016-07-18 16:15:13
【问题描述】:

大家好,我在使用 LARAVEL 从不是从原始 1 冒号 1 (A1) 开始的 Excel 文档中读取表格时遇到问题,在此文档中有一个标题和一些空行,如图所示:Excel table image

这是我用来从文档中加载表格的代码,同时如果我删除了所有标题文本和所有空单元格,它工作正常!

     Excel::load(Input::file('file'), function($reader) {

// Getting all results
$results = $reader->get();
foreach ($results as $r =>$v) {
     $person = new Person;
        $person->name = $v['name'];
        $person->age = $v['age'];
        $person->save();
}

【问题讨论】:

  • 你用什么扩展或工具来读取excel文件?
  • 我正在使用 maatwebsite/excel

标签: php excel laravel laravel-5.2


【解决方案1】:

Yupiiii!通过转到配置文件找到了解决此问题的方法: \laravel-Project\config\excel.php 并更改以下行:

  /*
    |--------------------------------------------------------------------------
    | First Row with data or heading of data
    |--------------------------------------------------------------------------
    |
    | If the heading row is not the first row, or the data doesn't start
    | on the first row, here you can change the start row.
    |
    */

    'startRow'                => 1,

并将数字 1 更改为表格开始的任何行^^!

【讨论】:

    猜你喜欢
    • 2023-01-02
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多