C# 迭代excel工作表中特定列号的所有行,并对每行值进行一些处理
我试图创建一个循环,遍历excel工作表中特定列号的所有行,比如列号16,并对每行中每个单元格的值进行一些处理。 例如,循环将遍历单元格1,16,然后下一个单元格转到单元格2,16,然后下一个单元格转到单元格3,16…然后一直转到该工作表在该特定列号(在本例中为列号16)中有多少行。 到目前为止,我能够使用以下语句获取和设置单个excel单元格的值:C# 迭代excel工作表中特定列号的所有行,并对每行值进行一些处理,c#,.net,excel,C#,.net,Excel,我试图创建一个循环,遍历excel工作表中特定列号的所有行,比如列号16,并对每行中每个单元格的值进行一些处理。 例如,循环将遍历单元格1,16,然后下一个单元格转到单元格2,16,然后下一个单元格转到单元格3,16…然后一直转到该工作表在该特定列号(在本例中为列号16)中有多少行。 到目前为止,我能够使用以下语句获取和设置单个excel单元格的值: string cellValue = excelSheet.Cells[1, 16].Value.ToString(); //Do some pr
string cellValue = excelSheet.Cells[1, 16].Value.ToString();
//Do some processing.
excelSheet.Cells[1, 16] = cellValue;
但是我想在我的循环中循环通过行号到类似这样的音调:
string cellValue = excelSheet.Cells[n, 16].Value.ToString();
//Do some processing.
excelSheet.Cells[n, 16] = cellValue;
有什么想法吗?你需要一个循环的
,
这里:
for(int n = 1; n <= excelSheet.Columns.Count; n++)
{
string cellValue = excelSheet.Cells[n, 16].Value.ToString();
//Do some processing.
excelSheet.Cells[n, 16] = cellValue;
}
for(int n=1;n您需要一个for循环
这里:
for(int n = 1; n <= excelSheet.Columns.Count; n++)
{
string cellValue = excelSheet.Cells[n, 16].Value.ToString();
//Do some processing.
excelSheet.Cells[n, 16] = cellValue;
}
for(int n=1;n我假设您使用的是C#和Microsoft.Office.Interop.Excel COM+库
试试像这样的东西
Microsoft.Office.Interop.Excel.Range range = excelSheet.UsedRange;
for (int index = 0; index < range.Rows.Count; index++)
{
string cellValue = excelSheet.Cells[index, 16].Value.ToString();
//Do some processing.
excelSheet.Cells[index, 16] = cellValue;
}
Microsoft.Office.Interop.Excel.Range=excelSheet.UsedRange;
对于(int index=0;index
我假设您使用的是C#和Microsoft.Office.Interop.Excel COM+库
试试像这样的东西
Microsoft.Office.Interop.Excel.Range range = excelSheet.UsedRange;
for (int index = 0; index < range.Rows.Count; index++)
{
string cellValue = excelSheet.Cells[index, 16].Value.ToString();
//Do some processing.
excelSheet.Cells[index, 16] = cellValue;
}
Microsoft.Office.Interop.Excel.Range=excelSheet.UsedRange;
对于(int index=0;index