你如何通过Excel工作簿与多个工作表仅取出发言权列“C”,“E”和“F”的数据迭代?
这里是我迄今的代码:
public static string ExtractData(string filePath)
{
Excel.Application excelApp = new Excel.Application();
Excel.Workbook workBook = excelApp.Workbooks.Open(filePath);
string data = string.Empty;
int i = 0;
foreach (Excel.Worksheet sheet in workBook.Worksheets)
{
data += "******* Sheet " + i++.ToString() + " ********\n";
//foreach (Excel.Range row in sheet.UsedRange.Rows)
//{
// data += row.Range["C"].Value.ToString();
//}
foreach (Excel.Range row in sheet.UsedRange.Rows)
{
foreach (Excel.Range cell in row.Columns)
{
data += cell.Value + " ";
}
data += "\n";
}
}
excelApp.Quit();
return data;
}
非常感谢您的宝贵时间,任何帮助表示赞赏。