Hi community,

I have a PHP page with a table in it that I want to export to Excel. I have seen multiple ways to export an entire PHP page to excel, but I only want to export the table within my page. Is there anyway to specify what content I would want to export to Excel using HTML or PHP or anything? I have seen this example:

$filename ="excelreport.xls";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;

but I have more than that on my page and with this method, it just downloads the whole page into excel.

Recommended Answers

All 2 Replies

You should build a second version of the page with just the info to be exported and create the excel file from that.

That's what i was trying to avoid but that's what i'll stick with until i can find something better. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.