Search code examples
pythonexcelpython-3.xspreadsheetxlwings

How to add new sheet if it's not exist in python using xlwings


Using xlwings in python, I want to add new sheet in existing workbook. If sheet already present in the same name, It should return the sheet dataframe.


Solution

  • import xlwings as xw
    
    wb = xw.Book('file_path')
    try:
        wb.sheets.add('sheetname')
    except ValueError as V:
        print("Error:", V)