gpt4 book ai didi

c# - 如何通过列名获取单元格值?

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:54 25 4
gpt4 key购买 nike

我下面的代码工作正常,但如何按列名称指定?

for (int resultFiltered = 1; resultFiltered <= filteredRange.Areas.Count; areaId++)
{
Range areaRange = filteredRange.Areas.Item(resultFiltered);
string studentID = areaRange.Cells[1, 1].Value2; //How to specify column name?
}

最佳答案

您可以用列号代替列字母。

例子:

object rangeObject = activeWorksheet.Cells[3, "W"];

Range range = (Range)rangeObject;

object rangeValue = range.Value2;

string cellValue = rangeValue.ToString();

或者如果这有帮助,在我正在访问的 Excel 文件中,我将单元格“W5”命名为“overflow5”:

Range topExcel = activeWorksheet.get_Range("overflow5", Type.Missing);

topExcel.Select();

string cellValue = topExcel.Value2.ToString();

关于c# - 如何通过列名获取单元格值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42849103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com