Python reads only the formula from excel cell

浪子不回头ぞ 提交于 2020-04-10 05:10:03

问题


I have a excel 2010 file which has cells (See C2 below in formula bar) with formulae. (Screenshot 1 below)

enter image description here

I am reading the value using python and it's printing the formula instead of actual value of the cell (Screenshot below of eclipse console.)

enter image description here

I want the results to print 10.188.11.184 which is the value populated by the formula of the excel cell. How can this be achieved? Thanks in advance.


回答1:


From: https://openpyxl.readthedocs.org/en/latest/usage.html#read-an-existing-workbook

data_only controls whether cells with formulae have either the formula (default) or the value stored the last time Excel read the sheet.

wb = load_workbook('file.xlsx', data_only=True)



回答2:


You can use xlrd module and do the reading easily.

read_fullreport = xlrd.open_workbook(report_to_read)
read_fullreport_sheet = read_fullreport.sheet_by_index(0)
ipAddressofMC = read_fullreport_sheet.cell_value(row_nr, col_nr)


来源:https://stackoverflow.com/questions/30734294/python-reads-only-the-formula-from-excel-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!