我怎样才能从Excel单元格地址 [英] How can i get the Cell address from excel
问题描述
我怎样才能从Excel中给出例如行和列数的单元格地址
How can i get the Cell address from excel given a row and column number for example
第2行和第3栏应该返回C2 ......请帮助
row 2 and col 3 should return C2... Please help
推荐答案
我不是VSTO C#大用户 - 我通常选择VBA。但是,以下对功能可能对您有用。不确定他们是否可以简化一些:
I'm not a big user of VSTO C# - I usually opt for VBA. However, the following pair of functions might be useful for you. Unsure if they can be streamlined some more:
public string RangeAddress(Excel.Range rng)
{
return rng.get_AddressLocal(false, false, Excel.XlReferenceStyle.xlA1,
missing, missing);
}
public string CellAddress(Excel.Worksheet sht, int row, int col)
{
return RangeAddress(sht.Cells[row, col]);
}
的
RangeAddress
将采取任何Excel范围扔你回来的地址。如果你想绝对样式(与美元符号,例如$ C $ 3),那么你必须在get_AddressLocal调用的前两个参数更改为true,真实。
The RangeAddress
will take any Excel range and throw you back the address. If you want the absolute style (with dollar signs, e.g. $C$3) then you have to change the first two parameters of the get_AddressLocal call to true, true.
要从一个行/列对单元格地址,你可以使用 CellAddress
。它确实需要一个表来获取地址。但是,你可以在换(Excel.Worksheet)ActiveSheet
如果你不想提供一个表(这可能会或可能无法正常工作,这取决于你所拥有的开放您VSTO会话)。
To get the cell address from a row/col pair, you can use CellAddress
. It does need a sheet to get the address. However, you could swap in (Excel.Worksheet)ActiveSheet
if you don't want to provide a sheet (this may or may not work, depending on what you have open in your VSTO session).
这篇关于我怎样才能从Excel单元格地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!