相关疑难解决方法(0)

如何从现有excel文件中读取单元格值

我想读取excel文件中的每个单元格值,但即使在.NET中尝试不同的示例后,我也无法获取单元格值.我没有得到以下代码的结果,任何人都可以得到这个.我正在使用.net framework 2.0

string filePath = "F:/BulkTest.xlsx";
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
ExcelApp.Visible = true;
Microsoft.Office.Interop.Excel.Workbook wb = ExcelApp.Workbooks.Open(filePath, Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);

Microsoft.Office.Interop.Excel.Worksheet sh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets["Sheet1"];
Range excelRange = sh.UsedRange;

for (int i=2; i<= excelRange.Count + 1 ; i++)
{
    string values = sh.Cells[i,2].ToString();
}
Run Code Online (Sandbox Code Playgroud)

c# excel

2
推荐指数
1
解决办法
5万
查看次数

标签 统计

c# ×1

excel ×1