Jump to content

[SOLVED] xls export not working if export data too big


obay

Recommended Posts

Hi all,

 

I have a file called excel.php, which exports data into an excel file.

 

Content-Type:application/vnd.ms-excel

 

When I click the link to export, it opens a "download" dialog box, where I can "Run" or "Save" the resulting excel document.

 

This script has seemed to work perfectly for the past months but I have recently noticed that sometimes it doesn't. I noticed that it usually happens when the export data is very large. When I click on the link to export, it just opens a new, empty browser window.

 

I was thinking this is just an issue of PHP's memory limit. So I changed it from 16M to 256M (crazy, right?). But it still doesn't work. I figured later that maybe this isn't a memory problem since it doesn't take long for the page to load, it just doesn't load.

 

What do you think is causing this problem?

 

Note: in case this helps, in my excel.php file, before putting the header()s, I do a base64_decode() on the data to be exported since in the calling page, the data is base64_encode()ed.

 

This is my excel.php:

 

$excel_data = base64_decode($_POST['excel_data']);

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Pragma: no-cache');
header('Cache-Control: must-revalidate, post-check=0,pre-check=0');

//need to export as UTF-8, otherwise japanese characters will not show
header("Content-Transfer-Encoding: binary");
$excel_data =  iconv ( 'UTF-8', 'UTF-16LE//IGNORE', $excel_data ); // assume $excel_data contains UTF-8 encoded

header('Content-Type: application/vnd.ms-excel; charset=utf-8');
header('Content-Disposition: attachment; filename='. uniqid('') . '.xls');
header('Content-Length: ' . strlen($excel_data));

//add two characters at the beginning of a file to indicate that it's a UTF-8 document
echo chr(255).chr(254);

//display the data
echo $excel_data;

Link to comment
Share on other sites

If you remove the Content-Type: headers and just let the raw excel data get echoed, are there any error messages in there? Perhaps it's the execution time of the script? Disabling the header changes will let you see if there are any messages.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.