tags:

views:

32

answers:

3

Hi, I have an excel sheet that is loaded with a dynamic result set of data.I need to validate the excel sheet before insert into mysql table.Validation such as Is there any duplicate entry,email validation etc.Any idea about how can validate using php.

A: 

How do you parse the xls itself? For me the most simple solution is to parse the whole xls into an array then validate that. You can easily check for duplicates then iterate through with one foreach and validate the remaining.

fabrik
+1  A: 

As easy as :

  • parse your excel using phpexcel for example
  • make an array with all entries.
  • use array_unique to discart duplicates
  • then validate email fields
youssef azari
A: 

You cna use COMS under PHP

$excel = new COM("excel.application") or die("Unable to instanciate excel");

//Open your file
$excel->Workbooks->Open("files/test.xls");

$Workbook = $excel->Worksheets(1); //Select the wortksheet
foreach($Workbook = $excel->Worksheets as $Worksheet)
{
   //Loop each page in the book
   $Worksheet->Activate; //Activate Sheet 1

   for($row=0;$row<=$Worksheet->rows;$row++)
   {
       $row_item = $Worksheet->rows[$row];
       //Hmm, i forgot the rest but you can do that ;)
   }
}

You will have to read more about it, as i have never used it to open Excel sheets.

http://www.php.net/manual/en/class.com.php

RobertPitt
COM isn't available only under Win? OP didn't mentioned his environment so there's a chance his script will die @ line 1.
fabrik
true, but if he is under windows then my answer may be useful
RobertPitt
Thanks....Sorry.I am under Linux platform.
Ajith
Thank you for all of your participation.
Ajith