using OfficeOpenXml; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace friction { public class Report { public string FilePath { set; get; } public string MaterialSpring { set; get; } public string MaterialTable { set; get; } public DataTable AnalysisData { set; get; } public DataTable CompatibilityData { set; get; } public List CompatibilityColumns { set; get; } public List CompatibilityRows { set; get; } public Bitmap RadarChart { set; get; } public Bitmap TrendChartByHumidity { set; get; } public Bitmap TrendChartByTemperature { set; get; } public Bitmap TrendChartByForce { set; get; } public Bitmap TrendChartByVelocity { set; get; } public void Export() { using (ExcelPackage package = new ExcelPackage()) { if (package.Workbook.Worksheets.Count < 1) package.Workbook.Worksheets.Add("Report"); ExcelWorksheet Sheet = package.Workbook.Worksheets[1]; int iRow = 2; int iCol = 2; Sheet.Cells[iRow, iCol].Value = "Material Spring: " + MaterialSpring; Sheet.Cells[iRow, iCol].Style.Font.Bold = true; // analysis table iRow += 1; foreach(DataColumn column in AnalysisData.Columns) { Sheet.Cells[iRow, iCol].Value = column.ColumnName; iCol++; } iRow++; iCol = 2; int iTableRowStart = iRow-1; int iTableColStart = iCol; double dValue; int iNoOfTest = 0; int iAvgRPNColumn = 1; foreach(DataRow row in AnalysisData.Rows) { int.TryParse(row["No. of Tests"].ToString(), out iNoOfTest); iCol = 2; for (int i = 0; i < AnalysisData.Columns.Count; i++) { if(double.TryParse(row[i].ToString(), out dValue) == true) { Sheet.Cells[iRow, iCol].Value = dValue; if(AnalysisData.Columns[i].ColumnName == "No. of Tests") { } else if (AnalysisData.Columns[i].ColumnName == "Average RPN") { Sheet.Cells[iRow, iCol].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; var Risk = Config.ANALYSIS.GetRisk((float)dValue); switch (Risk) { case Config.ANALYSIS.RISK.NO: Sheet.Cells[iRow, iCol].Style.Fill.BackgroundColor.SetColor(Theme.Green); break; case Config.ANALYSIS.RISK.POTENTIAL: Sheet.Cells[iRow, iCol].Style.Fill.BackgroundColor.SetColor(Theme.Yellow); break; case Config.ANALYSIS.RISK.HIGH: Sheet.Cells[iRow, iCol].Style.Fill.BackgroundColor.SetColor(Theme.Red); break; } iAvgRPNColumn = iCol; } else { Sheet.Cells[iRow, iCol].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; var Dependancy = Config.ANALYSIS.GetDependancy((float)dValue, iNoOfTest); switch (Dependancy) { case Config.ANALYSIS.DEPENDANCY.NO: Sheet.Cells[iRow, iCol].Style.Fill.BackgroundColor.SetColor(Theme.Green); break; case Config.ANALYSIS.DEPENDANCY.POTENTIAL: Sheet.Cells[iRow, iCol].Style.Fill.BackgroundColor.SetColor(Theme.Yellow); break; case Config.ANALYSIS.DEPENDANCY.HIGH: Sheet.Cells[iRow, iCol].Style.Fill.BackgroundColor.SetColor(Theme.Red); break; case Config.ANALYSIS.DEPENDANCY.NOT_ENNOUGH_DATA: Sheet.Cells[iRow, iCol].Style.Fill.BackgroundColor.SetColor(Theme.Gray); Sheet.Cells[iRow, iAvgRPNColumn].Style.Fill.BackgroundColor.SetColor(Theme.Gray); break; } } } else { Sheet.Cells[iRow, iCol].Value = row[i].ToString(); } iCol++; } iRow++; } Sheet.Cells[iTableRowStart, iTableColStart, iTableRowStart, iCol-1].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin); Sheet.Cells[iTableRowStart, iTableColStart, iRow-1, iTableColStart].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin); Sheet.Cells[iTableRowStart, iTableColStart, iRow-1, iCol-1].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thick); Sheet.Cells[iTableRowStart, iTableColStart, iRow - 1, iCol - 1].AutoFitColumns(); // compatibility table iRow += 1; iCol = 3; foreach (string column in CompatibilityColumns) { Sheet.Cells[iRow, iCol].Value = column; iCol++; } iRow++; iCol = 2; iTableRowStart = iRow - 1; iTableColStart = iCol; dValue = 0; iNoOfTest = 0; iAvgRPNColumn = 1; for(int j=0; j