简体   繁体   中英

how to create a new xlsx file using openpyxl?

Does anybody knows how to create a new xlsx file using openpyxl in python?

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

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

wb.save(filename='Test.xlsx')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM