Laravel Excel:如何获取单元格的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38074802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:04:22 来源:igfitidea点击:
Laravel Excel: how to get value of a cell?
提问by qwaz
I've loaded .xls
file with Laravel Excel:
我已经.xls
用Laravel Excel加载了文件:
Excel::load('public/files/20160621.xls', function($reader) {
// read a cell value
});
How do I read values of cells of the loaded excel file? Documentation seems to be unclear on that part.
如何读取加载的 excel 文件的单元格值?该部分的文档似乎不清楚。
回答by Demian
public function get()
{
$excelFile ...
return Excel::load($excelFile, function($doc) {
$sheet = $doc->getSheetByName('data'); // sheet with name data, but you can also use sheet indexes.
$sheet->getCell('A1');
$sheet->getCellByColumnAndRow(0,0);
});
}
You're right, the documentation to read some cells is unclear. Hope this will help you.
您说得对,读取某些单元格的文档不清楚。希望这会帮助你。
回答by Gabriel Hans González Pe?a
for read use this
阅读使用这个
public function reader($file)
{
$excel=Excel::load($file, function($reader) {
$reader->...//Document propities
$sheet = $doc->getSheet(0); // sheet with index
$cell=$sheet->getCell('A1')->getValue();
})->toArray()//get();
...
$cell=$excel->index//[row][col] Get formatted type(date,currency,calculated) cells
...
}