如何保存 XLSX 文件? [英] How to save XLSX file?

查看:102
本文介绍了如何保存 XLSX 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了:

setPreference("browser.helperApps.neverAsk.saveToDisk","application/xls;text/csv");  

.

setPreference("browser.helperApps.alwaysAsk.force", false);  

.

profile.set_preference("browser.helperApps.neverAsk.saveToDisk",application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")  

但 Firefox 总是询问我是否要打开文件.它适用于 XLS 文件.

but Firefox always asks if I want to open the file. It works fine for XLS file.

有什么想法吗?

推荐答案

我遇到了类似的问题.

这是我的工作浏览器配置文件配置行.

Here's my working browser profile config lines.

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.helperApps.alwaysAsk.force", False);
profile.set_preference("browser.download.dir", 'Desktop')
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

driver = webdriver.Firefox(firefox_profile=profile)

在我的设置中,浏览器通常会在页面加载时提示用户保存或下载.使用此设置,它只会自动下载.要记住的一件事是您如何创建电子表格.在我的例子中,PHPExcel_IOFactory 库使用这些行将其创建为 openxmlformats-officedocument.spreadsheetml.sheet.

In my setup the browser would normally prompt he user to save or download upon page load. With this setup it just automatically downloads. One thing to keep in mind is how you're creating the spreadsheet. In my case the PHPExcel_IOFactory library is creating it as openxmlformats-officedocument.spreadsheetml.sheet with these lines.

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

PHPExcel_IOFactory::createWriter($new_excel_object, 'Excel2007');

因此,您尝试下载的文件类型可能与预期类型不匹配.

So it's possible the file type you're trying to download doesn't match it's expected type.

这篇关于如何保存 XLSX 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆