两个excel表格所用的组件不一样,一个是 XSSF,一个是HSSF,给你端程序参考一下吧。
public static void InitializeWorkbook(Stream stream)
{
string fileExt = Path.GetExtension(filename);
switch (fileExt)
{
case ".xls":
workbook = new HSSFWorkbook(stream);
break;
case ".xlsx":
workbook = new XSSFWorkbook(stream);
break;
default:
break;
}
}