什么是docx,pptx等正确的MIMEtypes?

对于较老的* .doc文件,这足够了:

header("Content-Type: application/msword"); 

我应该为新的docx文件使用什么MIMEtypes? 也用于pptx和xlsx文件?

以下是HTTP内容stream的正确Microsoft Office MIMEtypes:

 Extension 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.template.macroEnabled.12 .ppsm application/vnd.ms-powerpoint.slideshow.macroEnabled.12 .mdb application/vnd.ms-access 

有关更多详细信息,请查阅此TechNet文章和此博客文章 。

或者,如果你使用.Net v4.5或更高版本,请尝试使用System.Web.MimeMapping.GetMimeMapping (yourFileName)来获取MIMEtypes – 比硬编码string好得多

加载.docx文件

  if let htmlFile = Bundle.main.path(forResource: "fileName", ofType: "docx") { let url = URL(fileURLWithPath: htmlFile) do{ let data = try Data(contentsOf: url) self.webView.load(data, mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", textEncodingName: "UTF-8", baseURL: url) }catch{ print("errrr") } }