Issues opening a downloaded excel file on an android tablet

I'm working on an application that generates an excel file with data from the system. The excel file generates and downloads fine on a desktop but when I try and download it on my android tablet it won't open. It downloads fine but when opening it, a message tells me it's not a valid MS Excel file.

The document it's trying to download is being generated from a php script with these headers at the top of the page:

header('Pragma: public');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Pragma: no-cache');
header('Expires: 0');
header('Content-Transfer-Encoding: none');
header('Content-Type: application/vnd.ms-excel;');
header('Content-type: application/x-msexcel');
header('Content-Disposition: attachment; filename="Report.xls"');

// code below

I've tried many different variations of headers but nothing works. The download starts by clicking an icon that runs:

top.document.location = 'script_that_generates_excel_file.php';

I should add that the size of the file is coming across correctly on the tablet so the data should be there. Any ideas as to what's going on? Why can't I open the file on a tablet?

Errors I get when trying to open the file on the tablet:

Polaris Office:

An error occurred while opening the document

Sheet To Go:

This file cannot be opened because it is not a valid MS Excel 97 - 2011 file


created an excel spreadsheet on my desktop and copied it to the tablet and it opened fine on the tablet! That's good news. I also took a file that I generated on my tablet that didn't open and copied it to my desktop and it opened fine. It has to be the generation process obviously. Any ideas?

HTML code technically isn't valid XLS - it's just that Excel is kind enough to overlook the slight, and imports the data as if you had instructed it to import a HTML file. I guess the other non-Microsoft viewers aren't as lenient, and insist on the file being actual XLS (or XSLX or whatever the new format is named).

If that's true, you may have to generate real, actual XLS, using a tool like PHPExcel, it you want your documents to work on the tablet.

链接地址: http://www.djcxy.com/p/46874.html

上一篇: 在浏览器中以PDF形式获取响应

下一篇: 在Android平板电脑上打开下载的Excel文件的问题