NPOI读取excel功能,兼容xls和xlsx

样例:

            IWorkbook workbook;
            string fileExt = Path.GetExtension(filePath);
            try
            {
                using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    if (fileExt == ".xls")
                    {
                        workbook = new HSSFWorkbook(file);
                    }
                    else if (fileExt == ".xlsx")
                    {
                        workbook = new XSSFWorkbook(file);
                    }
                    else
                    {
                        return null;
                    }
                }
            }
原文地址:https://www.cnblogs.com/Benjamin/p/3186829.html