openpyxl 获取单元格的值、行、列、坐标

from openpyxl import load_workbook
workbook = load_workbook(filename = "test.xlsx")
sheet = workbook["Sheet1"] 
data = sheet.cell(row=1, column=1)
print("单元格的值:",data.value,"
单元格所在行的数值:",data.row,"
单元格所在列的数值:",data.column,"
单元格的坐标:",data.coordinate)
 
word = get_column_letter(1)
print('数字列号转为英文字母列号: ', word)

输出:

单元格的值:测试
单元格所在行的数值:1
单元格所在列的数值:1
单元格的坐标:A1
数字列号转为英文字母列号: A

 

你可能感兴趣的