2

I'm trying to convert a config file into an Excel file using xlwt. Getting an error because of duplicate worksheets. The config file is massive, I want to merge the duplicate worksheets . Is there a way to go around it?

Thanks

osrrev
  • 51
  • 1
  • 5

1 Answers1

2

Below some idea for check duplicate sheets:

import xlwt

wb = xlwt.Workbook()
#Adding 2 sheets
ws1 = wb.add_sheet('One')
ws2 = wb.add_sheet('Two')

sheets = wb._Workbook__worksheets #Getting sheets list
sheet_names = [] #List for shhets names
for sheet in sheets:
     sheet_names.append(
         sheet.get_name() #getting sheet name
         ) 
print sheet_names
print True if u"One" in sheet_names else False #check for our name
wb.save('test.xls')

Results:

$python simple.py 
[u'One', u'Two']
True
Michael Kazarian
  • 4,376
  • 1
  • 21
  • 25