今天学习东西是从一个Excel文件中取出一个单元格的数据,并打印出来。对比cell 和 cell_vavalue 的不同。
源程序如下:
import xlrd
filename = "D:\python\pythonProject\000001.xlsx"
book = xlrd.open_workbook(filename, encoding_override="utf-8")
text = book.sheets()
for book in text:
sheet_name = [book.name]
sbs = book.cell(1, 0)
print(sbs)
sbs = book.cell_value(1, 0)
print(sbs)
print(sheet_name)
运行程序时候,出现如下错我
Traceback (most recent call last):
File “D:\python\pythonProject\测试-1.py”, line 4, in
book = xlrd.open_workbook(filename, encoding_override=“utf-8”)
File “C:\Users\ThinkPad\AppData\Local\Programs\Python\Python39\lib\site-packages\xlrd_init_.py”, line 111, in open_workbook
with open(filename, “rb”) as f:ValueError: embedded null character
查了一下,ValueError: embedded null character的意思是:嵌入的值错误:空字符
实在搞不明白这个错误怎么回事,
然后我尝试打