Home » excel » How to get a value from specific cell address in Excel through Laravel

How to get a value from specific cell address in Excel through Laravel

Posted by: admin May 14, 2020 Leave a comment

Questions:

Is there any way to get the cell value with exact address in Excel?

Like I upload the excel file then return sheet(2).cell(10,1).value ?

Since I am writing a website to upload a excel and put those data into DB,
the file’s rows and columns are automatically generated and the formats are not exactly matching maatwebsite/Excel’s upload sample.

I am using Laravel 5.7 and maatwebsite/Excel 3.1

How to&Answers:

In maatwebsite/Excel 2.* you could fetch the value in the cell with

Excel::load('file.xlsx, function($excel) {
    $cell = $excel->getSheet(2)->getCellByColumnAndRow(10, 1);       
});

These methods have been removed in 3.*

However maatwebsite/Excel is just a wrapper around phpoffice/phpspreadsheet – so we can still call the function directly from that library:

$inputFileName = 'filename.xlsx';

$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);

$cellValue = $spreadsheet->getSheet(2)->getCellByColumnAndRow(10, 1)->getValue();

Answer:

I hope this would be help to you.