@sinnebril
Thanks for responding. I managed to read columns by name and place them in seperate sheet as intented. Is there a way that i can write the data to a specific sheet of already existing exel file. I want to overwrite that sheet every time i run the script. Thanks
import xlrd
import xlwt
wb = xlrd.open_workbook('DiagnosticDataList_L494_BB90574_CSW03_Prerelease_Updated format.xls')
sh = wb.sheet_by_name(u'SystemReleaseTable expanded')
#print "Number of rows: %s Number of cols: %s" % (sh.nrows, sh.ncols)
wbook = xlwt.Workbook()
sheet = wbook.add_sheet('test')
wb.sheet_names()
rowx = 3
colx = 0
col = 1
row = 3
for count_col in range(0,sh.ncols):
row_cell = sh.cell(rowx,colx).value
read_name = row_cell
colx += 1
if read_name == 'Group Name':
found_col = count_col
sheet.write(row,col,read_name)
break
rowx = 4
colx = found_col
row = 4
for count_row in range(rowx,sh.nrows):
row_cell = sh.cell(rowx,colx).value
print_row = row_cell
rowx += 1
row += 1
sheet.write(row,col,print_row)
rowx = 3
colx = 0
col = 2
row = 3
for count_col in range(0,sh.ncols):
row_cell = sh.cell(rowx,colx).value
read_name = row_cell
colx += 1
if read_name == 'EBD':
found_col = count_col
sheet.write(row,col,read_name)
break
rowx = 4
colx = found_col
row = 4
for count_row in range(rowx,sh.nrows):
row_cell = sh.cell(rowx,colx).value
rowx += 1
row += 1
if row_cell == 'Off':
print_row = 1
else :
print_row = 0
sheet.write(row,col,print_row)
rowx = 3
colx = 0
col = 3
row = 3
for count_col in range(0,sh.ncols):
row_cell = sh.cell(rowx,colx).value
read_name = row_cell
colx += 1
if read_name == 'Abs':
found_col = count_col
sheet.write(row,col,read_name)
break
rowx = 4
colx = found_col
row = 4
for count_row in range(rowx,sh.nrows):
row_cell = sh.cell(rowx,colx).value
rowx += 1
row += 1
if row_cell == 'On':
print_row = 1
else :
print_row = 0
sheet.write(row,col,print_row)
rowx = 3
colx = 0
col = 4
row = 3
for count_col in range(0,sh.ncols):
row_cell = sh.cell(rowx,colx).value
read_name = row_cell
colx += 1
if read_name == 'VDC_Controller':
found_col = count_col
sheet.write(row,col,read_name)
break
rowx = 4
colx = found_col
row = 4
for count_row in range(rowx,sh.nrows):
row_cell = sh.cell(rowx,colx).value
rowx += 1
row += 1
if row_cell == 'On':
print_row = 0
elif row_cell == 'Off' :
print_row = 1
else:
print_row = 0
sheet.write(row,col,print_row)
rowx = 3
colx = 0
col = 5
row = 3
for count_col in range(0,sh.ncols):
row_cell = sh.cell(rowx,colx).value
read_name = row_cell
colx += 1
if read_name == 'HDC':
found_col = count_col
sheet.write(row,col,read_name)
break
rowx = 4
colx = found_col
row = 4
for count_row in range(rowx,sh.nrows):
row_cell = sh.cell(rowx,colx).value
rowx += 1
row += 1
if row_cell == 'On':
print_row = 0
elif row_cell == 'Off' :
print_row = 1
elif row_cell == 'RampOff' :
print_row = 1
else:
print_row = 0
sheet.write(row,col,print_row)
rowx = 3
colx = 0
col = 6
row = 3
for count_col in range(0,sh.ncols):
row_cell = sh.cell(rowx,colx).value
read_name = row_cell
colx += 1
if read_name == 'HBA':
found_col = count_col
sheet.write(row,col,read_name)
break
rowx = 4
colx = found_col
row = 4
for count_row in range(rowx,sh.nrows):
row_cell = sh.cell(rowx,colx).value
rowx += 1
row += 1
if row_cell == 'On':
print_row = 0
elif row_cell == 'Off' :
print_row = 1
elif row_cell == 'RampOff' :
print_row = 1
else:
print_row = 0
sheet.write(row,col,print_row)
rowx = 3
colx = 0
col = 7
row = 3
for count_col in range(0,sh.ncols):
row_cell = sh.cell(rowx,colx).value
read_name = row_cell
colx += 1
if read_name == 'RSC':
found_col = count_col
sheet.write(row,col,read_name)
break
rowx = 4
colx = found_col
row = 4
for count_row in range(rowx,sh.nrows):
row_cell = sh.cell(rowx,colx).value
rowx += 1
row += 1
if row_cell == 'On':
print_row = 0
elif row_cell == 'Off' :
print_row = 1
elif row_cell == 'RampOff' :
print_row = 1
else:
print_row = 0
sheet.write(row,col,print_row)
wbook.save('reformatted.data.xls')