0

I have this code that exports a html table to excel.

print $obj->methodThatReturnTable();

header("Content-type: application/vnd.ms-excel");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=$fileName");
header("Pragma: no-cache");

It works fine for tables with a few rows, but now I have created a table with almost 1000 rows (8 columns) and instead of the download be forced, the table is showed in the browser.

What could be happening?

9
  • 1
    You must send headers before print your excel content with $obj->methodThatReturnTable() Commented Oct 22, 2014 at 15:33
  • I did that and the download was the php file Commented Oct 22, 2014 at 15:35
  • Your "Content-Type" header is duplicated, is that normal ? Try : header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$fileName"); header("Pragma: no-cache"); $obj->methodThatReturnTable(); Can you post the content of your methodThatReturnTable function ? Commented Oct 22, 2014 at 15:41
  • I guess it's normal, because it works for table with a few rows. The content of the method just return a table in html. It's too many lines to be posted, won't help. I THINK the problem is the size of the table, but I can't find anything to solve this problem... Commented Oct 22, 2014 at 15:47
  • 1
    I know, but it's not the right way to do this. It's better to start things properly. The lib i recommanded you will facilate your job when you should use xls specific features like "Formula" Commented Oct 22, 2014 at 15:54

1 Answer 1

3

Please check PHP: Exporting Data to Excel. It may help you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.