excel转换成vcf报错
import quopriimport xlrd
#111.xlsx为需要处理的表格(姓名+电话)
file2='1_(最新版本)深圳沿江高速项目通讯录(2021.7.6)(1).xlsx'
#123.vcf 为处理后生成的文件
file1=open('123.vcf','w+',encoding='utf-8')
workbook=xlrd.open_workbook(file2)
sheet=workbook.sheet_by_index(0)
n_of_rows=sheet.nrows
print(n_of_rows)
for i in range(n_of_rows):
file1.write('BEGIN:VCARD\n')
file1.write('VERSION:2.1\n')
name=sheet.cell(i,0).value
name1='N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;'+str(quopri.decodestring(name.encode())).replace('\\x','=').upper()+';;;\n'
name2='FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;'+str(quopri.decodestring(name.encode())).replace('\\x','=').upper()+'\n'
file1.write(name1)
file1.write(name2)
print('TEL;CELL:'+str(int(sheet.cell(i,1).value))+'\n')
file1.write('TEL;CELL:'+str(int(sheet.cell(i,1).value))+'\n')
file1.write('END:VCARD\n')
file1.close()
报错原因:Traceback (most recent call last):
File "C:\Users\15125\Desktop\csv_vcf.py", line 10, in <module>
workbook=xlrd.open_workbook(file2)
File "D:\python3.8\lib\site-packages\xlrd\__init__.py", line 170, in open_workbook
raise XLRDError(FILE_FORMAT_DESCRIPTIONS+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported xlrd不支持xlsx,只支持xls。
想读取xlsx,用openpyxls。
页:
[1]