设置 Excel 文档的 MIME 类型 [英] Setting mime type for excel document
问题描述
MS Excel 具有以下观察到的 MIME 类型:
MS Excel has the following observed MIME types:
application/vnd.ms-excel
(官方)application/msexcel
application/x-msexcel
application/x-ms-excel
application/x-excel
application/x-dos_ms_excel
application/xls
application/x-xls
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
(xlsx)
application/vnd.ms-excel
(official)application/msexcel
application/x-msexcel
application/x-ms-excel
application/x-excel
application/x-dos_ms_excel
application/xls
application/x-xls
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
(xlsx)
有没有一种类型适用于所有版本?如果不是,我们是否需要为这些 mime 类型中的每一种单独设置 response.setContentType()
?
Is there any one type that would work for all versions? If not, do we need to set response.setContentType()
with each one of these mime types individually?
此外,我们在应用程序中使用文件流来显示文档(不仅仅是 excel - 任何类型的文档).这样做时,如果用户选择保存文件,我们如何保留文件名 - 目前,呈现文件的 servlet 的名称显示为默认名称.
Also, we use file streaming in our application to display document (not just excel - any type of document). In doing so, how can we retain the filename if the user opts to save the file - currently, the name of the servlet that renders the file appears as the default name.
推荐答案
我相信标准 Excel 的 MIME 类型 文件是 application/vnd.ms-excel
.
I believe the standard MIME type for Excel files is application/vnd.ms-excel
.
关于文档的名称,您应该在响应中设置以下标题:
Regarding the name of the document, you should set the following header in the response:
header('Content-Disposition: attachment; filename="name_of_excel_file.xls"');
这篇关于设置 Excel 文档的 MIME 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!