您好,登錄后才能下訂單哦!
#coding=utf-8
import xlrd,chardet,traceback,csv
#根據列名獲取相應序號
def getColumnIndex(table,columnName):
columnIndex=None
for i in range(table.ncols):
if(table.cell_value(0,i)==columnName):
columnIndex=i
break
return columnIndex
#根據Excel中sheet名稱讀取數據
def readExcelDataByName(fileName,sheetName):
table=None
try:
data=xlrd.open_workbook(fileName)
table=data.sheet_by_name(sheetName)
except Exception:
pass
return table
if __name__=='__main__':
#example
csv_file=open('房源清單.csv','w+',newline='',encoding='utf-8')
writer=csv.writer(csv_file)
fileName=r'/Users/Desktop/python/python生成現金流套表/房源清單-(截止1031).xlsx'
sheetName='Sheet1'
table=readExcelDataByName(fileName,sheetName)
list=[]
for i in range(0,8000):
try:
xm=table.cell_value(i,getColumnIndex(table,'項目'))
cplx=table.cell_value(i,getColumnIndex(table,'產品類型'))
fymc=table.cell_value(i,getColumnIndex(table,'房源名稱'))
except Exception:
pass
list.append([xm,cplx,fymc])
for row in list:
writer.writerow(row)
csv_file.close()
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。