I uploaded the excel and the data is successfully inserted to the database, by submitting the "submit button" using php script. There is an final stage for me to do is the validation of the excel before inserting the data to the database. I don't get any idea on validation.
In my excel, i should validate that the first row should contain "the following heading"(ie numbers,marks,grade,attention etc) and then from the second row the values should be checked(validate) by the PHP script(number should be only 8digits,marks should be <=3digits,grade should be 1digit,attention should be <=2digits and finally empty row) and finally should gets inserted to the database by successfully. How can i validate the excel rows and columns using PHP script?
I am using PHP Excel library for read the spread sheet data
Thanks in advance
You can do it using following code
$objReader = PHPExcel_IOFactory::load($filename);
$objWorksheet = $objReader->getActiveSheet();
//This will fetch the first row
$row = $objWorksheet->getRowIterator(1)->current();
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
//You can loop through the columns to see the data and match it with your some predefined array of headings.
foreach ($cellIterator as $cell) {
echo $cell->getValue();
}
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With