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

后端 未结 8 1162
-上瘾入骨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 19:18

    Using openpyxl

    from openpyxl import load_workbook
    # The source xlsx file is named as source.xlsx
    wb=load_workbook("source.xlsx")
    
    ws = wb.active
    first_column = ws['A']
    
    # Print the contents
    for x in xrange(len(first_column)): 
        print(first_column[x].value) 
    

提交回复
热议问题