Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel “巨蟒投掷”';utf8';编解码器可以';t解码位置0处的字节0xd0“;错误_Excel_Python 2.7_Text_Openpyxl - Fatal编程技术网

Excel “巨蟒投掷”';utf8';编解码器可以';t解码位置0处的字节0xd0“;错误

Excel “巨蟒投掷”';utf8';编解码器可以';t解码位置0处的字节0xd0“;错误,excel,python-2.7,text,openpyxl,Excel,Python 2.7,Text,Openpyxl,我正在尝试加载当前存在的工作表,并导入如下所示的文本文件(逗号分隔值)屏幕截图 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)

我正在尝试加载当前存在的工作表,并导入如下所示的文本文件(逗号分隔值)屏幕截图

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”编解码器无法解码位置0中的字节0xd0:无效的连续字节


还有一个问题:如何让python导入excel工作表中从A3列开始的文本数据?

Unicode编码让我感到困惑,但您不能强制该值忽略无效字节,方法是:

value = unicode(value, errors='ignore')

以下是有关unicode的详细阅读的一个很好的答案:

您好,您确定没有包含

您可以尝试使用。通常Windows+UTF+8会有点麻烦。虽然它显示的字符可能不是BOM。

只处理格式(xlsx/xlsm)。 请尝试使用Excel保存为xlsx文件格式,而不是xls文件格式

如果要将xls文件转换为代码中的xlsx。请尝试以下列表中的一个选项:

  • 在Windows中,还可以使用该工具将xls转换为xlxx
  • 在Linux中,请检查
  • 或者,您可以通过在Python中使用来转换为xlsx。请查收

  • 谢谢你,亚当!我试着这么做,但还是犯了同样的错误。