/// <summary> /// 获取错误消息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="output"></param> /// <returns></returns> public static string GetErrorMessage <T>(this ExcelImportRowInfo <T> output) where T : class, new() { if (output?.Errors == null) { return(null); } return($"行编号【{output.RowNum}】存在错误:{string.Join(",", output.Errors.Select(a => a.ErrorMessage))};\r\n"); }
/// <summary> /// 检查错误并抛出异常 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="output"></param> /// <returns></returns> public static void CheckError <T>(this ExcelImportRowInfo <T> output) where T : class, new() { if (output == null) { return; } if (!output.IsValid) { throw new Exception($"{output.GetErrorMessage()}"); } }
/// <summary> /// 获取数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="output"></param> /// <param name="isValid">是否有效数据,null则全部</param> /// <returns></returns> public static T GetData <T>(this ExcelImportRowInfo <T> output, bool?isValid = true) where T : class, new() { if (output == null) { return(null); } if (isValid == null || output.IsValid == isValid) { return(output.Row); } return(null); }