下载excel打开后弹出警告提示,文件类型和文件内容不符问题处理

时间:2024-11-10 11:17:15

在网页下载excel时,一定要正确设置response头中的content-type;即设置正确的mime type,具体设置如下:

Ext

 

MIME Type

 

.doc

 

application/msword

 

.dot

 

application/msword

 

.docx

 

application/

 

.dotx

 

application/

 

.docm

 

application/.12

 

.dotm

 

application/.12

 

.xls

 

application/-excel

 

.xlt

 

application/-excel

 

.xla

 

application/-excel

 

.xlsx

 

application/

 

.xltx

 

application/

 

.xlsm

 

application/.12

 

.xltm

 

application/.12

 

.xlam

 

application/.12

 

.xlsb

 

application/.12

 

.ppt

 

application/-powerpoint

 

.pot

 

application/-powerpoint

 

.pps

 

application/-powerpoint

 

.ppa

 

application/-powerpoint

 

.pptx

 

application/

 

.potx

 

application/

 

.ppsx

 

application/

 

.ppam

 

application/.12

 

.pptm

 

application/.12

 

.potm

 

application/.12

 

.ppsm

 

application/.12

 

 

To fully support the new types, web server administrators are advised to add the MIME types for the Open XML formats to their web server metabase settings so as to add the correct MIME type header in documents saved directly on the server and sent back.  For Windows 2003 Servers running IIS 6.0, you can add the Open XML types in IIS Manager, Server Properties, MIME Types.  These new formats are included in Windows 2008 running IIS 7.0 by default.  For more details on the default MIME types for IIS, please see the following KB article:

 

 

936496: Description of the default settings for the MimeMap property and for the ScriptMaps property in IIS

 

Clients that install Office 2007 or the Office 2007 File Format Compatibility Pack will get client-side MIME mappings to these formats by default.  

 

To use the MIME type in your ASP/ code, you should use the built-in property and set it to the MIME value that matches the content type you are providing.  If you fail to set the correct type, security checks by the client may prevent the content from being opened or may prompt the user with an alert that the file is not in the correct format.

为了在ASP/代码中使用MIME type,你应该用ASP/的内置的Response的ContentType属性,并且设置这个属性为和你提供内容相符的MIME type。如果没有正确的设置,那么就会在下载后打开文档是报类似的警告出来。

一般来说导出excel时

如果是excel97~2003,那么content-type应该设置为:application/-excel,

如果是excel2007以后的,那么content-type应该设置为:application/

参考网址:

/vsofficedeveloper/2008/03/11/excel-2007-extension-warning-on-opening-excel-workbook-from-a-web-site-2/

/vsofficedeveloper/2008/05/08/office-2007-file-format-mime-types-for-http-content-streaming-2/

Tags Office Core Pages