I have written code to import data from excel sheet and for that I want to count total number of rows and columns.
I am using this SpreadsheetReader library.
Here is my code:
$uploadFilePath = 'uploads/'.basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'], $uploadFilePath);
$Reader = new SpreadsheetReader($uploadFilePath);
$Sheets = $Reader -> Sheets();
foreach ($Sheets as $Index => $Name)
{
$Reader -> ChangeSheet($Index);
foreach ($Reader as $Key => $Row){
for($i=0; $i<=TOTALCOLUMNS; $i++){//I need to count total columns here
if(!empty($Row[$i])){
if($i==0)
$parent=$Row[$i];
else{
if(!empty($Row[(int)$i-1]))
$parent=$Row[(int)$i-1];
}
$category=$Row[$i];
$data['category']=$category;
$data['parent']=$parent;
$res=saveCategory($data);
}
}
}
echo "<br>Categories imported successfully<br>";
}