-1
我需要將數據從文本文件複製到excel文件,但不覆蓋舊數據。使用openpyxl寫入excel文件而不覆蓋舊內容
我的代碼:
import os,sys
from openpyxl import Workbook
from openpyxl.compat import range
wb = Workbook()
Excelfilename = 'LogErrors.xlsx'
ws1 = wb.active
ws1.title = "Historique"
excelData = []
try:
with open('out.txt') as f:
for line in f:
excelData.append([word for word in line.split("\t") if word])
for lines in range(1,len(excelData)):
for columns in range(1,len(excelData[lines])):
ws1.cell(column=columns, row=lines, value=excelData[lines][columns-1])
wb.save(filename = Excelfilename)
except Exception, e:
print e.message