public static (bool success, string errMsg) CheckConfig(csDBToExcel eo) { if (eo == null) { return(false, "配置错误"); } if (eo.DBType != DB.ORACLE && eo.DBType != DB.SQLSERVER) { return(false, "数据库类型错误"); } if (string.IsNullOrWhiteSpace(eo.ConnStr)) { return(false, "连接字符串错误"); } ; if (eo.Sheets == null || eo.Sheets.Count == 0) { return(false, "Sheet节点存在错误"); } foreach (var sheet in eo.Sheets) { if (string.IsNullOrWhiteSpace(sheet.SheetName)) { return(false, "SheetName不能为空"); } if (sheet.Fileds == null || sheet.Fileds.Count == 0) { return(false, "Filed节点存在错误"); } foreach (var filed in sheet.Fileds) { if (string.IsNullOrEmpty(filed.FldName)) { return(false, "FldName不能为空"); } if (string.IsNullOrEmpty(filed.RowName)) { return(false, "配置错误"); } } } return(true, null); }
private static (bool success, string errMsg) OracleToExcel(csDBToExcel eo) { var errMsg = string.Empty; try { var outpath = System.AppDomain.CurrentDomain.BaseDirectory + "outpath"; if (!Directory.Exists(outpath)) { Directory.CreateDirectory(outpath); } OracleHelper.connStr = eo.ConnStr; List <Sheet> sheets = new List <Sheet>(); List <DataTable> dts = new List <DataTable>(); eo.Sheets.ForEach(e => { try { sheets.Add(e); dts.Add(OracleHelper.ExecuteDataTable(e.Sql)); } catch { errMsg += $"Sheet {e.SheetName} 查询异常\n"; logger.Error("异常描述:\t" + errMsg); } }); if (string.IsNullOrEmpty(errMsg)) { ToExcel(sheets, dts, outpath + $"\\{DateTime.Now:D}.xlsx"); } } catch (Exception ex) { logger.Error("异常描述:\t" + ex.Message); logger.Error("异常方法:\t" + ex.TargetSite); logger.Error("异常堆栈:\t" + ex.StackTrace); errMsg += "生成Excel异常\n"; } return(string.IsNullOrEmpty(errMsg), errMsg); }
public static (bool success, string errMsg) ToExcel(csDBToExcel eo) { return(eo.DBType == DB.ORACLE ? OracleToExcel(eo) : SqlServerToExcel(eo)); }