python 將資料寫入excel
阿新 • • 發佈:2018-11-01
參考部落格:
https://www.cnblogs.com/liuyang92/p/7492336.html
https://www.cnblogs.com/lhj588/archive/2012/01/06/2314181.html
https://www.cnblogs.com/liuyang92/p/7492336.html
https://www.cnblogs.com/jiangzhaowei/p/5857904.html
我自己寫的一段程式碼:
#開啟excel檔案讀取資料
data = xlrd.open_workbook('source_aa.xls',formatting_info=True)
#通過索引順序獲取:但是通過sheet_by_index獲取的sheet沒有write()方法
table = data.sheet_by_index(0)
#寫入的另外一個檔案
workbook = xlwt.Workbook(encoding='utf-8')
data_sheet = workbook.add_sheet('demo1')
for rowIndex in range(0,table.nrows):
for colIndex in range(0,table.ncols):
if '1' in str(table.cell(rowIndex, 0).value):
print('.....')
break
data_sheet.write(rowIndex, colIndex, table .cell(rowIndex, colIndex).value)
workbook.save('demo7.xls')