Python 如何使用openpyxl创建一个新的xlsx文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31893057/
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 create a new xlsx file using openpyxl?
提问by Newboy11
Does anybody knows how to create a new xlsx file using openpyxl in python?
有人知道如何在 python 中使用 openpyxl 创建一个新的 xlsx 文件吗?
filepath = "/home/ubun/Desktop/stocksinfo/yyy.xlsx"
wb = openpyxl.load_workbook(filepath)
ws = wb.get_active_sheet()
What do I need to add?
我需要添加什么?
回答by Charlie Clark
This is covered in the documentation: https://openpyxl.readthedocs.io/en/stable/tutorial.html#saving-to-a-file
这在文档中有介绍:https: //openpyxl.readthedocs.io/en/stable/tutorial.html#saving-to-a-file
wb.save(…)
wb.save(…)
回答by Newboy11
I'm sorry my head is turning around. :) This solves the problem
对不起,我的头在转。:) 这解决了问题
filepath = "/home/ubun/Desktop/stocksinfo/test101.xlsx"
wb = openpyxl.Workbook()
wb.save(filepath)
This will create a new file.
这将创建一个新文件。
回答by arpit patel
Install and Import openpyxl
安装和导入 openpyxl
import openpyxl
Create new workbook
创建新工作簿
wb = openpyxl.Workbook()
Get SHEET name
获取工作表名称
Sheet_name = wb.sheetnames
Save created workbook at same path where .py file exist
将创建的工作簿保存在 .py 文件所在的同一路径
wb.save(filename='Test.xlsx')