2016-04-21 132 views
-1

我有一個多張工作簿excel工作簿,我想從工作簿的工作表中導入兩列,我該怎麼做?我在網上無處不在,也不在哪裏。我正在嘗試使用軟件包openpyxl。使用openpxl和python導入一個xlsx文件

+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早期版本可能有不同的語法。

+0

謝謝你的工作完美 – Anny

+0

不客氣安妮:) –