我有excel文件與2列(empid,empname),我必須閱讀第1列8行然後第2列8行,通過以下代碼我得到第一列8行,但在第二列的行或不填充內部,他們只填寫第一列的行。這是我的代碼將excel文件移動到datagridview
for (int Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
{
if (Cnum == 1)
{
dt.Columns.Add((ShtRange.Cells[1, Cnum] as Excel.Range).Value2.ToString());
for (int Rnum = 1; Rnum <= 9; Rnum++)
{
dt.Rows.Add((ShtRange.Cells[Rnum, 1] as Excel.Range).Value2.ToString());
}
}}
for (int Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
{
if (Cnum == 2)
{
dt.Columns.Add((ShtRange.Cells[1, Cnum] as Excel.Range).Value2.ToString());
for (int Rnum = 1; Rnum <= 9; Rnum++)
{
dt.Rows.Add((ShtRange.Cells[Rnum,2] as Excel.Range).Value2).ToString();
}
}
}
excel文件的極限時間是?(.csv,.xls,.xlsx) – Tinwor