【发布时间】:2013-10-01 13:44:45
【问题描述】:
我正在尝试加载当前存在的工作表并导入如下所示的文本文件(逗号分隔值)屏幕截图,
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
还有一个问题:如何告诉python从excel表格的A3列开始导入文本数据?
【问题讨论】:
标签: excel python-2.7 text openpyxl