public void build_excel() { IPropertyContainer[] rows = { new MutablePropertyContainer() .WithValue(Sheet1Meta.Name, "Alex") .WithValue(Sheet1Meta.Age, 42) .WithValue(Sheet1Meta.Date, DateTime.Today.ToLocalDateTime().Date), new MutablePropertyContainer() .WithValue(Sheet1Meta.Name, "Helen") .WithValue(Sheet1Meta.Age, 17), }; var documentMetadata = new ExcelDocumentMetadata() .WithValue(ExcelMetadata.DataType, CellValues.SharedString) .WithValue(ExcelMetadata.FreezeTopRow, true) .WithValue(ExcelMetadata.ColumnWidth, 14) as ExcelDocumentMetadata; var transposed = new ExcelSheetMetadata() .WithValue(ExcelMetadata.Transpose, true) as ExcelSheetMetadata; ExcelReportBuilder .Create("build_excel.xlsx", documentMetadata) .AddReportSheet(new Sheet1Report("Sheet1"), rows) .AddReportSheet(new Sheet1Report("Sheet2").SetMetadata(transposed), rows) .SaveAndClose(); }
public byte[] GetRunExcelReport(ExcelReportRunModel run) { using (var reportBuilder = new ExcelReportBuilder(new ExcelStyleApplier())) { reportBuilder.PredefineStyles(GamePlanReportStyles.RunReportPredefineStyles); foreach (var scenario in run.Scenarios) { reportBuilder.Sheet(scenario.Name, sb => { var columnsCount = scenario.MaxColumnsCount; SetColumnsWidthForRunReport(sb, columnsCount); WriteGrid(sb, scenario.ScenarioDetails); sb.Skip(); WriteGrid(sb, scenario.SalesAreaPassPriorities); sb.Skip(); WriteGrid(sb, scenario.General); sb.Skip(); WriteGrid(sb, scenario.Weighting); sb.Skip(); WriteGrid(sb, scenario.Tolerance); sb.Skip(); WriteGrid(sb, scenario.Rules); sb.Skip(); WriteGrid(sb, scenario.ProgrammeRepetitions); sb.Skip(); WriteGrid(sb, scenario.MinRatingPoints); sb.Skip(); WriteGrid(sb, scenario.BreakExclusions); sb.Skip(); WriteGrid(sb, scenario.SlottingLimits); }); } return(reportBuilder.Save()); } }
public void CanGetColumnName(string source, string tableName, string colName) { var(table, column) = ExcelReportBuilder.GetColumnName(source); Assert.AreEqual(tableName, table); Assert.AreEqual(colName, column); }
public byte[] GetSmoothFailuresExcelReport(ExcelReportSmoothFailuresModel reportModel) { using (var builder = new ExcelReportBuilder(new ExcelStyleApplier())) { return(builder .PredefineStyles(GamePlanReportStyles.SmoothFailuresReportPredefineStyles) .Sheet("Smooth Failures", sb => GetSmoothFailures(sb, reportModel.SmoothFailures)) .Sheet("Report Info", sb => GetReportInfo(sb, "Smooth Failures", reportModel.Run, reportModel.ReportDate)) .Save()); } }
public void builder_test_report() { Report report; ReportDirector director = new ReportDirector(); #region Excel { ExcelReportBuilder builder = new ExcelReportBuilder(); report = director.CreateReport(builder); Assert.That(report.ReportType == ReportType.Excel); Assert.That(report.ReportHeader == HeaderType.ExcelHeader); Assert.That(report.ReportContent == ContentType.ExcelContent); Assert.That(report.ReportFooter == FooterType.ExcelFooter); } #endregion #region PDF { PDFReportBuilder builder = new PDFReportBuilder(); report = director.CreateReport(builder); Assert.That(report.ReportType == ReportType.PDF); Assert.That(report.ReportHeader == HeaderType.PDFHeader); Assert.That(report.ReportContent == ContentType.PDFContent); Assert.That(report.ReportFooter == FooterType.PDFFooter); } #endregion #region Word { WordReportBuilder builder = new WordReportBuilder(); report = director.CreateReport(builder); Assert.That(report.ReportType == ReportType.Word); Assert.That(report.ReportHeader == HeaderType.WordHeader); Assert.That(report.ReportContent == ContentType.WordContent); Assert.That(report.ReportFooter == FooterType.WordFooter); } #endregion #region Powerpoint { PowerPointReportBuilder builder = new PowerPointReportBuilder(); report = director.CreateReport(builder); Assert.That(report.ReportType == ReportType.PowerPoint); Assert.That(report.ReportHeader == HeaderType.PowerPointHeader); Assert.That(report.ReportContent == ContentType.PowerPointContent); Assert.That(report.ReportFooter == FooterType.PowerPointFooter); } #endregion }
public Stream ReportToExcel(Entity[] entities, IReportBuilderSettings?reportBuilderSettings) { var reportRows = entities.Select(entity => EntityMeta.Instance.ToContainer(entity)); var excelStream = new MemoryStream(); ExcelReportBuilder.Create(excelStream, settings: reportBuilderSettings) .AddReportSheet(new EntityReport("Entities"), reportRows) .SaveAndClose(); return(excelStream); }
public void build_excel_with_nulls() { IPropertyContainer[] rows = { new MutablePropertyContainer(), }; var documentMetadata = new ExcelDocumentMetadata() .WithValue(ExcelMetadata.DataType, CellValues.SharedString) .WithValue(ExcelMetadata.FreezeTopRow, true) .WithValue(ExcelMetadata.ColumnWidth, 14); ExcelReportBuilder .Create("build_excel.xlsx", documentMetadata) .AddReportSheet(new Sheet1Report("Sheet1"), rows) .SaveAndClose(); }
public byte[] GetReportAsByteArray(string sheetName, IEnumerable <CampaignReportModel> data, IEnumerable <ColumnStatusModel> columnStatusList, IReportColumnFormatter reportColumnHelper) { var confBuilder = CreateExcelConfigurationBuilder(); using (var reportBuilder = new ExcelReportBuilder(new ExcelStyleApplier()) .PredefineStyles(GamePlanReportStyles.AllPredefineStyles)) { var orderedData = reportColumnHelper.ApplySettings(data, columnStatusList, confBuilder); reportBuilder.Sheet(sheetName, sheetBuilder => { sheetBuilder.DataContent(orderedData, confBuilder.BuildConfiguration()); reportColumnHelper.AutoFitAll(sheetBuilder); }); return(reportBuilder.Save()); } }
public IActionResult Index(ReportModel model) { try { // Load the XML _logger.LogDebug("Loading XML"); var dataLoader = new XmlDataLoader(_configuration, _logger); var xml = dataLoader.LoadData(Request.Form.Files[1]); // Load the HTML and populate with the XML data (single pass) _logger.LogDebug("Converting Excel to HTML"); var builder = new ExcelReportBuilder(_configuration, _logger); var html = builder.GenerateReport(Request.Form.Files[0], xml); _logger.LogDebug("Outputting HTML as Content"); // Output the content as HTML return(Content(html, "text/html; charset=UTF-8")); } catch (Exception ex) { _logger.LogError($"{ex.Message}\r\n{ex.StackTrace}"); return(Content($"{ex.Message}\r\n{ex.StackTrace}")); } }
/// <summary> /// Execute Report /// </summary> /// <param name="pstrCCNID">CCN</param> /// <param name="pstrYear">Year</param> /// <param name="pstrMonth">Month</param> /// <param name="pstrProLineID">Production Line</param> /// <param name="pstrWorkCenterID">Work Center</param> /// <returns></returns> public DataTable ExecuteReport(string pstrCCNID, string pstrYear, string pstrMonth, string pstrProLineID, string pstrWorkCenterID) { const string WORKING_DATE = "WorkingDate"; const string BEGIN_DATE = "BeginDate"; const string END_DATE = "EndDate"; const double FIELD_WIDTH = 585; const string FLD = "fld"; int intCCNID = 0; int intYear = 0; int intMonth = 0; int intProductionLineID = 0; int intWorkCenterID = 0; try { intCCNID = int.Parse(pstrCCNID); } catch {} try { intYear = int.Parse(pstrYear); } catch {} try { intMonth = int.Parse(pstrMonth); } catch {} try { intProductionLineID = int.Parse(pstrProLineID); } catch {} try { intWorkCenterID = int.Parse(pstrWorkCenterID); } catch {} DateTime dtmStartDate = new DateTime(intYear, intMonth, 1); DateTime dtmEndDate = dtmStartDate.AddMonths(1).AddDays(-1); string strExpression = string.Empty; Hashtable arrStandardCapacity = new Hashtable(); Hashtable arrActual = new Hashtable(); Hashtable arrRemain = new Hashtable(); Hashtable arrEffective = new Hashtable(); C1Report rptReport = new C1Report(); string strMonth = dtmStartDate.ToString("MMM"); // planning offset DataTable dtbPlanningOffset = GetPlanningOffset(pstrCCNID); // get all cycles in selected year DataTable dtbCycles = GetCycles(pstrCCNID); // refine cycles as of date based on production line dtbCycles = RefineCycle(pstrProLineID, dtbPlanningOffset, dtbCycles); // all planning period ArrayList arrPlanningPeriod = GetPlanningPeriod(pstrCCNID); StringBuilder sbCycleIDs; DataTable dtbCyclesCurrentMonth = ArrangeCycles(dtmStartDate, dtmEndDate, dtbCycles, arrPlanningPeriod, out sbCycleIDs); DataTable dtbStandard = GetStandardCapacity(intWorkCenterID, intCCNID, intProductionLineID); DataTable dtbTRC = GetTotalRequiredCapacity(intProductionLineID, sbCycleIDs.ToString(), dtmStartDate, dtmEndDate); DataTable dtbValidWorkDay = GetWorkingDateFromWCCapacity(intProductionLineID); decimal decTotalStandard = 0; decimal decTotalActual = 0; decimal decTotalRemain = 0; decimal decTotalEffective = 0; DataRow[] drowStandard = null; for (int i = dtmStartDate.Day; i <= dtmEndDate.Day; i++) { DateTime dtmDate = new DateTime(dtmStartDate.Year, dtmStartDate.Month, i); string strColName = "D" + i.ToString("00"); decimal decSC = 0; decimal decActual = 0; decimal decRemain = 0; decimal decEffective = 0; strExpression = BEGIN_DATE + "<='" + dtmDate.ToString("G") + "' AND " + END_DATE + ">='" + dtmDate.ToString("G") + "'"; DataRow[] drowValidWorkDay = dtbValidWorkDay.Select(strExpression); if (drowValidWorkDay.Length == 0) { arrStandardCapacity.Add(strColName, decSC); arrActual.Add(strColName, decActual); arrRemain.Add(strColName, decRemain); arrEffective.Add(strColName, decimal.Round(decEffective, 2)); continue; } string strCycleID = GetCycleOfDate(dtmDate, dtbCyclesCurrentMonth); string strFilter = "WorkingDate = '" + dtmDate.ToString() + "'" + " AND DCOptionMasterID = '" + strCycleID + "'"; #region Standard Capacity drowStandard = dtbStandard.Select(strExpression); foreach (DataRow drowData in drowStandard) { try { decSC += (decimal)drowData["Capacity"]; } catch { } } arrStandardCapacity.Add(strColName, decimal.Round(decSC, 0)); decTotalStandard += decSC; #endregion #region Total Required Capacity DataRow[] drowTotalRequired = dtbTRC.Select(strFilter); foreach (DataRow drowData in drowTotalRequired) { try { decActual += (decimal)drowData["TotalSecond"]; } catch {} } arrActual.Add(strColName, decimal.Round(decActual, 0)); decTotalActual += decActual; #endregion #region Effective = Required Cap / Standard Cap try { decEffective = decActual / decSC; } catch {} arrEffective.Add(strColName, decimal.Round(decEffective, 2)); #endregion #region Remain Capacity // remain capacity decRemain = decSC - decActual; arrRemain.Add(strColName, decimal.Round(decRemain, 0)); #endregion } arrStandardCapacity.Add("Total", decimal.Round(decTotalStandard, 0)); arrActual.Add("Total", decimal.Round(decTotalActual, 0)); decTotalRemain = decTotalStandard - decTotalActual; arrRemain.Add("Total", decimal.Round(decTotalRemain, 0)); try { decTotalEffective = decTotalActual / decTotalStandard; } catch {} arrEffective.Add("Total", decimal.Round(decTotalEffective, 2)); /// column Name in the dtbResult const string STANDARD_CAPACITY = "StandardCapacity"; const string TOTAL_REQUIRED_CAPACITY = "TotalRequiredCapacity"; const string REMAIN_CAPACITY = "RemainCapacity"; const string EFFECTIVE = "Effective"; DataTable dtbResult = new DataTable(); dtbResult.Columns.Add(new DataColumn("RowType", typeof(string))); #region Report layout mLayoutFile = "CASReport.xml"; string[] arrstrReportInDefinitionFile = rptReport.GetReportInfo(mReportFolder + "\\" + mLayoutFile); rptReport.Load(mReportFolder + "\\" + mLayoutFile, arrstrReportInDefinitionFile[0]); arrstrReportInDefinitionFile = null; rptReport.Layout.PaperSize = PaperKind.A3; #endregion for (int i = dtmStartDate.Day; i <= dtmEndDate.Day; i++) { string strColumnName = "D" + i.ToString("00"); dtbResult.Columns.Add(new DataColumn(strColumnName, typeof(decimal))); #region Report layout DateTime dtmDay = new DateTime(intYear, intMonth, i); string strDate = "fldD" + i.ToString("00"); string strDay = "fldDay" + i.ToString("00"); try { rptReport.Fields[strDate].Text = i + "-" + strMonth; } catch { } try { rptReport.Fields[strDay].Text = dtmDay.DayOfWeek.ToString().Substring(0, 3); } catch { } DataRow[] drowValidWorkDay = dtbValidWorkDay.Select("BeginDate <= '" + dtmDay.ToString("G") + "'" + " AND EndDate >='" + dtmDay.ToString("G") + "'"); if (drowValidWorkDay.Length == 0) { try { if (dtmDay.DayOfWeek == DayOfWeek.Saturday) { rptReport.Fields[strDate].ForeColor = Color.Blue; rptReport.Fields[strDate].BackColor = Color.Yellow; } else { rptReport.Fields[strDate].ForeColor = Color.Red; rptReport.Fields[strDate].BackColor = Color.Yellow; } } catch { } try { if (dtmDay.DayOfWeek == DayOfWeek.Saturday) { rptReport.Fields[strDay].ForeColor = Color.Blue; rptReport.Fields[strDay].BackColor = Color.Yellow; } else { rptReport.Fields[strDay].ForeColor = Color.Red; rptReport.Fields[strDay].BackColor = Color.Yellow; } } catch { } } #endregion } #region Layout the format based on days in month int intDaysInMonth = DateTime.DaysInMonth(dtmStartDate.Year, dtmStartDate.Month); if (intDaysInMonth < 31) { for (int i = intDaysInMonth + 1; i <= 31; i++) { #region field name string strDate = "fldD" + i.ToString("00"); string strDayOfWeek = "fldDay" + i.ToString("00"); string strDiv = "div" + i.ToString("00"); #endregion #region Report Header try { rptReport.Fields[strDate].Visible = false; } catch { } try { rptReport.Fields[strDayOfWeek].Visible = false; } catch { } try { rptReport.Fields[strDiv].Visible = false; } catch { } #endregion } try { #region Resize all line //double dWidth = rptReport.Fields["line1"].Width; for (int i = 1; i <= 7; i++) { rptReport.Fields["line" + i].Width = rptReport.Fields["line" + i].Width - (31 - intDaysInMonth) * FIELD_WIDTH; } #endregion double dWidthToChange = (31 - intDaysInMonth) * FIELD_WIDTH; #region Total columns rptReport.Fields["fldDTotal"].Left = rptReport.Fields["fldStandardCapacityD"].Left = rptReport.Fields["fldTotalRequiredCapacityD"].Left = rptReport.Fields["fldEffectiveD"].Left = rptReport.Fields["fldRemainCapacityD"].Left = rptReport.Fields["fldDTotal"].Left - dWidthToChange; rptReport.Fields["divTotal"].Left = rptReport.Fields["fldDTotal"].Left + FIELD_WIDTH; #endregion } catch (Exception ex) { throw ex; } } #endregion DataRow drowSC = dtbResult.NewRow(); drowSC["RowType"] = STANDARD_CAPACITY; DataRow drowTR = dtbResult.NewRow(); drowTR["RowType"] = TOTAL_REQUIRED_CAPACITY; DataRow drowRC = dtbResult.NewRow(); drowRC["RowType"] = REMAIN_CAPACITY; DataRow drowEff = dtbResult.NewRow(); drowEff["RowType"] = EFFECTIVE; for (int i = dtmStartDate.Day; i <= dtmEndDate.Day; i++) { string strColumnName = "D" + i.ToString("00"); drowSC[strColumnName] = arrStandardCapacity[strColumnName]; drowTR[strColumnName] = arrActual[strColumnName]; drowRC[strColumnName] = arrRemain[strColumnName]; drowEff[strColumnName] = arrEffective[strColumnName]; } dtbResult.Rows.Add(drowSC); dtbResult.Rows.Add(drowTR); dtbResult.Rows.Add(drowRC); dtbResult.Rows.Add(drowEff); #region RENDER REPORT const string REPORTFLD_CHART = "fldChart"; const string REPORTFLD_TOTALCHART = "fldTotalChart"; if (dtbResult.Rows.Count > 0) { #region BUILD CHART, save to image in clipboard, and then put in the report field fldChart Field fldChart = rptReport.Fields[REPORTFLD_CHART]; Field fldTotalChart = rptReport.Fields[REPORTFLD_TOTALCHART]; #region INIT string EXCEL_FILE = "CASReport.xls"; string strTemplateFilePath = mReportFolder + Path.DirectorySeparatorChar + EXCEL_FILE; string strDestinationFilePath = mReportFolder + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(EXCEL_FILE) + FormControlComponents.NowToUTCString() + ".XLS"; /// Copy layout excel report file to ExcelReport folder with a UTC datetime name File.Copy(strTemplateFilePath, strDestinationFilePath, true); ExcelReportBuilder objXLS = new ExcelReportBuilder(strDestinationFilePath); #endregion try { #region BUILD THE REPORT ON EXCEL FILE string[] arrExcelColumnHeading = new string[DateTime.DaysInMonth(intYear, intMonth)]; for (int i = 1; i <= intDaysInMonth; i++) { DateTime dtmDate = new DateTime(intYear, intMonth, i); string strColHeading = i + "-" + strMonth + "\n" + dtmDate.DayOfWeek.ToString().Substring(0, 3); arrExcelColumnHeading[i - 1] = strColHeading; } double[,] arrExcelStandard = new double[1, intDaysInMonth]; double[,] arrExcelActual = new double[1, intDaysInMonth]; for (int i = dtmStartDate.Day; i <= dtmEndDate.Day; i++) { string strSC = "fldStandardCapacityD" + i.ToString("00"); string strTR = "fldTotalRequiredCapacityD" + i.ToString("00"); string strRC = "fldRemainCapacityD" + i.ToString("00"); string strEff = "fldEffectiveD" + i.ToString("00"); string strColName = "D" + i.ToString("00"); rptReport.Fields[strSC].Text = arrStandardCapacity[strColName].ToString(); rptReport.Fields[strTR].Text = arrActual[strColName].ToString(); rptReport.Fields[strRC].Text = arrRemain[strColName].ToString(); rptReport.Fields[strEff].Text = arrEffective[strColName].ToString(); try { arrExcelStandard[0, i - 1] = Decimal.ToDouble((decimal)arrStandardCapacity[strColName]); } catch {} try { arrExcelActual[0, i - 1] = Decimal.ToDouble((decimal)arrActual[strColName]); } catch {} } // total field rptReport.Fields["fldStandardCapacityD"].Text = arrStandardCapacity["Total"].ToString(); rptReport.Fields["fldTotalRequiredCapacityD"].Text = arrActual["Total"].ToString(); rptReport.Fields["fldRemainCapacityD"].Text = arrRemain["Total"].ToString(); rptReport.Fields["fldEffectiveD"].Text = arrEffective["Total"].ToString(); switch (intDaysInMonth) { case 28: objXLS.GetRange("A1", "AB1").Value2 = arrExcelColumnHeading; objXLS.GetRange("A2", "AB2").Value2 = arrExcelStandard; objXLS.GetRange("A3", "AB3").Value2 = arrExcelActual; break; case 29: objXLS.GetRange("A1", "AC1").Value2 = arrExcelColumnHeading; objXLS.GetRange("A2", "AC2").Value2 = arrExcelStandard; objXLS.GetRange("A3", "AC3").Value2 = arrExcelActual; break; case 30: objXLS.GetRange("A1", "AD1").Value2 = arrExcelColumnHeading; objXLS.GetRange("A2", "AD2").Value2 = arrExcelStandard; objXLS.GetRange("A3", "AD3").Value2 = arrExcelActual; break; default: objXLS.GetRange("A1", "AE1").Value2 = arrExcelColumnHeading; objXLS.GetRange("A2", "AE2").Value2 = arrExcelStandard; objXLS.GetRange("A3", "AE3").Value2 = arrExcelActual; break; } ChartObject chart = objXLS.GetChart("DetailChart"); // SeriesCollection serieSC = (SeriesCollection) chart.Chart.SeriesCollection(0); chart.Chart.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap, XlPictureAppearance.xlScreen); Image image = (Image)Clipboard.GetDataObject().GetData(typeof(Bitmap)); fldChart.Visible = true; fldChart.Text = ""; fldChart.Picture = image; chart = objXLS.GetChart("Chart 12"); chart.Chart.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap, XlPictureAppearance.xlScreen); image = (Image)Clipboard.GetDataObject().GetData(typeof(Bitmap)); fldTotalChart.Visible = true; fldTotalChart.Text = ""; fldTotalChart.Picture = image; #endregion } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } finally { #region SAVE, CLOSE EXCEL FILE CONTAIN REPORT objXLS.CloseWorkbook(); objXLS.Dispose(); objXLS = null; #endregion } #endregion BUILD CHART } #region MODIFY THE REPORT LAYOUT #region PUSH PARAMETER VALUE const string REPORTFLD_PARAMETER_CCN = "fldParameterCCN"; const string REPORTFLD_PARAMETER_MONTH = "fldParameterMonth"; const string REPORTFLD_PARAMETER_YEAR = "fldParameterYear"; const string REPORTFLD_PARAMETER_PRODUCTIONLINE = "fldParameterProductionLine"; const string REPORTFLD_PARAMETER_WORKCENTER = "fldParameterWorkCenter"; string strCCN = GetCCNCode(intCCNID); rptReport.Fields[REPORTFLD_PARAMETER_CCN].Text = strCCN; rptReport.Fields[REPORTFLD_PARAMETER_MONTH].Text = pstrMonth; rptReport.Fields[REPORTFLD_PARAMETER_YEAR].Text = pstrYear; string strProductionLine = GetProCodeAndName(intProductionLineID); rptReport.Fields[REPORTFLD_PARAMETER_PRODUCTIONLINE].Text = strProductionLine; string strWorkCenter = GetWCCodeAndName(intWorkCenterID); rptReport.Fields[REPORTFLD_PARAMETER_WORKCENTER].Text = strWorkCenter; #endregion #endregion rptReport.DataSource.Recordset = dtbResult; rptReport.Render(); C1PrintPreviewDialog ppvViewer = new C1PrintPreviewDialog(); ppvViewer.FormTitle = "Compare Actual And Standard Capacity"; ppvViewer.ReportViewer.Document = rptReport.Document; ppvViewer.Show(); #endregion return(dtbResult); }