我試圖加載一個現有的工作表和導入的文本文件(逗號分隔值)如下所示屏幕截圖「‘UTF8’編解碼器不能在0位置解碼字節0xd0」,Python的投擲的錯誤
Excel工作表:
文本文件:
我使用的代碼所示貝羅女:
# importing necessary modules for performing the required operation
import glob
import csv
from openpyxl import load_workbook
import xlwt
#read the text file(s) using the CSV modules and read the dilimiters and quoutechar
for filename in glob.glob("E:\Scripting_Test\Phase1\*.txt"):
spamReader = csv.reader((open(filename, 'rb')), delimiter=',')
#read the excel file and using xlwt modules and set the active sheet
wb = load_workbook(filename=r"E:\Scripting_Test\SeqTem\Seq0001.xls")
ws = wb.worksheets(0)
#write the data that is in text file to excel file
for rowx, row in enumerate(spamReader):
for colx, value in enumerate(row):
ws.write(rowx, colx, value)
wb.save()
我得到一個以下錯誤消息:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
一個問題:你怎麼知道蟒蛇導入從A3列在Excel工作表開始的文本數據?
謝謝你,亞當!我試圖做到這一點,但仍然是同樣的錯誤。 – Raj