需要幫助,請!看起來像一個簡單的任務 - 我需要從某些電子表格單元中獲取值並對其進行總結。但即使在第一步,我也失敗了 - 取而代之。起初,我認爲模塊出問題了(openpyxl正在定期升級,我錯過了一些東西),但是xlrd模塊產生了相同的錯誤結果!下面的代碼:xlrd&openpyxl獲取錯誤的單元格值(Excel)
import xlrd, xlwt
wb = xlrd.open_workbook(r"E:\Projects_working (11).xlsx")
sheet = wb.sheet_by_name('Language Process')
for i in range(1, 100):
cellVal = sheet.cell(i, 14).value #need to find "5" in column 14
if type(cellVal) == float and cellVal == 5.0: #need to read corresp.
print(sheet.cell(i, 11).value) #values в column 11
結果,而不是整數(比如,22),所述代碼結束了一個浮子42782.61458。 (其它值是相似的,錯誤的:42782.66146,42781.38542,42781.42708等)
Orignially我用openpyxl模塊和DATA_ONLY =添加的標誌真正到loadede工作簿:WB = load_workbook( 「file.xlsx」, DATA_ONLY =真)。該代碼產生相同的結果。如果沒有這個標誌,所有得到的都是奇怪的公式:= B32 +((M32-B32)/ 2),= B41 +((M41-B41)/ 2)等這些公式的代碼(無標誌):
import openpyxl
wb = openpyxl.load_workbook(r"E:\Projects_working (11).xlsx")
sheet = wb.get_sheet_by_name('Language Process')
for i in range(1, 100):
cellVal = sheet.cell(row=i, column=14).value
if type(cellVal) == float and cellVal == 5.0:
print(sheet.cell(row=i, column=11).value)
下面是對文件的鏈接,以防萬一:https://docs.google.com/spreadsheets/d/1bFhkEs8JTVWCgZoW5_9lQ1q_T0gtijBhuywr6OVpfGc/edit?usp=sharing
John,你太棒了!謝謝,男人! (好天啊!我在尋找一些棘手的理由,而錯誤很明顯!) –