Openpyxl - How to read only one column from Excel file in Python?

后端 未结 8 1160
-上瘾入骨i
-上瘾入骨i 2020-12-14 18:14

I want to pull only column A from my spreadsheet. I have the below code, but it pulls from all columns.

from openpyxl import Workbook, load_workbook

wb=load         


        
8条回答
  •  天涯浪人
    2020-12-14 18:54

    By using openpyxl library and Python's list comprehensions concept:

    import openpyxl
    
    book = openpyxl.load_workbook('testfile.xlsx')
    user_data = book.get_sheet_by_name(str(sheet_name))
    print([str(user_data[x][0].value) for x in range(1,user_data.max_row)])
    

    It is pretty amazing approach and worth a try

提交回复
热议问题