我对Phython非常陌生,我必须创建一个脚本。我想通过Phython阅读Excel工作表,然后以自定义格式输出单元格值。
我输入的Excel是:
B Server1 NESLDS1 Local T Remote F Mltstdby F Group 60 Grpdef 60 Pad
B Server2 NESLDS2 Local T Remote F Mltstdby F Group 60 Grpdef 60 Pad
我的问题:
我正在运行一个Phython代码以获取每一行中参数的值,如果它是字符串或整数,我希望该值用引号(""
)引起来。现在,如果该值为布尔值,即T
或F
,那么我希望该值不带引号。
我的代码:
import xlrd
loc = ("C:\parameter.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
for k in range(2,sheet.nrows):
if sheet.cell_value(k,0)=="B":
print ('\n')
for i in range (2,14,2):
print('"%s"' % sheet.cell_value(k,i),",",end='',sep='')
我当前的输出是:
"NESLDS2","T","F","F","60","60",
"NESLDS2","T","F","F","60","60",
我想要什么:
我想要T
和F
不带引号。