赞
踩
- import openpyxl
-
- # 打开excel表格
- workbook = openpyxl.load_workbook('xxxxxxx.xlsx')
-
- # 打印excel全部的sheet名称
- print(workbook.sheetnames)
-
- # 定位到单元表
- sheet = workbook['Sheet2']
-
- # 获取该单元表尺寸
- print(sheet.dimensions)
-
- # 获取单个单元格
- cell = sheet['F1']
- print(cell.value)
- print('---------------------')
-
- # 获取一列单元格
- cells = sheet['F1:F5'] # sheet['A'] 为获取一列中所有元素
- for cell in cells: # 遍历列的内容
- print(cell[0].value)
- print('-----------------')
-
- # 获取任意范围的单元格
- cols = sheet['D1:H5'] # 定义单元格范围
- for col in cols: # 遍历范围内所有单元格
- for cell in col: # 遍历单元格的内容
- print(cell.value)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。