python获取Excel表中某一格的数据
安装并导入模块
打开命令行窗口,输入:
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)
相关推荐
diyanpython 2020-11-05
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20