Excel validation in Laravel

178 views Asked by At

I'm trying to do some Excel validation when uploading a file. This is what my Excel file looks like.

Name   | Price 1 | Price 2 | Price 3 | Total
Item 1 | 123     | 123     | 123     | 369
Item 2 | 1200    | 300     | 900     | 2400

I need to make sure that Price 1, Price 2, Price 3 = Total for each row in the Excel sheet, and if it doesn't, then the upload fails. I'm not sure how to even start checking. I'm also using Laravel and phpoffice/phpspreadsheet. This is what I've got so far.

// $path is from the excel upload
$xl = IOFactory::load($path);
$sheet = $xl->getSheetByName('ITEMS');

$col = $sheet->getHighestDataColumn();
$row = $sheet->getHighestDataRow();

$items = $sheet->rangeToArray("A1:{$col}{$row}", null, false);

foreach($items as $item)
{
}
0

There are 0 answers