【发布时间】:2014-05-06 11:27:21
【问题描述】:
我正在使用带有 xlrd 和 csv 模块的 Python 3.3 将 xls 文件转换为 csv。这是我的代码:
import xlrd
import csv
def csv_from_excel():
wb = xlrd.open_workbook('MySpreadsheet.xls')
sh = wb.sheet_by_name('Sheet1')
your_csv_file = open('test_output.csv', 'wb')
wr = csv.writer(your_csv_file, quoting=csv.QUOTE_ALL)
for rownum in range(sh.nrows):
wr.writerow(sh.row_values(rownum))
your_csv_file.close()
我收到此错误:TypeError: 'str' does not support the buffer interface
我尝试更改编码并将循环中的行替换为:
wr.writerow(bytes(sh.row_values(rownum),'UTF-8'))
但我收到此错误:TypeError: encoding or errors without a string argument
有人知道可能出了什么问题吗?
【问题讨论】:
标签: python csv python-3.x xlrd