html to excel problem! - excel

I am printing excel like this:
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".str_replace(' ', '_', $title).".xls");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
The content is plain html. The problem, when I download this, I get an initial confirmation box written
The file you are trying to open 'File_name.xls', is in a different format than specified by the file extension. Verified that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
When I do 'yes', I get this. Bit strange, any input here friends please ?

Well, that is pretty strange. I doubt this will help, but try renaming it to .xlsx. It might just be that it's not getting the proper (newer) file extension.

I always use content type = "application/ms-excel"

I have an application that does the same thing; it sets ContentType = "application/vnd.xls" and it works correctly (you still get the warning about that it's in the wrong format, but it opens after that).
I suspect the problem is not the content type, but the actual html content you are sending. Can you post an example of the file you are sending that causes the error?

Well, this one suddenly got solved, I don't know how.
This is what I did. I copied and pasted codes of a different page where the excel thing was working. Then, I changed the variables manually to adapt this with the 2nd page.
After some hit and try, it suddenly worked.
Thanks for all the answers anyway.
PS. By solved, I mean that excel is not crushing anymore, though I am still getting the confirm box about incorrect format.

Related

Amazon sitemap data in xml.gz form uncompressable

this might be a very dumb question but.. I'm trying to get the amazon sitemap and I have looked at amazon.com/robots.txt. They have a few .xml.gz files for their sitemap which I have downloaded. The problem that I'm having is that I cannot unzip them. I feel like I'm missing something very obvious.
For example, one sitemap is: http://www.amazon.com/sitemaps.f3053414d236e84.SitemapIndex_0.xml.gz
Thanks!
This is happening because Content-Type is set to binary/octet-stream in the response. If you override Content-Type response header to text/xml,
browser will automatically decompress the file.
I just renamed the *.xml.gz to *.xml and open it in a text editor and just worked.
I don't know if it was a problem with the browser or the file is corrrupted.

Forcing IE to download NOT open files

We have a simple html page with a list of links on a Tomcat server. Many of the links are just a simple .msg file for users to download, fill-in and send. Works great in Chrome but not in IE. IE tries to load the .msg file and all you see is 'garbally gook'.
I've tried searching for answers but none have worked so far.
Tried:
- Adding 'download' to the tag but of course this isn't supported in IE.
- Tried adding a .htaccess file with: AddType application/octet-stream .msg, but this didn't work either.
Tomcat is by Apache so I'm really surprised the .htaccess file answer didn't work. Some answers suggested using PHP or adjusting config files, but this is a little over my head. Who would have thought such a seemingly simple question would be so technical to fix!
Many thanks for any direction you are able to suggest!
I finally found my answer so for the next none techy, hopefully this will help you too!
For Apache Tomcat, find your web.xml and open in Note Pad. Search for MIME, you want to keep going until you find your MIME types, they will look like the below code. They are sorted alphabetically so place your new MIME type accordingly. For me it was a .msg file that I wanted IE to prompt an open/save as, rather than just trying to opening it.
<mime-mapping>
<extension>msg</extension>
<mime-type>application/vnd.ms-outlook</mime-type>
</mime-mapping>
To find the appropriate MIME type, I just did a Google search for 'Outlook .msg MIME Type' and found it pretty quickly. After you have added your new MIME Type save and restart your server.
Issue: web.xml wouldn't let us save over it. We got around this by saving our new file with a different name, rename/delete the existing web.xml file and then renaming the updated file back to web.xml.
Issue: After restarting the server, IE STILL tried to read the .msg file rather than opening it, even after refreshing cache, grrrr! Trying another link we hadn't tried before, revealed the new MIME Type to be working and testing on another computer confirmed it.
Good luck!

How to import a segment of html into Excel

Requirement:
1.I need to export a table as a excel file.
2.I render it in a html page at first. I have a button to export to html.
My opinion:
1.I get the html from page:
document.getElementById('content').value = document.getElementById('containerId').innerHTML;
form1.submit();
2.I get it from server, response.ContentType = "application/vnd.ms-excel;" // it need the client has installed Microsoft Excel.
3.I got the right Excel file "XXXX.xls".
4.BUT BUT BUT, when I open it, it's alert a waring tell me like
"it's not the right format of Excel, are you confirm to open it?"
I'm feel sorry to see it.
So I want to import the HTML section into a Excel file, then response the right Excel file to USER-AGENT.
I have use the Aspose.Cells library in my project, I don't know how to use it to finish the task, Or is any other solution to solve it ?
If you need to parse html tags/portion to Excel spreadsheet using Aspose.Cells for .NET, you may use Cell.HtmlString attribute to set your desired html code segment in a cell, it will be parsed accordingly in the generated Excel file. Mind you, not all the html tags are supported at the moment.
Aspose.Cells for .NET also supports to convert an Excel file to Html file directly, see the documents on which file formats are supported for conversion, it may help you for your reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/opening-files.html
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/saving-files.html
If you still have some issue/confusion, kindly give us details with your sample code using Aspose.Cells API, we can help you.

How to determine real format of an XLSX Excel file?

I have a well known problem that is described in Extension Warning On Opening Excel Workbook from a Web Site microsoft blog entry. I've added URL rewrite to have URL nicely formatted and my mime type matches exactly XLSX recommended file type. However I still get a warning. I suspect that service that provides me those xlsx files mismatches real file format and extension.
Is there a way to determine real xlsx file format? Something that would say what is the native extension for particular Excel file.
Thanks in advance.
Have you tried changing the mime header from vnd:excel to octet-stream? This will still bring Excel up, albeit not embedded into IE, which vnd:excel does (but I hate vnd:excel anyways because embedding the spreadsheet into the browser screws up the form flow of my web apps).
Did not find an answer for that anyway.
However I've discovered the reason why I get a warning from Excel - any parameter in query string will trigger such a warning, even for static files:
http://localhost/1.xls
works ok
http://localhost/1.xls?testparam=paramvalue
gives a warning.
Will use URL rewrite to encode parameters.

How can I stop Excel 2003 from hanging after opening a spreadsheet in IE?

I have a web application which provides Excel files via IE 7. It requests the files with an HTTP GET from a URL which returns the data with a content type of 'application/vnd.ms-excel'. It then opens the spreadsheets in an IFrame.
This all works fine unless Excel is already open when a spreadsheet is downloaded. In this case it is still displayed correctly but reuses the instance of Excel which is open. When the IFrame is closed, Excel hangs. Excel only becomes unlocked if the user logs out of the web application or if they download a file of a different type.
I've tried turning on the 'Ignore other applications' setting under Tools | Options | General but it didn't solve the problem.
I've also tried following the steps in this answer (as the linked reference says 'This issue has been addressed in Excel 2007 beta 2.') with no luck.
Is there some kind of 'disposal' step which I'm not currently doing which would prevent Excel from hanging?
Versions:
Excel 2003 (11.8220.8221) SP3
IE 7.0.5730.11 (Update Versions: 0)
Not sure if this helps but ...
I had some similar problem (generating CSV content on the fly) long time ago and all I can remember is that it had to do something with right Response methods being called. The code was something like this
Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment; filename=export.csv");
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Cache.SetExpires(DateTime.MinValue);
Response.Cache.SetLastModified(DateTime.Now);
Response.Cache.SetMaxAge(new TimeSpan(1));
Response.ContentType = "text/csv";
Response.ContentEncoding = System.Text.Encoding.Unicode;
...
//Some writing to the Response.OutputStream
...
Response.Flush();
//I am not sure about the following line:
Response.End();
Further to Robert's answer, the following line of (Java) code fixes this problem, in that it prevents Excel from hanging:
response.setHeader("Content-Disposition",
"attachment; filename=\"" + filename + "\"");
[NB 'response' is an HttpServletResponse]
However, it forces the spreadsheet to be loaded into an Excel window rather than being displayed in the IFrame...
Update: Resetting the URL of the IFrame to blank forces the Excel instance to be disposed and fixes this problem (without requiring the Content-Disposition change).
Unfortunately, this is completely out of your hands. It really depends on what version of excel they have and what updates have been applied.
Have you been able to reproduce this issue in your own environment? If not, it may be an issue on the client's computer. Is there any way you can find out what options were or werent installed, or if Excel has been maintained with it's patches?
It seems to me that office itself needs to be re-installed, if not IE 7 after that.
I would also look into any iFrame closing issues. To test this theory out, you could post the iframe to a new page (without iframes) and then link back to a page with iframes and the excel file? I realize that probably wont' be a working solution for you, but it should help you eliminate whether it's excel, IE7 or the iframe code having a bug.
Is this something you're able to reproduce, or is it something being reported to you by a customer, and you're trying to hunt it down?
The link you've provided deals with multiple monitors - I have multiple monitors as well when I dock my laptop, and I've found a number of applications don't respond well. For example, if an application attempts to open a modal dialog box in a desktop space that doesn't exist anymore (for example, on my "second monitor" after I'veundocked my laptop), it will lock up the application since I can't get to the box. Could that be what's happening here?
Another potential problem happens if you're asking the user for some kind of authentication when they get the Excel file. On our sharepoint site, Excel wants the user to authenticate, and if that modal authentication dialog somehow gets pushed into the background, it can be impossible to get to the front again. The only way is if you kill the process or if you close the sharepoint browser, since that terminates the request for the file in the first place.
Hope this helps, and if either of these give you some more clues, post them here and we'll get this solved.

Resources