Python 如何将 Xlsxwriter 文件保存在特定路径中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22904654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to save Xlsxwriter file in certain path?
提问by user3496563
Where does Xlsxwriter save the files you have created? Is it possibly to specify the path where I want the excel files to be saved?
Xlsxwriter 在哪里保存您创建的文件?是否可以指定我希望保存 excel 文件的路径?
My XlsxWriter script was in file /app/smth1/smth2/ and for some reason it saved the excel file to /app/. Shouldn't it have saved it in the same file where the script was? Or do I have to specify the path like this:
我的 XlsxWriter 脚本位于文件 /app/smth1/smth2/ 中,出于某种原因,它将 excel 文件保存到 /app/。它不应该将它保存在脚本所在的同一个文件中吗?或者我必须像这样指定路径:
workbook = xlsxwriter.Workbook(' /app/smth1/smth2/Expenses01.xlsx')
What is the default file where the excel file is saved?
保存excel文件的默认文件是什么?
采纳答案by Steve Byrne
The file it's self is saved to your local directory (where you run the file from) for example, I am using Python 2.7.6, and when I run this:
例如,它自己的文件保存到您的本地目录(您运行文件的位置),例如,我使用的是 Python 2.7.6,当我运行它时:
workbook = xlsxwriter.Workbook('demo.xlsx')
The file is saved in the same folder as my Python file, you can also specify a full path like so:
该文件与我的 Python 文件保存在同一文件夹中,您还可以指定完整路径,如下所示:
workbook = xlsxwriter.Workbook('C:/Users/Steven/Documents/demo.xlsx')
And this will save my demo.xlsx file in my documents folder (assuming you are on windows) Make sure all of your paths are correct (case sensitive, and none corrupted) and it should work, the final example that should be a copy and paste for you is:
这会将我的 demo.xlsx 文件保存在我的文档文件夹中(假设您在 Windows 上)确保您的所有路径都正确(区分大小写,并且没有损坏)并且它应该可以工作,最后一个示例应该是副本和为您粘贴的是:
workbook = xlsxwriter.Workbook('app/smth1/smth2/Expenses01.xlsx')
Notice the starting "/" is not needed and may be causing your errors (at least on Windows, I can't say for sure on Mac/Linux). Best of luck! Examples can be found here
请注意,不需要开头的“/”,并且可能会导致您的错误(至少在 Windows 上,我不能确定在 Mac/Linux 上)。祝你好运!例子可以在这里找到