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-
JavaScript
x
8
1
wb = open_workbook(path1)
2
sh = wb.sheet_by_name('Sheet1')
3
csv_file = open(path2, 'w')
4
wr = csv.writer(csv_file, quoting=csv.QUOTE_ALL)
5
for rownum in range(sh.nrows):
6
wr.writerow(sh.row_values(rownum))
7
csv_file.close()
8
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