【问题标题】:Excel file to Html using Maatwebsite/Laravel-Excel使用 Maatwebsite/Laravel-Excel 将 Excel 文件转换为 Html
【发布时间】:2016-06-07 12:43:12
【问题描述】:

我只是从这里 https://github.com/Maatwebsite/Laravel-Excel/ 设置 Maatwebsite/Laravel-Excel 插件。我想在 laravel 的刀片中读取 excel 文件并在 Html 表中显示数据。我通过以下方式获取数据:

$content=Excel::load($file, function($reader) {

})->get();

当我回显 $content;我有关注::

SheetCollection {#762 ▼
  #title: ""
  #items: array:3 [▼
    0 => RowCollection {#623 ▼
      #title: "Sheet1"
      #items: array:4 [▼
        0 => CellCollection {#693 ▼
          #title: null
          #items: array:2 [▼
            "name" => "Abc"
            "city" => "City1"
          ]
        }
        1 => CellCollection {#692 ▼
          #title: null
          #items: array:2 [▼
            "name" => "Xyz"
            "city" => "city2"
          ]
        }
        2 => CellCollection {#710 ▼
          #title: null
          #items: array:2 [▼
            "name" => "Name2"
            "city" => "city3"
          ]
        }
        3 => CellCollection {#709 ▼
          #title: null
          #items: array:2 [▼
            "name" => "Name2"
            "city" => "city3"
          ]
        }
      ]
    }
    1 => RowCollection {#728 ▼
      #title: "Sheet2"
      #items: []
    }
    2 => RowCollection {#697 ▼
      #title: "Sheet3"
      #items: []
    }
  ]
}

这些是我的 xlsx 文件中的数据。现在我想在 view Blade 上渲染它。任何想法????谢谢

【问题讨论】:

标签: laravel


【解决方案1】:

你可以使用 Laravel Collections 方法来获取数据。探索这些方法,但我认为您可以尝试这样的方法。

return $content->all();

或迭代每一行并将它们格式化存储在您的数据中,以使用每行将其呈现在刀片视图中。

$content->each(function($row){
   // process here each row
}); 

希望对你有帮助。

【讨论】:

  • 使用这个我无法获取 excelsheet 的头部
猜你喜欢
  • 2019-05-20
  • 2014-11-12
  • 1970-01-01
  • 2017-11-12
  • 2015-06-12
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 2021-07-26
相关资源
最近更新 更多