Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML table to excel - PHP

Tags:

html

php

excel

I am creating a report in Table format. This report is displayed on the browser. I want to provide a download report in excel format link so that the report can be available in excel file also. How can I do this

like image 828
Mohd Viqar Avatar asked Aug 09 '10 06:08

Mohd Viqar


People also ask

How do I export data from HTML table to excel using php?

Under head tag we create title tag in which we show title of webpage. And link some additional scripts to help button to export data in excel files. Now, inside body here we create a table. We can also display data from database with the help of php.


2 Answers

Either you can use CSV functions or PHPExcel Or there is even a better and a simple solution. Just put the Table HTML in a file and save it as XLS file but that might give variety of problems.

like image 172
Shubham Avatar answered Oct 05 '22 22:10

Shubham


<?php
$file="test.xls";
$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $test;
?>
like image 23
Vibin TV Avatar answered Oct 06 '22 00:10

Vibin TV