我通过 C# 中的互操作 excel 对象使用 UsedRange 来获取工作表的最后一行。工作表是新创建的,仅编辑了 Name 属性。但是,当我得到 ws.UsedRange.Rows.Count 时,我得到了超过 10k。为什么这不给我 0 或 1?我怎样才能得到真正的最后一行?
Application xlApp = null;
Worksheet temp;
Range cell;
int row;
int col;
int i;
xlApp = new Application();
xlApp.Visible = true;
Workbook wbDetail = xlApp.Workbooks.Add();
wbDetail.Worksheets.Add(Type.Missing, Type.Missing, 26, XlWBATemplate.xlWBATWorksheet);
i = 0;
while(i < 29)
{
temp = (Worksheet)wbDetail.Worksheets[i+1];
temp.Name = "TITLE_"+i
i++;
}
DateTime reqdate;
i=0;
while(i<29)
{
temp = (Worksheet)wbDetail.Worksheets["TITLE_"+i];
int j = 0;
temp.get_Range("A1", Type.Missing).Value = "TITLE STUFF";
row = temp.UsedRange.Rows.Count;
while(j < 50)
{
cell = (Range)temp.Cells[row+1, j+1];
cell.Value = j;
j++;
}
}
i++
}
wbDetail.Save();