public static void read_excel( )
{
using(FileStream stream = new FileStream(@"c:\20120823.xls",FileMode.OpenOrCreate,FileAcess.ReadWrite))
{
HSSFWorkbook wb = new HSSFWorkbook(stream);
HSSFSheet sheet = wb.GetSheetAt(0);
HSSRow row = sheet.GetRow(0);
for(int i=0;i<row.LastCellNum;i++)
{
HSSFCell cell = row.GetCell(i);
switch(cell.CellType) //根据单元格的数据格式提取数据
{
case 1: Console.WriteLine(cell.StringCellValue);
break;
case 0: Console.WriteLine(cell.NumericCellValue);
break;
case 4: Console.WriteLine(cell.BooleanCellValue);
break;
case 5: Console.WriteLine(cell.ErrorCellValue);
break;
default:
Console.WriteLine("没有值");
break;
}
}
}
} |