Laravel Excel: how to get value of a cell?

血红的双手。 提交于 2019-12-10 15:19:39

问题


I've loaded .xls file with 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.


回答1:


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.




回答2:


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
  ...
}



回答3:


try this

$sheet->getCell('A1')->setCell($sheet->getCell('B1')->getValue);

more info you can find here



来源:https://stackoverflow.com/questions/38074802/laravel-excel-how-to-get-value-of-a-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!