vendredi 4 juillet 2014

Displaying html table and also exporting it to excel file


Vote count:

0




Here is my code which upload any xlsx file process it and display it on browser as a TABLE.



echo '<h1>Parsing Result</h1>';
echo '<table border="1" cellpadding="3" style="border-collapse: collapse">';
$eng = array();
list($cols,) = $xlsx->dimension();
foreach( $xlsx->rows() as $k => $r) {
// if ($k == 0) continue; // skip first row
echo '<tr>';
for( $i = 0; $i < $cols; $i++)
{
$temp = $Arabic->ar2en($r[$i]);
echo '<td>'.( (isset($r[$i])) ? $temp : '&nbsp;' ).'</td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
<h1>Upload</h1>
<form method="post" enctype="multipart/form-data">
*.XLSX <input type="file" name="file" />&nbsp;&nbsp;<input type="submit" value="Parse" />
<br/>
Select xlsx file with Arabic content
</form>


Now here I tried to export the above html table content to XLSX file. Issues are



  1. Now html table does not appear on browser screen

  2. xlsx file generated from table also displays form content/. i.e. Upload *.XLSX and parse button


What I want



  1. Table should be displayed on screen along with creating xlsx file of table content

  2. xlsx file should not content form content, except table data


Here is the code which generate xlsx file from table:



$file="demo.xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo '<table border="1" cellpadding="3" style="border-collapse: collapse">';
$eng = array();
list($cols,) = $xlsx->dimension();
foreach( $xlsx->rows() as $k => $r) {
// if ($k == 0) continue; // skip first row
echo '<tr>';
for( $i = 0; $i < $cols; $i++)
{
$temp = $Arabic->ar2en($r[$i]);
echo '<td>'.( (isset($r[$i])) ? $temp : '&nbsp;' ).'</td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
<h1>Upload</h1>
<form method="post" enctype="multipart/form-data">
*.XLSX <input type="file" name="file" />&nbsp;&nbsp;<input type="submit" value="Parse" />
</form>


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire