python的Excel只支持这种后缀:.xlsx openpyxl
定位excel中的单元格数值:
from openpyxl import load_workbook wb=load_workbook("ex.xlsx")#打开Excel sheet=wb['cs']#定位表单 res=sheet.cell(1,1).value#定位单元格 根据行列值定位 print("拿到结果",res)
获取excel最大行与最大列:
print("最大行:{}".format(sheet.max_row)) print("最大列:{}".format(sheet.max_column))
打印某个单元格的数据:print("获取数据:{},类型是{}".format(sheet.cell(1,1).value)
打印某个单元格的数据还有类型:单元格中的数字的类型是数字,其他类型都是字符串
print("获取数据:{},类型是{}".format((sheet.cell(1,1).value),type(sheet.cell(1,1).value)))
边角料小芝士:
字符串转换类型:
s='True' print(s,type(s)) s='True' print(eval(s),type(eval(s))) s={"age":18} print(s,type(s)) s='{"age":18}' print(s,type(s)) s='{"age":18}' print(eval(s),type(eval(s)))