生活随笔
收集整理的這篇文章主要介紹了
【MIKE HYDRO】断面处理-excel断面数据转成可导入的txt格式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
excel斷面數據轉可導入的txt格式
excel斷面數據格式為:
import xlrddef re():readbook = xlrd.open_workbook(r'C:\Users\Lenovo\Desktop\tt.xlsx')sheet = readbook.sheet_by_index(0)nrows = sheet.nrowsncols = sheet.ncolstopoid=str(int(sheet.cell(0,0).value))f=open('E:/tt1.txt', 'a')f.write(topoid)rivername=sheet.cell(1,0).valuef.write('\r\n'+rivername)chainage = str(sheet.cell(2,0).value)f.write('\r\n' + ' '+chainage)f.write('\r\n'+'COORDINATES')co=str(sheet.cell(4,0).value)f.write('\r\n' +' '+ co)f.write('\r\n' + 'FLOW DIRECTION')fd = str(int(sheet.cell(6, 0).value))f.write('\r\n' + ' '+fd)f.write('\r\n' + 'PROTECT DATA')pd = str(int(sheet.cell(8, 0).value))f.write('\r\n' + ' '+pd)f.write('\r\n' + 'DATUM')datum = str(sheet.cell(10, 0).value)f.write('\r\n' + ' '+datum)f.write('\r\n' + 'CLOSED SECTION')cs = str(int(sheet.cell(12, 0).value))f.write('\r\n' + cs)f.write('\r\n' + 'RADIUS TYPE')rt = str(int(sheet.cell(14, 0).value))f.write('\r\n' + ' '+rt)f.write('\r\n' + 'DIVIDE X-Section')ds = str(int(sheet.cell(16, 0).value))f.write('\r\n' + ds)f.write('\r\n' + 'SECTION ID')f.write('\r\n' + ' ')f.write('\r\n' + 'INTERPOLATED')ip = str(int(sheet.cell(19, 0).value))f.write('\r\n' + ' '+ip)f.write('\r\n' + 'ANGLE')ag1 = str(sheet.cell(21, 0).value)ag2 = str(int(sheet.cell(21, 1).value))f.write('\r\n' + ' '+ag1+' '+ag2)f.write('\r\n' + 'RESISTANCE NUMBERS')rn1 = str(int(sheet.cell(23, 0).value))rn2 = str(int(sheet.cell(23, 1).value))rn3 = str(sheet.cell(23, 2).value)rn4 = str(sheet.cell(23, 3).value)rn5 = str(sheet.cell(23, 4).value)rn6 = str(sheet.cell(23, 5).value)f.write('\r\n'+' '+rn1+' '+rn2+' '+rn3+' '+rn4+' '+rn5+' '+rn6)nu = str(int(sheet.cell(24, 1).value))f.write('\r\n' + 'PROFILE'+' '+nu)for i in range(nrows-2-25):p1 = str(sheet.cell(25+i, 0).value)p2 = str(sheet.cell(25 + i, 1).value)p3 = str(sheet.cell(25 + i, 2).value)p4 = str(sheet.cell(25 + i, 3).value)p5 = str(int(sheet.cell(25 + i, 4).value))p6 = str(sheet.cell(25 + i, 5).value)p7 = str(int(sheet.cell(25 + i, 6).value))f.write('\r\n'+' '+p1+' '+p2+' '+p3+' '+p4+' '+p5+' '+p6+' '+p7)f.write('\r\n' + 'LEVEL PARAMS')l1 = str(int(sheet.cell(nrows-1, 0).value))l2 = str(int(sheet.cell(nrows - 1, 1).value))l3 = str(sheet.cell(nrows - 1, 2).value)l4 = str(int(sheet.cell(nrows - 1, 3).value))l5 = str(sheet.cell(nrows - 1, 4).value)l6 = str(int(sheet.cell(nrows - 1, 5).value))f.write('\r\n' + '*******************************')f.closereturn Noneif __name__ == "__main__":re()
總結
以上是生活随笔為你收集整理的【MIKE HYDRO】断面处理-excel断面数据转成可导入的txt格式的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。