简体   繁体   English

如何使用openpyxl创建一个新的xlsx文件?

[英]how to create a new xlsx file using openpyxl?

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?我需要添加什么?

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.这将创建一个新文件。

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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 openpyxl 从字典创建 Excel 文件扩展名 .xlsx? - How to create an Excel file extension .xlsx from a dictionary using openpyxl? 如何使用openpyxl读取xlsx流文件 - how to read a xlsx stream file using openpyxl 列出并使用python和openpyxl将数据写入新的xlsx文件 - Take a list and write the data to a new xlsx file using python and openpyxl 如何使用 Openpyxl 更新现有的 Excel.xlsx 文件? - How to update existing Excel .xlsx file using Openpyxl? openpyxl,保存/使用后如何关闭/shutdown.xlsx 文件/会话? - openpyxl, how to close/shutdown .xlsx file/session after saving/using it? 如何使用 openpyxl 在 XLSX 文件中逐个单元格地插入和格式化值 - How to insert and format values cell by cell in an XLSX file using openpyxl 如何使用openpyxl从python中的xlsx文件中读取货币符号? - How to read a currency symbol from an xlsx file in python using openpyxl? 使用 OpenPyXL 将 XLSX 文件保存到指定位置 - Save XLSX file to a specified location using OpenPyXL 在python中使用openpyxl模块编写xlsx文件 - write xlsx file using openpyxl module in python 数据丢失,使用熊猫在具有多个工作表的.xlsx文件中更改格式,同时在现有的.xlsx文件中添加新工作表时使用openpyxl - Data missing, format changed in .xlsx file having multiple sheets using pandas, openpyxl while adding new sheet in existing .xlsx file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM