日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python写excel文件出错_【求教】xlutils修改中文Excel文件出错

發布時間:2025/3/19 python 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python写excel文件出错_【求教】xlutils修改中文Excel文件出错 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

該樓層疑似違規已被系統折疊?隱藏此樓查看此樓

#coding=utf-8

import xlrd

import xlwt

from xlutils.copy import copy

sheetIndex=-1

file=xlrd.open_workbook(u'中文文件.xlsx')

writeFile=copy(file)

writeFile.encoding='utf8'

for sheet in file.sheets():

sheetIndex=sheetIndex+1

for rownum in range(1,sheet.nrows):

key=sheet.cell(rownum,4).value

val=sheet.cell(rownum,3).value

writeSheet=writeFile.get_sheet(sheetIndex)

writeSheet.write(rownum,4,(key+u'啊').encode('utf8'))

writeSheet.write(rownum,3,(val+u'1').encode('utf8')

writeFile.save(u'中文文件.xlsx')

下面是出錯信息

Traceback (most recent call last):

File "D:\PythonTest\ReplaceNationName.py", line 28, in

writeFile.save(u'中文文件.xlsx')

File "D:\Program Files\Python276\lib\site-packages\xlwt\Workbook.py", line 662, in save

doc.save(filename, self.get_biff_data())

File "D:\Program Files\Python276\lib\site-packages\xlwt\Workbook.py", line 637, in get_biff_data

shared_str_table = self.__sst_rec()

File "D:\Program Files\Python276\lib\site-packages\xlwt\Workbook.py", line 599, in __sst_rec

return self.__sst.get_biff_record()

File "D:\Program Files\Python276\lib\site-packages\xlwt\BIFFRecords.py", line 76, in get_biff_record

self._add_to_sst(s)

File "D:\Program Files\Python276\lib\site-packages\xlwt\BIFFRecords.py", line 91, in _add_to_sst

u_str = upack2(s, self.encoding)

File "D:\Program Files\Python276\lib\site-packages\xlwt\UnicodeUtils.py", line 50, in upack2

us = unicode(s, encoding)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)

總結

以上是生活随笔為你收集整理的python写excel文件出错_【求教】xlutils修改中文Excel文件出错的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。