Excel文档流转换成DataTable
第一行必须为标题行
excelFileStream Excel文档流
sheetIndex 表索引号,如第一个表为0
headerRowIndex 标题行索引号,如第一行为0
public static DataTable RenderFromExcel(Stream excelFileStream, int sheetIndex)
{
return RenderFromExcel(excelFileStream, sheetIndex, 0);
}
Sheet=表格
headerRowIndex=标题行索引号,如第一行为0
public static DataTable RenderFromExcel(Stream excelFileStream, int sheetIndex, int headerRowIndex)
{
DataTable table = null;
using (excelFileStream)
{
using (IWorkbook workbook = new HSSFWorkbook(excelFileStream))
{
using (ISheet sheet = workbook.GetSheetAt(sheetIndex))
{
table = RenderFromExcel(sheet, headerRowIndex);
}
}
}
return table;
}