xlrd&openpyxl提取错误的单元格值(Excel)

需要帮助,请! 看起来像一个简单的任务 – 我需要从特定的电子表格单元格中提取值并总结出来。 但是,即使在第一步,我也失败了 – 取而代之。 起初,我认为模块是错误的(openpyxl正在定期升级,我错过了一些东西),但是xlrd模块产生了相同的错误结果! 代码如下:

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 = True添加到loadede工作簿:wb = load_workbook(“file.xlsx”,data_only = True)。 该代码产生相同的结果。 没有这个标志,所有得到的都是奇怪的公式:= 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 =分享

您正在阅读的数据看起来像Excel的原始date时间值版本。 你可能错误的列(即给出错误的列索引)。