我正在尝试使用xlwt将学位符号写到工作簿中,但是我在单元格中得到了一个额外的字符,就像这样-> S 58°15'31“ W 但是应该像这样-> S 58°15'31“ W
这是我用来创建轴承的功能。
def returnBearingString(azimuth):
bearing=None
dmsbearing=None
if azimuth>270 and azimuth<=360:
bearing = 360 - azimuth
dmsbearing=ddToDms(bearing)
dmsbearing = """N {0}°{1}'{2}" W""".format(int(dmsbearing[0]),int(dmsbearing[1]),int(round(dmsbearing[2],0)))
return dmsbearing
if azimuth>=0 and azimuth<=90:
dmsbearing=ddToDms(azimuth)
dmsbearing = """N {0}°{1}'{2}" E""".format(int(dmsbearing[0]),int(dmsbearing[1]),int(round(dmsbearing[2],0)))
return dmsbearing
if azimuth>90 and azimuth<=180:
bearing= 180 - azimuth
dmsbearing=ddToDms(bearing)
dmsbearing = """S {0}°{1}'{2}" E""".format(int(dmsbearing[0]),int(dmsbearing[1]),int(round(dmsbearing[2],0)))
return dmsbearing
if azimuth>180 and azimuth<=270:
bearing = azimuth-180
dmsbearing=ddToDms(bearing)
dmsbearing = """S {0}°{1}'{2}" W""".format(int(dmsbearing[0]),int(dmsbearing[1]),int(round(dmsbearing[2],0)))
return dmsbearing
此处具有将dd方位角转换成dms的功能
def ddToDms(dd):
negative = dd<0
dd=abs(dd)
minutes,seconds = divmod(dd*3600,60)
degrees,minutes = divmod(minutes,60)
if negative:
if degrees>0:
degrees = -degrees
elif minutes>0:
minutes = -minutes
else:
seconds = -seconds
return (int(degrees),int(minutes),round(seconds,3))
这是我的工作簿
workbook = xlwt.Workbook(encoding='utf-8')
sheet = workbook.add_sheet("""SEC {0} BLK {1}""".format(sec,blk))
bear = returnBearingString(az)
sheet.write(cnt,1,bear,style)
workbook.save(newBook)
方位角只是0到360之间的数字。