且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有办法找到Excel中的一个范围内的范围是多少?

更新时间:2022-12-12 23:19:17

我想我会做什么,在这种情况下,首先构建由每个头和它的位置的查找表。对于列表中的关键,我会串连标题单元格在一起,使一个单一的查询值。所以,你的代码后紧跟的:

I think what I would do in this scenario is first construct a look-up list consisting of each header and its location. For the key in the list, I would concatenate the header cells together to make a single look-up value. So following on immediately after your code:

Dictionary<string, int> lookUpList = new Dictionary<string, int>();

// Loop through the rows

for (int i = 0; i < valueArray.GetLength(0); i++)
{
    // Identify the header rows

    if (valueArray[i, 0].ToString() == "WR")
    {
        // Concatenate the header strings into a single string

        string header = "";

        for (int j = 0; j < valueArray.GetLength(1); j++)
        {
            header += valueArray[i, j].ToString();
        }

        // Store the header location

        lookUpList.Add(header, i + 1);
    }
}



请记住,这是即兴,我的天堂 ŧ进行了测试。我不知道究竟是怎么 Range.get_Value 方法的地方数据放入数组,这样的尺寸可能是周围的错误的方式。我也正在做关于如何在电子表格中根据您所提供的数据,在图像上确定标题行假设。

Bear in mind that this is extempore and I haven't tested it. I'm not sure exactly how the Range.get_Value method places data into the array, so the dimensions might be the wrong way around. Also I'm making assumptions about how to identify header rows in your spreadsheet based on the image of the data you supplied.

无论如何,一旦构造可以执行简单的外观到提取头的行号:

Anyway, once constructed you can perform a simple look up to extract the row number of the header:

string userSelectedHeader = "concatenation of whatever the user selected";
int rowNumber = lookUpList[userSelectedHeader];



这是否在一定程度上帮助回答你的问题?

Does that go some way to helping answer your question?