简体   繁体   English

如何使用C#访问Excel工作表中的公式?

[英]how can I access the formula in an excel sheet with c#?

I am parsing thorugh a 2000+ record excel file, and need ot be able to grab the formula itself from the cells and not just the value. 我正在解析一个有2000多个记录的excel文件,并且需要能够从单元格中获取公式本身,而不仅仅是值。 For example, one cell 'Contributions' may be a single number like 1500 or it can be a few numbers 1500+500-200 but I dont want the total, I want the actual formula so I can get the different numbers. 例如,一个单元格“贡献”可以是单个数字,例如1500 ,也可以是几个数字1500 + 500-200,但是我不希望总数,我想要实际的公式,这样我就可以得到不同的数字。

I was just parsing with an oledbconnection and that only seems to get me the total. 我只是用oledbconnection进行解析,似乎只能使我了解总数。 How would I go about getting the formula? 我将如何获得配方? Is it possible (I can get it in either XLS or XLSX)? 有可能吗(我可以在XLS或XLSX中获得它)?

Thank you. 谢谢。

一个快速的Google发现了以下内容: http : //codingsense.wordpress.com/2009/03/01/get-all-formula-from-excel-cell/

Using OLE Automation, you can access the formula in a cell as follows: 使用OLE自动化,可以按如下方式访问单元格中的公式:

formula = worksheet.Cells(1, 1).Formula

EDIT: 编辑:

To use OLE Automation in your C# project, see the following Microsoft KB article : 要在C#项目中使用OLE自动化,请参见以下Microsoft KB文章

The xslx is an xml file so it should be easy enough to read. xslx是一个xml文件,因此应该足够容易阅读。 Alternatively you can use third-part components like the one from Infragistics that allows you to read xsl-files programmatically and also to access the formulas. 或者,您可以使用第三方组件,例如Infragistics的组件,该组件允许您以编程方式读取xsl文件,还可以访问公式。

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

相关问题 如何在 C# GUI 中搜索 Excel 工作表? - How can I search through an Excel sheet in a C# GUI? 我如何在C#中通过数字获取excel中的工作表以及如何在打开后关闭Excel applicatin - how i can get the sheet in excel by number in c# and how to close Excel applicatin after open it 如何使用C#访问Excel工作表中的按钮 - How to access button in excel sheet using c# 我如何在C#for Excel中使用函数替换为公式 - How I can use in C# for Excel, the function Replace with the function Formula 打开具有c#完全访问权限的Excel工作表 - Opening Excel sheet with full access in c# 如何将网格线添加到一个工作表而不是另一个工作表(C#Excel Interop)? - How can I add gridlines to one sheet and not the other (C# Excel Interop)? 如何从c#中的excel表中选择特定列? - How can i select specific columns from excel sheet in c#? 如何使用OLEDB for C#在Excel中执行“从[sheet1 $]其中列为L的*中选择*”? - How can I do this “select * from [sheet1$] where column is L” in Excel using OLEDB for C#? 如何在查询C#的Excel工作表中选择一组行和列? - How can I select a set of rows and columns from an excel sheet in query for C#? 如何使用C#将Excel工作表中的数据插入SQL Server - How can I insert data from Excel sheet into SQL Server using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM