【发布时间】:2017-09-28 13:30:51
【问题描述】:
创建一个应用程序来读取 excel (.xls) 文件。 我能够读取该文件,但它只显示数据计数。 但无法从文件中获取数据。
Microsoft.Office.Interop.Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Landingfolder\file.xls");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
//new line
if (j == 1)
Console.Write("\r\n");
//write the value to the console
if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
Console.Write(xlRange.Cells[i, j].Value2.ToString() + "\t");
Console.ReadLine();
}
}
请告诉我正确的流程。
【问题讨论】:
-
你想用excel数据做什么,是指如何显示或其他,请提供预期结果示例
-
我想将所有数据存储在一个列表中。例如,excel 表中有四列。 id、empName、salary、empDepartment
标签: c#-4.0