C#:获取细胞与Excel.interop价值 [英] C#: Getting a cell's value with Excel.interop
问题描述
我想从一个excel在C#软件文件得到一个单元格的值;不是文本,因为文本取决于列的大小,我不能改变它自己的软件不应当由该干扰。所以我的选择是获得的价值。
I want to get the value of a cell from an excel file with a software in C#; NOT THE TEXT, because the text depend of the size of the column, and I must not change it myself, the software should not be disturbed by that. So my choice was to get the value.
我得到我的范围是1单元:1,所以我有一个Range对象,但值字段和值2场不被认可的语言。我试着用的get_value(),但它需要一个参数,我不知道要放什么东西在里面,我没有找到关于它的单证。这里是我的代码(从循环中提取):
I get my cell as a range of 1:1, so I have a Range object, but Value field and Value2 field are not recognized by the language. I tried with get_Value() but it needs a parameter and I don't know what to put in it, i didn't find documentations about it. Here's my code (extracted from a loop):
if((string)(ws_Varsheet.get_Range("L" + iIndex, "L" + iIndex).Text) != "")
{
rng_ResolutionCell = ws_Varsheet.get_Range("L" + iIndex, "L" + iIndex);
float iResolution;
rng_ResolutionCell.Cells.get_Value(&iResolution); //what to do here?
str_Resolution = ((string)iResolution.toString()).Replace(",",".");
str_Resolution = str_Resolution.Replace(" ","");
mObj.Str_Resolution="1";
}
你能帮助我吗?由于提前通过
Can you help me with that? Thanks by advance.
推荐答案
我常常发现代码稍高于全国各地需要更加复杂。基本上阅读细胞是简单的:
I have often found codes a little more complex than needed all over. Basically reading a cell is as simple as:
Xl.Range rng = sheet.Cells[row, column] as Xl.Range;
return rng.Value2;
这篇关于C#:获取细胞与Excel.interop价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!