using MiniExcelLibs;
using SharpCompress.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.NET.Core;
///
///
///
///
public class InputExcelUtil where T : class, new()
{
private static List extName = new List() { ".xls", ".xlsx" };
///
/// 导入Excel内容读取到List中
///
///
///
///
public static List InputExcel(IFormFile file, string sheetName = null)
{
//获取文件后缀名
string type = Path.GetExtension(file.FileName);
//判断是否导入合法文件
if (!extName.Contains(type))
{
return null;
}
// List list = new List();
//转成为文件流
//MemoryStream ms = new MemoryStream();
//file.CopyTo(ms);
//ms.Seek(0, SeekOrigin.Begin);
////实例化T数组
////获取数据
// list = InputExcel(ms, sheetName);
//根据指定路径读取文件
var fs = file.OpenReadStream();
List list = fs.Query(sheetName: sheetName).ToList();
// list = ms.Query().ToList();
return list;
}
}