简体   繁体   English

如何使用公式从 Excel 单元格中获取值? Openpyxl data_Only 标志无法正常工作

[英]How to fetch Value from Excel cell with formula ? Openpyxl data_Only flag doesn't work properly

I have a automation script, in which openpyxl writes some data into Excel file.我有一个自动化脚本,其中 openpyxl 将一些数据写入 Excel 文件。 And that Excel file has some Formulas.并且那个 Excel 文件有一些公式。 On next step i want to fetch that formulated cell value in python using openpyxl or Pandas, but OpenpyXl return as None and pandas return as Nan .在下一步中,我想使用 openpyxl 或 Pandas 获取 python 中的公式化单元格值,但 OpenpyXl 返回为None并且 pandas 返回为Nan I know about Xlwings, but unfortunately xlwings doesn't work in Linux.我知道 Xlwings,但不幸的是 xlwings 在 Linux 中不起作用。

If there are any other workaround and working in Linux, please let me know.如果有任何其他解决方法并在 Linux 中工作,请告诉我。 Thanks in Advance.提前致谢。

Xlrd module can read the cell value, even it has formula. Xlrd 模块可以读取单元格值,即使它有公式。 try the below code Mark it as solved if it works.试试下面的代码如果它有效,请将其标记为已解决。

import xlrd
book = xlrd.open_workbook("excel.xlsx")
sheet = book.sheet_by_index(0)
value= sheet.cell_value(1, 1)
print(value)

You probably need to save the document first and then reopen it.您可能需要先保存文档,然后再重新打开它。 You could try using xlwings or the win32 module to save as.您可以尝试使用 xlwings 或 win32 模块另存为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM