我試圖讓我的輸出從我的代碼進入一個excel電子表格,我不斷收到此特定錯誤:Python的PDF刮板輸出到Excel
「異常:嘗試覆蓋細胞:SHEETNAME = U」表1'rowx = 1 colx = 0「
我如何設置我的代碼是我需要它以便找到項目並打印所需的結果,因爲我正在使用它來刮擦.PDF並且它會產生如果我想把它全部寫入一個文本文件,則需要確切的輸出。但我希望輸出爲excel,因此我可以指定數據的位置。看起來,因爲代碼的輸出循環遍歷結果,它還會嘗試將所有內容都連續放在第0行第0列中,並且我會不斷收到有關覆蓋數據的錯誤。
from xlwt import Workbook, Formula, easyxf
wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
lines = open("register.txt", "r").readlines()
search_counters = {
"Per End": 0,
}
lines=[line for line in lines if line] # removes empty lines, if there are any
for i, line in enumerate(lines):
for search_key in search_counters.keys():
if search_key in line:
# print the previous line if the current line contains "Per End"
search_counters[search_key] += 1
if search_key == "Per End":
print lines[i-1]
EE_Name = lines[i-1]
wb.save('payroll2.xls')
對不起,太模糊了。我不想輸出覆蓋。我需要它列出數據輸出到第一列的新行。 –