How to export html to table to excel

Aug 24, 2012 at 1:10 PM
Edited Aug 24, 2012 at 1:14 PM

Please! help i have no idea on how to export my html document to excel using phpexcel. below is my php code that i want to export to excel.. can you please give me a step by step process on how to export the below php code to excel.

 

<html>

<body>
<?php       ob_start();     if (!isset($_SESSION)) {       session_start();     } 
$studID = isset($_GET['search']) ? mysql_real_escape_string(htmlentities(trim($_GET['search'])))  : "";
$syr = $_SESSION['CURRENT_SY'];$activeSem = $_SESSION['CURRENT_SEM'];
$sqlCk = @mysql_query("SELECT STUDENTNUM FROM student_grade WHERE STUDENTNUM='$studID'");if(mysql_num_rows($sqlChk)){echo '<p class="message">No subject(s) found.</p>';header( "refresh:3;url=registrar.php?page=cert_grade_rep" );}else{$sql = @mysql_query("SELECT FNAME,MNAME,LNAME from student WHERE STUDENTNUM='$studID'") or die(mysql_error());$row = @mysql_fetch_array($sql);
$studName = $row['FNAME'] .'&nbsp;' .$row['MNAME'].'.' .'&nbsp;'.$row['LNAME'];
$sqlMaxNum = "SELECT MAX(SY) as MAX_SY FROM registration WHERE STUDENTNUM='$studID'";$maxResult = @mysql_query($sqlMaxNum) or die(mysql_error());     $row = mysql_fetch_assoc($maxResult);     $maxSY = trim($row['MAX_SY']);  $sqlReg = @mysql_query("SELECT SECTION_NAME,YEAR_LEVEL,COURSE_NAME FROM registration WHERE STUDENTNUM='$studID' AND SY='$maxSY' ");$rowR = mysql_fetch_array($sqlReg);$sec = $rowR['SECTION_NAME'];$ylevel = $rowR['YEAR_LEVEL'];$course = $rowR['COURSE_NAME'];include 'yearLevelConfig.php';$level = yearLevel($ylevel);$courseYr = $course .'&nbsp;'.$level;$dday = date("d");$syear = date("Y");$dmo = date("m");include 'emonth.php';include 'dconfig.php';$mon = convert($dmo);$mday = convertD($dday);$issue = 'Issued this&nbsp;'.$mday.'&nbsp;of&nbsp;'.$mon.',&nbsp;'.$syear.'&nbsp;for reference purposes.';//echo $issue;$sqlCourseName = @mysql_query("SELECT COURSE_DESC FROM course WHERE COURSE_NAME = '$course'");$crow = mysql_fetch_array($sqlCourseName);$cname = $crow['COURSE_DESC'];
$sqlGetRecFrmReg = @mysql_query("SELECT SY, SEMESTER, YEAR_LEVEL FROM registrationWHERE STUDENTNUM='$studID' ORDER BY SY,SEMESTER, YEAR_LEVEL") or die(mysql_error()) ;$term = 'Trimester';
$getRegName = @mysql_query("SELECT FNAME,MI,LNAME from employee WHERE POS_ID='REG-2'");$rowGetN = @mysql_fetch_array($getRegName);$regName =  $rowGetN['FNAME'] .'&nbsp;' .$rowGetN['MI'].'.' .'&nbsp;'.$rowGetN['LNAME'];
$sqlEmp11 = @mysql_query("SELECT FNAME,MI,LNAME,DESIGNATION FROM employee WHERE POS_ID='VPC-1'");$re11 = mysql_fetch_array($sqlEmp11);$cooName =  $re11['FNAME'] .'&nbsp;'.$re11['MI'] .'.'.'&nbsp;' .$re11['LNAME'];$cooD = strtoupper($re11['DESIGNATION']);

echo '<table border=0 width=80% cellpadding=0 cellspacing=0>';
echo '<tr><td colspan=5>'."<a href=\"export_excel_cert.php?&search=$studID\" target=\"_blank\">".'<img src="./images/exportexcel.gif" width="100" height="25"/>'."</a>" .'</td></tr>';echo "<tr>" ."<td colspan=2 align=center>".'<img src="./images/fc.jpg" width="150" height="105"/>'  ."</td>" ."<td colspan=2 >" .'<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FORBES COLLEGE</b>' .'<br>(Formerly Global Trainers, Inc.)'.'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Legazpi City, Philippines'.'<br>&nbsp;&nbsp;&nbsp;Tel. No. (052)435-3128<br>&nbsp;&nbsp;Webiste: www.forbes.edu.ph' ."</td></tr>";
echo "<tr><td colspan=5>".'<hr style="height:1px; color:black">' ."</td><tr>";

echo "<tr><td colspan=5 align=center>".'<h3>CERTIFICATION'  .' OF ' .'GRADES</h3>' ."</td><tr>";echo "<tr><td colspan=5 align=center>" .'This is to certify that&nbsp;<b>'.$studName.'&nbsp;</b>'.'took the following subjects in this college:'.'</td></tr>';echo "<tr><td colspan=5>COURSE: <b>".$cname."</b></td></tr>";
echo "<tr></tr>";
echo '</table>';echo '<table border=1 width=80%>';echo '<col width=25%>'; echo '<col width=30%>'; echo '<col width=10%>'; echo '<col width=20%>';  echo '<col width=10%>';echo '<tr ></td><td width=5%><center><b>Subject Code</b></center></td><td width=25%><center><b>Descriptive Title</b></center></td><td width=4%><center><b>Final Rating</b></center></td><td width=4%><center><b>Removal Grade</b></center></td><td width=5%><center><b>Credit</b></center></td></tr>';echo '</table>';echo '<table border=0 width=80%>';echo '<col width=25%>'; echo '<col width=30%>'; echo '<col width=10%>'; echo '<col width=20%>';  echo '<col width=10%>';$num=0;while($row=mysql_fetch_array($sqlGetRecFrmReg)){    $syNum1 = substr($row['SY'],0,4);      $syNum2 = substr($row['SY'],4,4);  $sYear = $syNum1 .'-'.$syNum2;$num++;  $semester = $row['SEMESTER'];$syear = $row['SY'];  echo '<tr>' .'<td colspan=3><u><b>' .strtoupper($row['SEMESTER']) .'&nbsp'.$term .'&nbspSY'.'&nbsp;'.$sYear.'</u></b></td>' .'</tr>';  $sqlGetGrade = @mysql_query("SELECT SUBJECT_CODE, FINAL_RATING, COMPLETION_GRADE FROM student_subject   WHERE STUDENTNUM='$studID' AND SY='$syear'  AND SEMESTER='$semester' GROUP BY SUBJECT_CODE") or die(mysql_error());  while($row1=mysql_fetch_array($sqlGetGrade)){      $subjCode = $row1['SUBJECT_CODE']; $getTitle = @mysql_query("SELECT SUBJECT_TITLE,LEC_UNIT,LAB_UNIT FROM course_subject WHERE  SUBJECT_CODE='$subjCode'") or die(mysql_error());  $rowT = mysql_fetch_array($getTitle);  $title = $rowT['SUBJECT_TITLE'];  $unit = $rowT['LEC_UNIT'] + $rowT['LAB_UNIT'];  $credit = ($row1['FINAL_RATING']=='Drp') ? '-' : $unit;  $removal = ($row1['COMPLETION_GRADE']=="") ? "       " : $row1['COMPLETION_GRADE'];  echo '<tr><td>'.$subjCode .'<td >'.$rowT['SUBJECT_TITLE'].'</td>'.'<td ><center>'.$row1['FINAL_RATING'].'</center></td>'.'<td><center>'.$removal.'</center></td>'.'<td><center>'.$credit .'</center></td></tr>';    }
    }if($num==0){echo "<tr><td colspan=5>No grades found.</td></tr>";}else{echo "<tr><td colspan=5 align=center>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Nothing follows xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</td></tr>";echo "<tr></tr>" ;echo "<tr><td colspan=5 >".'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$issue ."</td></tr>";echo "<tr></tr>" ;
echo "<tr><td colspan=5 >" .'<p class="pad">'.'<b>'.$regName.'</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registrar'.'</p></b>' ."</td></tr>";echo "<tr><td colspan=5>" .'<b>&nbsp;&nbsp;&nbsp;'.$cooName.'</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$cooD ."</td></tr>";}echo '</table>';


?>

<!-- end of the content div --><br /> <br /><br /><br />

<?php//}}?>
</body></html>