troubleshooting Question

Opening web-located text files in MS Excel

Avatar of Stefan Lennerbrant
Stefan LennerbrantFlag for Sweden asked on
Web DevelopmentMicrosoft ExcelWeb BrowsersPHP.NET Programming
9 Comments1 Solution106 ViewsLast Modified:
I generate text files in a web application, and I would like the client (mainly IE11 running on Windows 7 and 8) to open the files in Excel.

I serve the files as:
Content-Type: application/
Content-Disposition: filename="myfile.txt"
and the content of the files is something like:
abc <tab> def <tab> ghi
123 <tab> 456 <tab> <789>
I have also tried using filename="myfile.htm" with a html content: <table><tr><td>...several rows/cells...</td></tr></table>

I run into several problems with this.
The biggest one is that this only works on small files. As soon as the file is larger than "quite small", WIndows and/or the browser "re-classifies" the file and renames it to myfile.xls (obviously(?) due to the mime type used). And then the Excel extension hardening kicks in and will issue a warning to the user. Not good!

In Chrome, there is a completely different problem. The file will always be downloaded to disk and will "loose" the connection to its mime type. The filename (extension) is never changed, as happens with IE, but saved on disk is is "only a text file" and will open in Notepad or similar, and not in Excel.
In IE, I get the same problem (of course) if the user chooses to save the file on disk, instead of opening it. In addition, IE sometimes renames the file to myfile.xls - which adds to the confusion :-)

So, in short - what is best practice?
How do I generate web content in non-binary form (tab-separated fields, comma-separated fields, html, or other text formats) that a modern browsers will open in MS Excel?
(the same question actually relates to MS Word, as well)

Any ideas?


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros