参考:https://blog.csdn.net/weixin_43179111/article/details/82745390
https://www.jb51.net/article/180348.htm
https://www.jb51.net/article/211271.htm
Python中几种常用包比较最近xlrd更新到了2.0.1版本,只支持.xls文件。所以pandas.read_excel(‘xxx.xlsx’)会报错:xlrd.biffh.XLRDError: Excel xlsx file; not supported
可以安装旧版xlrd,在cmd中运行:
pip uninstall xlrd
pip install xlrd==1.2.0
也可以用openpyxl代替xlrd打开.xlsx文件:
python使用openpyxl库读写Excel表格的方法(增删改查操作)1. openpyxl库的基础使用
import openpyxl
# 打开excel表格
data_excel = openpyxl.load_workbook(u'C:/Users/10344/Desktop/人员信息.xlsx')
# ...
for sheet_name in data_excel.sheetnames:
print(sheet_name)
# 在xlsl中存在多个sheet表格时,可指定,也可硬双面的循环全部列出
sheet = data_excel['Sheet1']
cell = sheet.cell(1, 3)
# 获取单元格的值
print('value:%s' % cell.value)
# 获取行号、列号
print('row: %d, col: %d' % (cell.row, cell.column))
# 获取列名
print('column_letter: %s' % cell.column_letter)
# 单元格的坐标
print('coordinate: %s' % cell.coordinate)
# 单元格数据格式,n: 数字,s:字符串,d: 日期
print('data_type: %s' % cell.data_type)
# 单元格编码格式
print('encoding: %s' % cell.encoding)
# 单元格样式
print('style: %s' % cell.style)
# 单元格批注
print('comment: %s' % cell.comment)
data_excel.close()



