读取单元格的文本而不是值 [英] Read the text of the Cell instead of Value

查看:35
本文介绍了读取单元格的文本而不是值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序来比较 C# 中的两个 excel 文件.我可以打开文件并读取 excel 的值,但我想比较单元格中的文本.

I am trying to write a program to compare two excel files in C#. I am able to open the files n read the value of the excel but i would like to compare the text in the Cell.

例如在我的工作表中,如果单元格 A3 有一个公式,请说=A1+A2".我可以使用

For example In my sheet, If the Cell A3 is having a formula say "=A1+A2". I am able to retrieve the value using

((Range)worksheet.Cells[2,0]).Value 

of A3(A1 和 A2 的总和)但不是=A1+A2".我如何获取文本.(.Text 始终为空)

of A3(the total value of A1 and A2) but not "=A1+A2". How can i get the text.(.Text is always null)

谢谢

推荐答案

看起来公式属性应该有.

Looks like the Formula property should have it.

Range.Formula 属性

"如果单元格包含常量,则此属性返回常量.如果单元格为空,则此公式属性返回空字符串.如果单元格包含公式,则公式属性将公式作为相同的字符串返回将在编辑栏中显示的格式(包括等号)."

"If the cell contains a constant, this property returns the constant. If the cell is empty, this Formula property returns an empty string. If the cell contains a formula, the Formula property returns the formula as a string in the same format that would be displayed in the formula bar (including the equal sign)."

((Range)worksheet.Cells[2,0]).Formula;

这篇关于读取单元格的文本而不是值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆