feishicheng 2020-05-11
安装并导入模块
打开命令行窗口,输入:
pip install -i https://mirrors.aliyun.com/pypi/simple/ openpyxl
导入:
from openpyxl import load_workbook
打开表格有两种方式:
1、sheet = workbook.active 打开活跃的/唯一的表格
2、sheet = workbook[‘sheet1‘] 打开表格sheet1
选择某一格也有两种方式:
1、cell = sheet[‘A1‘] 获取A1格子
2、cell = sheet.cell(row=1,column=1) 获取第一行第一列的格子
cell.value 该格子的数据
from openpyxl import load_workbook workbook = load_workbook(filename=‘IP2LOCATION.xlsx‘)# sheet = workbook[‘sheet1‘] sheet = workbook.active# cell = sheet.cell(row=1,column=1) cell = sheet[‘A1‘] print(cell.value)