C# 文件导出 EXCEL
#region 读excel
//using (Stream stream = File.OpenRead(@"c:\Book1.xls"))
//{
// //内存中的excel文件
// HSSFWorkbook workBook = new HSSFWorkbook(stream);
// //读取sheet
// HSSFSheet sheet = workBook.GetSheetAt(0);
// //Console.WriteLine(sheet.GetRow(0).GetCell(0).NumericCellValue);
// StringBuilder sb = new StringBuilder();
// for (int i = 1; i <= sheet.LastRowNum; i++)
// {
// //行
// HSSFRow row = sheet.GetRow(i);
// //遍历列
// for (int j = 0; j < row.LastCellNum; j++)
// {
// HSSFCell cell = row.GetCell(j);
// //判断单元格的类型。分别用不通类型读取单元格的值
// if (cell == null)
// {
// sb.Append("");
// continue;
// }
// if (cell.CellType == HSSFCell.CELL_TYPE_STRING)
// {
// sb.Append(cell.StringCellValue);
// }
// else if(cell.CellType == HSSFCell.CELL_TYPE_NUMERIC)
// {
// sb.Append(cell.NumericCellValue);
// }
// }
// sb.Append("\r\n");
// }
// Console.WriteLine(sb.ToString());
//}
#endregion
#region 创建excel
////创建excel
////在内存中创建了一个空的excel文件
//HSSFWorkbook workBook = new HSSFWorkbook();
////在workBook中创建一个sheet
//HSSFSheet sheet = workBook.CreateSheet();
////sheet中创建行
//HSSFRow row = sheet.CreateRow(0);
////创建cell 并设置cell的类型
//HSSFCell cell = row.CreateCell(0,HSSFCell.CELL_TYPE_STRING);
//cell.SetCellValue("15028008001");
////
//cell = row.CreateCell(1, HSSFCell.CELL_TYPE_NUMERIC);
//cell.SetCellValue(456);
//using (Stream stream = File.OpenWrite("c:\\1111.xls"))
//{
// workBook.Write(stream);
//}
//Console.WriteLine("chenggong ");
#endregion