简体   繁体   English

在Python中修改,重新计算和提取Excel中的结果

[英]Modifying, recalculating and and extracting results from Excel in Python

I would like to try and make a program which does the following, preferably in Python, but if it needs to be C# or other, that's OK. 我想尝试制作一个程序,最好在Python中执行以下操作,但是如果需要使用C#或其他程序,那就可以了。

  1. Writes data to an excel spreadsheet 将数据写入Excel电子表格
  2. Makes Excel recalculate formulas etc. in the modified spreadsheet 使Excel在修改的电子表格中重新计算公式等
  3. Extracts the results back out 提取结果回去

I have used things like openpyxl before, but this obviously can't do step 2. Is the a way of recalculating the spreadsheet without opening it in Excel? 我以前曾经使用过诸如openpyxl之类的东西,但这显然不能执行步骤2。是一种无需在Excel中打开即可重新计算电子表格的方法吗? Any thoughts greatly appreciated. 任何想法表示赞赏。

Thanks, 谢谢,

Jack 插口

You need some sort of UI automation with which you can control a UI application such as Excel. 您需要某种UI自动化,可以用来控制UI应用程序(例如Excel)。 Excel probably exposes some COM interface that you should be able to use for what you need. Excel可能会公开一些COM界面,您应该可以将其用于所需的内容。 Python has the PyWin32 library which you should install, after which you'll have the win32com module available. Python具有应安装的PyWin32库,之后您将具有可用的win32com模块。

See also: 也可以看看:

If you don't necessarily have to work with Excel specifically and just need to do spreadsheet using Python, you might want to look at http://manns.github.io/pyspread/ . 如果您不一定必须专门使用Excel,而只需要使用Python来制作电子表格,则可以查看http://manns.github.io/pyspread/

you could you pandas for reading in the data, using python to recalculate and then write the new files. 您可以用熊猫读取数据,使用python重新计算然后写入新文件。

For pandas it's something like: 对于熊猫来说,就像:

#Import Excel file
xls = pd.ExcelFile('path_to_file' + '/' + 'file.xlsx')
xls.parse('nyc-condominium-dataset', index_col='property_id', na_values=['NA'])

so not difficult. 所以不难。 Here the link to pandas. 这里是熊猫的链接

Have fun! 玩得开心!

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

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