How to clear a range of values in an Excel workbook using OpenPyXl

后端 未结 4 1979
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 18:14

I have a workbook that I would like to clear a range of values with using OpenPyXI. So far I have the following:

# Import OpenPyXl module.
from openpyxl impo         


        
4条回答
  •  攒了一身酷
    2021-01-01 19:14

    import openpyxl
    
    book = openpyxl.load_workbook('sample.xlsx') #get the file name
    sheet = book.get_sheet_by_name('Sheet') #get the sheet name
    
    for a in sheet['A1':'A2']: #you can set the range here 
        for cell in a:
            cell.value = None #set a value or null here
    book.save('sample.xlsx') #you can save it after if you like
    

提交回复
热议问题