简体   繁体   English

用于基于公式的电子表格的最佳Python API?

[英]Best Python API for formula based Spreadsheet?

My requirement is to fetch the data out of Spreadsheet(.xlsx) by inputting values in some cells . 我的要求是通过在某些单元格中输入值来从Spreadsheet(.xlsx)中获取数据。

On inputting value, other formula cells must have the calculated values based on the formula embedded in the sheet. 输入值时,其他公式单元格必须具有基于表中嵌入的公式的计算值。

lets say I am inputting values in Cell A and B . 可以说我在单元格A和B中输入值。 C is a formula cell =A+B . C是公式单元格= A + B。

SO need to get the value in C and also other formula cells. SO需要获得C和其他公式单元格中的值。

Had written following code in python 3. 在python 3中编写了以下代码。

import openpyxl as op
new_excel = op.load_workbook('WorkBook1.xlsx',read_only=False)
spreadsheet = new_excel .get_sheet_by_name('Input Quote')
spreadsheet['B30'] = 'VAU'
spreadsheet['D30'] = 1000
spreadsheet['F30'] = 5000

new_excel.save('WorkBook2.xlsx')#saving in a new file as I need to maintain versions

loa_excel1 = op.load_workbook('WorkBook2.xlsx',data_only='TRUE')#Opening the new file
spreadsheet1 = loa_excel1.get_sheet_by_name('Input Quote')
print(spreadsheet1['J13'].value)
# Output is None

J13 is a formula Cell that has dependency on B30,D30 and F30(inputted values). J13是一个公式单元格,它依赖于B30,D30和F30(输入值)。

How can we achieve this in Python 3 ? 我们如何在Python 3中实现呢?

I have used openpyxl. 我用过openpyxl。 I find it very powerful. 我觉得它非常强大。 If you are familiar with VBA, you will see a lot of similarities between the syntax and functions used with openpyxl. 如果您熟悉VBA,则将在openpyxl所使用的语法和函数之间看到很多相似之处。 THere is also descent (but not great) documentation. 这也是下降(但不是很好)的文档。 http://openpyxl.readthedocs.io/en/stable/index.html . http://openpyxl.readthedocs.io/en/stable/index.html You can install openpyxl with pip install too. 您也可以通过pip install安装openpyxl。

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

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