使用openpxl和python导入xlsx文件

时间:2016-04-21 02:17:46

标签: python arrays plot openpyxl

我有一个多表excel工作簿,我想从工作簿中的工作表中导入两列,我该怎么做?我一直在网上看到它,它不在哪里。我正在尝试使用openpyxl包。

1 个答案:

答案 0 :(得分:0)

你可以这样说:

from openpyxl import *

#import the excel workbook
wb = load_workbook('input.xlsx')
#this should give you the sheet names
WSheets = wb.sheetnames

#iterate through sheets
for i in WSheets:
    ws = wb[i]
    #To access values from a particular column of the sheet, for example column B
    print ws['B']

应该给予

(<Cell vane.B1>, <Cell vane.B2>, <Cell vane.B3>, <Cell vane.B4>, <Cell vane.B5>, <Cell vane.B6>, <Cell vane.B7>, <Cell vane.B8>, <Cell vane.B9>, <Cell vane.B10>, <Cell vane.B11>, <Cell vane.B12>, <Cell vane.B13>, <Cell vane.B14>, <Cell vane.B15>, <Cell vane.B16>, <Cell vane.B17>, <Cell vane.B18>, <Cell vane.B19>, <Cell vane.B20>, <Cell vane.B21>, <Cell vane.B22>, <Cell vane.B23>, <Cell vane.B24>, <Cell vane.B25>, <Cell vane.B26>, <Cell vane.B27>, <Cell vane.B28>, <Cell vane.B29>)

依旧......

注意:我使用openpyxl 2.4.0-a1早期版本可能有不同的语法。