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;
                    }
                }
            }

  

posted on 2015-08-13 11:13  VincentZhu  阅读(962)  评论(0编辑  收藏  举报