I want to convert all the excel document(.xls) sheets into csv, If excel document has one sheet only then I am converting like as follow-
wb = open_workbook(path1)
sh = wb.sheet_by_name('Sheet1')
csv_file = open(path2, 'w')
wr = csv.writer(csv_file, quoting=csv.QUOTE_ALL)
for rownum in range(sh.nrows):
wr.writerow(sh.row_values(rownum))
csv_file.close()
If my excel(.xls) document have more than one sheet i.e.('Sheet1', 'Sheet2', 'Sheet3', 'Sheet4') than how to convert all sheets into csv.
Any help would be appreciated.
Advertisement
Answer
wb.sheet_names() to get all the sheet names, and then loop it and dynamically put the name in the sheet_name