如何通过 C# 将 Excel 中的公式值解析为文本
我必须从 MS Excel 文件中解析出一些数据。
我需要从中获取数据的单元格将公式文本作为其值。
例如:
Sheet 2 [A1].Value = "$50"
Sheet 1 [A1].Formula = "='Sheet2'!A1"
当我获取 Sheet1 [A1]
的值时,我得到的是 ='Sheet2'!A1
,而不是 $50
。
有没有办法使用 C# 从 Sheet1[A1]
获取公式计算后的文本值?
I have to parse out some data from a MS Excel file.
The cells that I need to grab data out of have formula text as its value.
For example:
Sheet 2 [A1].Value = "$50"
Sheet 1 [A1].Formula = "='Sheet2'!A1"
When I grab the value for Sheet1 [A1]
, I get ='Sheet2'!A1
, not $50
.
Is there a way to get the text value after formula calculation from Sheet1[A1]
using C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我使用 Rup 提到的 Microsoft.Office.Interop.Excel 得到的结果
Here is what I got using Microsoft.Office.Interop.Excel as mentioned by Rup
我不确定范围 处理该集,但我猜它等于 Value2 而不是与电子表格相同的一般输入。尝试:
明确地将其设置为论坛。您可能还需要触发重新计算,但我预计不会。
I'm not sure which member of Range handles that set but I'd guess it equates to Value2 and not a general input in the same way as the spreadsheet. Try:
to explicitly set that as a forumula. You might also need to trigger a recalculation but I'd expect not.