views:

3439

answers:

6

I have a web page which links to an excel 2007 worksheet. It is a .xls file and not .xlsx file. When I click on the link I get the usual dialog box to either open/save the excel file. On clicking 'Open', I get the following warning message-

The file you are trying to open, 'filename.xls' is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

Can I some how suppress this warning message programmatically (i.e. to hide it or prevent it from showing up?) I'm using Coldfusion for web development.

A: 

I don't believe you can hide it from the user. Those kinds of warnings are external to your browser.

fmsf
+2  A: 

If you don’t want to look for a solution, but just want to solve the problem, insert this key in your registry to suppress the notification:

[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security] “ExtensionHardening”=dword:00000000

You can accomplish the above by doing the following:

  1. Open your Registry (Start -> Run -> regedit.exe)
  2. Navigate to HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
  3. Right click in the right window and choose New -> DWORD
  4. Type “ExtensionHardening” as the name (without the quotes)
  5. Verify that the data has the value “0″
Jon
Thanks Jon. Can I do this programmatically, say using coldfusion?
Andriyev
My workaround is for a single local machine. A webapp will not be able to edit the registry, as far as I am aware.
Jon
+2  A: 

This problem results from a feature called Extension Hardening, and you can find more information about it here

I've run into this problem a lot in my projects, and like Jon said, turning off Extension Hardening is something that will have to be done by each client side user.

Unfortunately, the link above also states that there are no expected changes to this code until at least Office 14.

Matthew Jones
I think that only applies if you're using CSV and save as XLS. However, if you construct a real excel file, then it should be fine.CF9 cfspreadsheet will be your friend. :)
Henry
A: 

The message suggests that the file contents and the file extension don't match. So either it's an XLSX file or the current file on the server is broken in some way. I suggest to try to open the file with a ZIP tool. If that works, it's really an XLSX-format file. Then you can fix the warning by renaming the file.

If that's not the case, something happened to the file.

But either way, suppressing the warning is not a solution to your problem. The next time a virus comes along and asks your customers to open nakedgrls.gif.exe, you better didn't mess with the security settings.

Aaron Digulla
A: 

If you're using the handy cfcontent trick to output as an excel file, consider using cfx_query2excel, it will write real excel files that should get you past this. It's a Java library and was worth it.

Best of luck.

Jas Panesar
A: 

If you are not specifying the file extension, it is probably getting named as a .cfm file with the content type as "application/vnd-excel" which causes this warning.

Try adding this before the file output begins:

<cfheader name="Content-Disposition" value="attachment;filename=myexcelfile.xls">
<cfcontent type="application/ms-excel" reset="true">
eapen