private FileResult ExportPerformanceReport(vmAdmin_PerformanceReport report, vmAdmin_PerformanceFilter filter, string title, string filename) { int rowNumber = 0; NPOI.SS.UserModel.IRow row; //Create new Excel workbook var workbook = new HSSFWorkbook(); //Create new Excel sheet var sheet = CreateSheet(workbook); var allStyles = ReportUtilities.CreateStyles(workbook); ReportUtilities.ExportReportHeader(title, sheet, allStyles, ref rowNumber); ExportReportSubheader(sheet, filter, allStyles, ref rowNumber); ExportReportValues(report, sheet, allStyles, ref rowNumber); ExportReportTshirts(report, sheet, allStyles, ref rowNumber); ExportReportFees(report, sheet, allStyles, ref rowNumber); ExportReportCharges(report, sheet,allStyles, ref rowNumber); //Write the workbook to a memory stream var output = new MemoryStream(); workbook.Write(output); //Return the result to the end user return File(output.ToArray(), //The binary data of the XLS file "application/vnd.ms-excel", //MIME type of Excel files filename); //Suggested file name in the "Save as" dialog which will be displayed to the end user }
private static void ExportReportValues(vmAdmin_PerformanceReport report, NPOI.SS.UserModel.ISheet sheet, StyleContainer allStyles, ref int rowNumber) { var row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Event Revenue", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 1, report.TotalRevenue, allStyles.Currency); ReportUtilities.CreateCell(row, 2, "Available Spots", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 3, report.TotalSpots, allStyles.RightAligned); ReportUtilities.CreateCell(row, 4, "Fee Total", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 5, report.FeeValue, allStyles.Currency); ReportUtilities.CreateCell(row, 6, "Charge Total", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 7, report.ChargeValue, allStyles.Currency); row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Days count", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 1, report.DayCount, allStyles.RightAligned); ReportUtilities.CreateCell(row, 2, "Active Registrations", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 3, report.SpotsTaken, allStyles.RightAligned); ReportUtilities.CreateCell(row, 4, "Discount value", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 5, report.DiscountValue, allStyles.Currency); ReportUtilities.CreateCell(row, 6, "Local Tax", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 7, report.ChargeLocalTaxValue, allStyles.Currency); row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Event count", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 1, report.EventCount, allStyles.RightAligned); ReportUtilities.CreateCell(row, 2, "Spots Available", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 3, report.SpotsLeft, allStyles.RightAligned); ReportUtilities.CreateCell(row, 4, "Local Tax", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 5, report.LocalTaxValue, allStyles.Currency); ReportUtilities.CreateCell(row, 6, "State Tax", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 7, report.ChargeStateTaxValue, allStyles.Currency); row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Revenue Per Day", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 1, report.RevenuePerDay, allStyles.Currency); ReportUtilities.CreateCell(row, 2, "Registrations Per Day", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 3, report.RegPerDay, allStyles.RightAligned); ReportUtilities.CreateCell(row, 4, "State Tax", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 5, report.StateTaxValue, allStyles.Currency); ReportUtilities.CreateCell(row, 6, "Total Revenue", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 7, report.ChargeActualRevenue, allStyles.Currency); row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Revenue Per Event", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 1, report.RevenuePerEvent, allStyles.Currency); row.CreateCell(2); row.CreateCell(3); ReportUtilities.CreateCell(row, 4, "Total Revenue", allStyles.LeftAligned); ReportUtilities.CreateCell(row, 5, report.FeeActualRevenue, allStyles.Currency); row.CreateCell(6); row.CreateCell(7); row = sheet.CreateRow(rowNumber++); }
private static void ExportReportFees(vmAdmin_PerformanceReport report, NPOI.SS.UserModel.ISheet sheet, StyleContainer allStyles, ref int rowNumber) { if (report.FeeReport.Count > 0) { var row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Event Fees", allStyles.Header2Style); foreach (var feeType in report.FeeReport.GroupBy(x => x.FeeType).Select(x => x.Key)) { row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, feeType.ToString(), allStyles.Header3Style); row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Cost", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 1, "Use Count", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 2, "Cost Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 3, "Discount Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 4, "Local Tax Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 5, "State Tax Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 6, "Actual Total", allStyles.TitleStyle); foreach (var fee in report.FeeReport.Where(x => x.FeeType == feeType).OrderBy(x => x.Cost)) { row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, fee.Cost, allStyles.Currency); ReportUtilities.CreateCell(row, 1, fee.UseCount, allStyles.RightAligned); ReportUtilities.CreateCell(row, 2, fee.CostTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 3, fee.DiscountTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 4, fee.LocalTaxTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 5, fee.StateTaxTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 6, fee.ActualTotal, allStyles.Currency); } row = sheet.CreateRow(rowNumber++); } } }
private static void ExportReportTshirts(vmAdmin_PerformanceReport report, NPOI.SS.UserModel.ISheet sheet, StyleContainer allStyles, ref int rowNumber) { if (report.TShirtSizes != null && report.TShirtSizes.Count > 0) { var row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "T-Shirts", allStyles.Header3Style); foreach (var size in report.TShirtSizes) { row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, size.Keys.ElementAt(0).ToString(), allStyles.LeftAligned); ReportUtilities.CreateCell(row, 1, size.Values.ElementAt(0), allStyles.RightAligned); } row = sheet.CreateRow(rowNumber++); } }
private static void ExportReportCharges(vmAdmin_PerformanceReport report, NPOI.SS.UserModel.ISheet sheet, StyleContainer allStyles, ref int rowNumber) { if (report.ChargeReport.Count > 0) { var row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Event Charges", allStyles.Header2Style); row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, "Name", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 1, "Cost Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 2, "Discount Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 3, "Local Tax Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 4, "State Tax Total", allStyles.TitleStyle); ReportUtilities.CreateCell(row, 5, "Actual Total", allStyles.TitleStyle); foreach (var charge in report.ChargeReport.OrderBy(x => x.Name)) { row = sheet.CreateRow(rowNumber++); ReportUtilities.CreateCell(row, 0, charge.Name, allStyles.LeftAligned); ReportUtilities.CreateCell(row, 1, charge.CostTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 2, charge.DiscountTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 3, charge.LocalTaxTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 4, charge.StateTaxTotal, allStyles.Currency); ReportUtilities.CreateCell(row, 5, charge.ActualTotal, allStyles.Currency); } } }