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

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

Ext

 

MIME Type

 

.doc

 

application/msword

 

.dot

 

application/msword

 

.docx

 

application/vnd.openxmlformats-officedocument.wordprocessingml.document

 

.dotx

 

application/vnd.openxmlformats-officedocument.wordprocessingml.template

 

.docm

 

application/vnd.ms-word.document.macroEnabled.12

 

.dotm

 

application/vnd.ms-word.template.macroEnabled.12

 

.xls

 

application/vnd.ms-excel

 

.xlt

 

application/vnd.ms-excel

 

.xla

 

application/vnd.ms-excel

 

.xlsx

 

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

 

.xltx

 

application/vnd.openxmlformats-officedocument.spreadsheetml.template

 

.xlsm

 

application/vnd.ms-excel.sheet.macroEnabled.12

 

.xltm

 

application/vnd.ms-excel.template.macroEnabled.12

 

.xlam

 

application/vnd.ms-excel.addin.macroEnabled.12

 

.xlsb

 

application/vnd.ms-excel.sheet.binary.macroEnabled.12

 

.ppt

 

application/vnd.ms-powerpoint

 

.pot

 

application/vnd.ms-powerpoint

 

.pps

 

application/vnd.ms-powerpoint

 

.ppa

 

application/vnd.ms-powerpoint

 

.pptx

 

application/vnd.openxmlformats-officedocument.presentationml.presentation

 

.potx

 

application/vnd.openxmlformats-officedocument.presentationml.template

 

.ppsx

 

application/vnd.openxmlformats-officedocument.presentationml.slideshow

 

.ppam

 

application/vnd.ms-powerpoint.addin.macroEnabled.12

 

.pptm

 

application/vnd.ms-powerpoint.presentation.macroEnabled.12

 

.potm

 

application/vnd.ms-powerpoint.presentation.macroEnabled.12

 

.ppsm

 

application/vnd.ms-powerpoint.slideshow.macroEnabled.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/ASP.NET code, you should use the built-in Response.ContentType 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/ASP.NET代码中使用MIME type,你应该用ASP/ASP.NET的内置的Response的ContentType属性,并且设置这个属性为和你提供内容相符的MIME type。如果没有正确的设置,那么就会在下载后打开文档是报类似的警告出来。

一般来说导出excel时

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

如果是excel2007以后的,那么content-type应该设置为:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

参考网址:

https://blogs.msdn.microsoft.com/vsofficedeveloper/2008/03/11/excel-2007-extension-warning-on-opening-excel-workbook-from-a-web-site-2/

https://blogs.msdn.microsoft.com/vsofficedeveloper/2008/05/08/office-2007-file-format-mime-types-for-http-content-streaming-2/

Tags Office Core Pages

  • 8
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用Excel软件自带的导功能将Excel表格转换为CSV文件。具体步骤如下: 1. 打开Excel表格,选择要导的工作表。 2. 点击“文件”菜单,选择“另存为”选项。 3. 在“另存为”对话框中,选择“CSV(逗号分隔)(*.csv)”作为文件类型,并指定文件保存路径和文件名。 4. 点击“保存”按钮,确认导设置。 5. 如果提示信息,表示表格中某些内容不能转换为CSV格式,可以选择忽略或修改并重新导。 导完成后,即可得到一个以逗号分隔的CSV文件,可以用任何文本编辑器打开查看。 ### 回答2: 要将Excel表格转为CSV文件,可以按照以下步骤进行操作: 1. 打开Excel表格,选择你要转换的工作表。 2. 在Excel菜单栏中选择“文件”(File)选项,然后选择“另存为”(Save As)。 3. 在“另存为”对话框中,选择存储位置和文件名。在“文件类型”(Save as type)下拉菜单中,选择“CSV(逗号分隔符)(*.csv)”格式。 4. 点击“保存”(Save)按钮,Excel会弹一个警告对话框,询问是否要保存当前工作表或整个工作簿。根据需要选择相应选项,然后点击“是”(Yes)按钮。 5. 现在,你的Excel表格已经转换为CSV文件,并且可以在指定的存储位置找到它。 这样,你就成功地将Excel表格转为了CSV文件。CSV文件是一种逗号分隔的文本文件格式,适用于许多应用程序的数据导入和导。请注意,CSV文件不支持Excel的某些功能,如单元格合并、公式等。转换后的CSV文件中,每个Excel单元格的值将以逗号分隔,并且每个行都会成为CSV文件中的一行。 ### 回答3: 将Excel表格转为CSV文件非常简单。以下是具体的步骤: 1. 打开Excel表格,并确认要转换的工作表是活动的。 2. 点击文件选项卡,在菜单中选择“另存为”选项。 3. 在“另存为”对话框中,选择CSV(逗号分隔)的文件格式。 4. 点击“保存”按钮,选择要保存CSV文件的位置和文件名,并点击“确定”按钮。 5. Excel会显示一个警告对话框,说明CSV文件不支持Excel特有的功能。如果您确定转换后不需要这些功能,可以点击“是”继续转换。 6. 转换完成后,您将在指定位置找到保存的CSV文件。 请注意以下几点: - CSV文件是一种纯文本格式,不能包含Excel中的公式、图表、宏等。 - CSV文件中的每行代表Excel表格中的一行数据,每个单元格的数据以逗号分隔。 - 如果Excel表格中存在复杂的数据格式或特殊符号,转换后的CSV文件可能需要进行一些调整或手动编辑以确保数据正确。 希望以上步骤能帮到您,如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值