Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2010: Different format than specified by the file extension.

Status
Not open for further replies.

jambai

Programmer
Mar 21, 2007
58
US
After upgrading to Excel 2010, I am getting the following error when try to open an existing
excel document or generating an excel from a web page (.asp page)

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

This errors particularly occurs when I am trying to open an XLS file (Excel 2000-2003) with Excel 2010.

Is there any alternative way to fix this problem other than changing the registry ([HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Security]
“ExtensionHardening”=dword:00000000)
or using thrid party tools.

Thanks
Jambai
 
As far as I know, this is a warning message and not an error message. If you click Yes to this warning message, file will be opened.

I read a Microsoft article on this issue. This article applies to Excel 2007 but it seems relevant for Excel 2010 too.


The warning message is a user-notification function that was added to Excel 2007. The warning message can help prevent unexpected problems that might occur because of possible incompatibility between the actual content of the file and the file name extension.

The user-notification function can be set to open the file, and not to display the warning message by using a Group Policy setting or by using Registry Editor.

You have already experimented using Registry Editor. You can also try the alternative way of using a Group Policy setting for which steps are mentioned in the article.
 
Hi Aziz,

I too came across the Group policy. But my client doesn't want to do the work around. The want this issue to be fixed on the asp page it self.

Thanks
 
I have Excel 2007 installed.

If I open Excel spreadsheet in a browser using response.ContentType, then I am getting this warning message regardless of file extension (xls or xlsx).
Code:
<%response.ContentType="application/vnd.ms-excel"%>
<html>
<body>
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
</table>
</body>
</html>

If I open an existing excel document using Response.Redirect, I do not get this warning message, be it xls file or xlsx file:
Code:
dim url,strfile

url="/[i]applicationname[/i]/excelreports/"
strfile = "test1.xlsx"
Response.Redirect(url & strfile)
This opens test1.xlsx without warning message

Code:
dim url,strfile

url="/[i]applicationname[/i]/excelreports/"
strfile = "test2.xls"
Response.Redirect(url & strfile)
This opens test2.xls without warning message


 
Aziz,

My question is how to hide the warning message, when you generate the spreadsheet from a web. Response.Redirect to .xls or .xlsx works one.

Thanks
Jambai
 

Quote from the above link:
ASP pages that return HTML and set the MIME type to something like XLS to try to force the HTML to open in Excel instead of the web browser (as expected) will always get the security alert since the content does not match the MIME type. If you use an HTML MIME type, then the web browser will open the content instead of Excel. So there is no good workaround for this case because of the lack of a special MIME type for HTML/MHTML that is Excel specific. You can add your own MIME type if you control both the web server and the client desktops that need access to it, but otherwise the best option is to use a different file format or alert your users of the warning and tell them to select Yes to the dialog.

So, you can use another file format, for example csv to hide the warning message. But in csv format, html tags will not work and you will have to use character codes to format data:

The following code opens MyBook.csv in Excel 2007 without warning message:
Code:
<%response.ContentType="application/vnd.ms-excel"
  Response.AddHeader "Content-Disposition", "Attachment;Filename=MyBook.csv" 
  Response.Write "1"
  Response.Write chr(44)
  Response.Write "2"
  Response.Write chr(44)
  Response.Write "3"
  Response.Write chr(13)
  Response.Write "4"
  Response.Write chr(44)
  Response.Write "5"
  Response.Write chr(44)
  Response.Write "6"
  Response.Write chr(13)  
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top