【问题标题】:Laravel Excel: how to get value of a cell?Laravel Excel:如何获取单元格的值?
【发布时间】:2016-06-28 11:20:04
【问题描述】:

我已经用Laravel Excel 加载了.xls 文件:

Excel::load('public/files/20160621.xls', function($reader) {
    // read a cell value
});

如何读取加载的 Excel 文件的单元格值?这部分的文档似乎不清楚。

【问题讨论】:

    标签: php laravel phpexcel laravel-excel


    【解决方案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);           
    
        });
    }
    

    您是对的,阅读某些单元格的文档不清楚。 希望这会对你有所帮助。

    【讨论】:

      【解决方案2】:

      试试这个

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

      更多信息你可以找到here

      【讨论】:

        【解决方案3】:

        供阅读使用

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

        【讨论】:

        • 一般来说,如果答案包含对代码的用途的解释,以及为什么在不介绍其他人的情况下解决问题的原因,答案会更有帮助。
        猜你喜欢
        • 2012-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-29
        相关资源
        最近更新 更多