123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using NPOI.XSSF.UserModel;
- using System.IO;
- namespace YBEE.EQM.Core;
- /// <summary>
- /// Excel操作工具
- /// </summary>
- public static class ExcelUtil
- {
- /// <summary>
- /// 获取 Workbook 实例
- /// </summary>
- /// <param name="filePath"></param>
- /// <param name="fileStream"></param>
- /// <returns></returns>
- public static IWorkbook GetWorkbook(string filePath, FileStream fileStream)
- {
- string fileExt = Path.GetExtension(filePath).ToLower();
- if (fileExt == ".xls")
- {
- return new HSSFWorkbook(fileStream);
- }
- else
- {
- return new XSSFWorkbook(fileStream);
- }
- }
- /// <summary>
- /// 创建 Workbook
- /// </summary>
- /// <param name="filePath"></param>
- /// <returns></returns>
- public static IWorkbook GetWorkbook(string filePath)
- {
- string fileExt = Path.GetExtension(filePath).ToLower();
- if (fileExt == ".xls")
- {
- return new HSSFWorkbook();
- }
- else
- {
- return new XSSFWorkbook();
- }
- }
- }
|