我试图通过查找第一列(由日期组成)和标题行中的第一个空单元格来查找使用C#的Excel表的维度。无法在空引用异常上执行运行时绑定
这是我现在使用的代码:
public static void findingTableBounds()
{
string dateCol = "";
ArrayList dateColumn = new ArrayList();
ArrayList numberOfColumns = new ArrayList();
for (int column = 1; column < currentRow; column++)
{
dateCol = ((Excel.Range)workSheet.Cells[currentRow, 1]).Value2.ToString();
if (dateCol != "")
{
dateColumn.Add(dateCol);
currentRow++;
totalRow++;
Console.WriteLine("Total Row: {0}", totalRow);
}
else
{
Console.WriteLine("Total Row: {0}", totalRow);
currentRow = 2;
}
}
**注:对于这种方法的右括号,我不包括它,因为还有另外一个for循环做完全相同的作为上面的代码,但只有多少列。 (“Excel.Range”)workSheet.Cells [currentRow,1])。Value2.ToString();“我很确定发生这种情况,因为我试图在string是非空类型时为dateCol(一个字符串)分配一个空值(单元格)。不幸的是我不确定如何解决这个问题。
你的变量名似乎很奇怪。 `列
2011-02-08 23:39:05