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 @ 2013-07-12 18:22  瓜王  阅读(14012)  评论(7编辑  收藏  举报