Search code examples
pythonpython-3.xxlsxwriterworksheet-functionworksheet

Creating multiple sheets with input function in xlsxwriter python


I want to create multiple sheets using the input function. I used the split function, but still it only creates one sheet. The idea is not to be restricted by the number of sheets.

import xlsxwriter
from xlsxwriter import workbook

workbook = xlsxwriter.Workbook('doc.xlsx')

sheetnames = input("Enter value: ").split(', ')

sheetss = []
for i in sheetnames:
  sheetss.append(i)
worksheet_data = workbook.add_worksheet(i)

workbook.close()

Any ideas?


Solution

  • Try:

    import xlsxwriter
    workbook = xlsxwriter.Workbook("test.xlsx")
    sheetnames = input("Enter value: ").split(", ")
    for i in sheetnames:
        workbook.add_worksheet(i)
    workbook.close()
    

    Using split() already creates a list so you don't need another variable to hold the sheetnames.