SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    cross platform problem with exporting a spreadsheet

    Hi,
    I recently ported a database app to a new server and the client is reporting an error with the tool that outputs a spreadsheet of data. I have tested it cross-platform and can't duplicate the problem.

    This is the error they are getting:
    Internet Explorer cannot download xxx.php from xxx.org.
    Internet Explorer was not able to open this site. The request is either unavailable or could not be found. Please try again later.
    From the screen shot they sent, it looks like they are using ie7 on XP.

    Does anybody have any ideas?

    Michael

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are known problems when exporting excel under https when using IE, which gives this error. You don't say whether or not you're using https, but setting headers to the following works for me with both http and https:
    PHP Code:
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header ('Pragma: public'); // HTTP/1.0
    header ('Content-Type: '.$cType);
    header ('Content-Disposition: attachment; filename="excelDownload.'.$fileExtension.'"');
    header ('Content-Transfer-Encoding: binary');
    header ('Content-Length: '.$fileSize); 
    where:
    $cType is the MIME type for the download ('application/vnd.ms-excel' for Biff5/8 files and 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' for Excel 2007)
    $fileExtension is the file extension ('xls' or 'xlsx')
    $fileSize is the sizze of the download file

    I then simply stream the raw data via readfile ($fileName);
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  3. #3
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks I'll try the header you suggest.
    It is https.

  4. #4
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well it seems like this had some good effect.
    The client reported she was able to download a report, but it returned an empty spreadsheet. I set the extension to xls so it will open in Excel, but really it is a tab delimited file. Does that make a difference?

    Michael

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by eruna View Post
    I set the extension to xls so it will open in Excel, but really it is a tab delimited file. Does that make a difference?
    Well it's really simply trying to con Excel.

    I can't confirm for Excel 2003 or earlier at the moment; but Excel 2007 recognises it as a "con" yet still allows you the option of opening the file anyway, and will successfully set each cell based on the tab separator. If the resulting file is genuinely empty (you can check by opening it in notepad or a similar text editor), then the problem is more likely to be in the code that you use to generate the file.

    A more common "trick" is to use a comma-separated value file (rather than tab-separated), with an extension of .csv and the appropriate MIME type for the download.A default installation of Excel, will set itself as the standard program to open .csv files, and won't consider this a "con".

    Personally, I'd create a genuine Excel file, which allows me to format the cells and use Excel formulae, as well as populating the data.
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  6. #6
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There's not an issue with reading the file. Its just an issue with downloading it.

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by eruna View Post
    There's not an issue with reading the file. Its just an issue with downloading it.
    Well the download shouldn't give an empty file unless it was empty to start with.

    Have you tried getting your client to open it in a text editor to confirm that it is actually empty? Have you tried checking the file on the server before its downloaded?
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  8. #8
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK I checked and it was actually empty.

    I noticed that it used default to open in in Excel, but now its defaulting to open in notepad.
    This problem is also not occurring in Vista. Only XP.

    My guess is that there was some kind of security patch that is checking the file type and identifying it is a fake file or maybe its because the server or connection is different?

    Maybe I should try playing around with the file tpe and extension. Any thoughts..

    Thanks a ton for your help so far.

  9. #9
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by eruna View Post
    I noticed that it used default to open in in Excel, but now its defaulting to open in notepad.
    This problem is also not occurring in Vista. Only XP.
    The default program to open any given filetype (based on extension) can easily be reset within windows explorer: right click on the file and "open with", and quite easy to misset the selected program as the new default.

    Have you checked the file that's produced on the server before it's downloaded? Just to confirm that it isn't empty as well?

    Quote Originally Posted by eruna View Post
    My guess is that there was some kind of security patch that is checking the file type and identifying it is a fake file
    Unlikely, to be honest, Windows has always been pretty blasť when it comes to accurately determining filetypes, and prefers to base it purely on extension... I can't see them getting out of that habit and suddenly making Windows a lot more secure without some kind of fanfare

    Quote Originally Posted by eruna View Post
    Maybe I should try playing around with the file tpe and extension. Any thoughts..
    Try using Comma-separated instead of Tab-separated, with the correct .csv extension, and appropriate mime type "text/csv". It should also open automatically in Excel.
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •