protected override void RenderHeader(ReportTextFieldCollection textFields, RenderHintsCollection hints) { Html.AppendLine(ExcelHeaderHtml(textFields)); WrapHeadAndBody = true; base.RenderHeader(textFields, hints); Html.Replace("<hr />", "<br /><br />"); }
/// <summary> /// Renders the footer. /// </summary> /// <param name="globalTable">The global table.</param> /// <param name="textFields">The text fields.</param> /// <param name="renderHints">The render hints.</param> protected virtual void RenderFooter(PdfPTable globalTable, ReportTextFieldCollection textFields, RenderHintsCollection renderHints) { if (!string.IsNullOrEmpty(textFields.Footer)) { ReportStyle reportStyle = renderHints[FooterStyle] as ReportStyle ?? GetDefaultFooterStyle(); globalTable.AddCell(CreateTextCell(reportStyle, renderHints[FontFamily] as string, textFields.Footer)); } }
protected void AppendStyling(RenderHintsCollection hints) { Html.AppendLine(@"<style type='text/css'>"); Html.AppendLine(DefaultStyle); Html.AppendFormat("{0}", hints[HtmlStyle]); Html.AppendLine(InternalStyling()); Html.AppendLine("</style>"); }
private static string GetRowDataFormatted(ReportRow row, RowField field, RenderHintsCollection hints) { bool encloseInQuotes = hints[EncloseInQuotes] as bool? ?? true; if (encloseInQuotes) { return(string.Format("\"{0}\"", row.GetFormattedValue(field))); } return(row.GetFormattedValue(field)); }
protected void AppendStyling(RenderHintsCollection hints) { Html.AppendLine(@"<meta http-equiv=""content-type"" content=""text/html;charset=utf-8"" />"); Html.AppendLine(@"<style type='text/css'>"); // Add the default styles Html.AppendLine(DefaultStyle); // Add any custom CSS passed into RenderHints Html.AppendFormat("{0}", hints[HtmlStyle]); // Add any internal styles, such as the ExcelReportWriter CSS Html.AppendLine(InternalStyling()); Html.AppendLine("</style>"); }
protected virtual void RenderRow(ReportRow row, RenderHintsCollection hints) { Html.AppendLine("<tr>"); foreach (var field in row.Fields) { if (row.RowType == ReportRowType.HeaderRow) { Html.AppendFormat("<th class='headerCell' style='{1}'>{0}</th>", field.HeaderText, GetCellStyle(row, field)); } else if (row.RowType == ReportRowType.DataRow) { if (hints.BooleanCheckboxes) { if (field.DataType == typeof(bool) || field.DataType == typeof(bool?)) { string checkbox = "<input type='checkbox' disabled='disabled'"; if (GetBooleanValue(row[field.Name])) { checkbox += " checked='checked'"; } checkbox += " />"; row[field] = checkbox; } } var formattedValue = row.GetFormattedValue(field); var url = row.GetUrlString(field); if (url != null) { formattedValue = string.Format("<a href='{1}'>{0}</a>", formattedValue, url); } Html.AppendFormat("<td style='{1}'>{0}</td>", formattedValue, GetCellStyle(row, field)); } else if (row.RowType == ReportRowType.FooterRow) { Html.AppendFormat("<td class='footerCell' style='{1}'>{0}</td>", row.GetFormattedValue(field), GetCellStyle(row, field)); } } Html.AppendLine("</tr>"); }
protected virtual void RenderFooter(ReportTextFieldCollection textFields, RenderHintsCollection hints) { Html.AppendLine("</table>"); var footerStyle = new ReportStyle { Italic = true }; Html.AppendFormat("<p style='{1}'>{0}</p>", textFields.Footer, footerStyle.ToCss()); Html.AppendLine("</div>"); if (WrapHeadAndBody) { Html.AppendLine("</body>"); Html.AppendLine("</html>"); } }
protected virtual void BuildReportHtml(ReportTextFieldCollection textFields, RenderHintsCollection hints, ReportRowCollection rows) { RenderHeader(textFields, hints); bool isFirstDataRow = true; foreach (ReportRow row in rows) { if (row.RowType == ReportRowType.HeaderRow) { Html.AppendLine("<thead>"); } else if (row.RowType == ReportRowType.FooterRow) { Html.AppendLine("<tfoot>"); } else if (row.RowType == ReportRowType.DataRow && isFirstDataRow) { Html.AppendLine("<tbody>"); isFirstDataRow = false; } RenderRow(row, hints); if (row.RowType == ReportRowType.HeaderRow) { Html.AppendLine("</thead>"); } else if (row.RowType == ReportRowType.FooterRow) { Html.AppendLine("</tfoot>"); } } Html.AppendLine("</tbody>"); RenderFooter(textFields, hints); }
protected virtual void RenderHeader(ReportTextFieldCollection textFields, RenderHintsCollection hints) { if (WrapHeadAndBody) { Html.AppendLine("<html><head>"); } AppendStyling(hints); if (WrapHeadAndBody) { Html.AppendLine("</head><body>"); } Html.AppendLine("<div class='htmlReport'>"); if (!string.IsNullOrEmpty(textFields.Title)) { Html.AppendFormat("<h4 class='title'>{0}</h4>", textFields.Title.FormatHtml()); } if (!string.IsNullOrEmpty(textFields.SubTitle)) { Html.AppendFormat("<h5 class='subTitle'>{0}</h5>", textFields.SubTitle.FormatHtml()); } if (!string.IsNullOrEmpty(textFields[HtmlLogo])) { Html.AppendFormat(textFields[HtmlLogo].FormatHtml()); } if (!string.IsNullOrEmpty(textFields.Header)) { Html.AppendFormat("<p class='header'>{0}</p>", textFields.Header.FormatHtml()); } Html.AppendLine("<table border='0' cellpadding='2' cellspacing='0' width='100%'>"); }
protected virtual void RenderHeader(ReportTextFieldCollection textFields, RenderHintsCollection hints) { if (WrapHeadAndBody) { Html.AppendLine("<html><head>"); } AppendStyling(hints); if (WrapHeadAndBody) { Html.AppendLine("</head><body>"); } Html.AppendLine("<div class='htmlReport'>"); if (!string.IsNullOrEmpty(textFields.Title)) { Html.AppendFormat("<center><h4 style='margin-bottom: 1px;'>{0}</h4></center>", textFields.Title.FormatHtml()); } if (!string.IsNullOrEmpty(textFields.SubTitle)) { Html.AppendFormat("<center><h5 style='margin-bottom: 3px; margin-top: 1px'>{0}</h5></center>", textFields.SubTitle.FormatHtml()); } if (!string.IsNullOrEmpty(textFields[HtmlLogo])) { Html.AppendFormat(textFields[HtmlLogo].FormatHtml()); } if (!string.IsNullOrEmpty(textFields.Header)) { Html.AppendFormat("<b>{0}</b><hr />", textFields.Header.FormatHtml()); } Html.AppendLine("<table border='0' cellpadding='2' cellspacing='0' width='100%'>"); }
protected virtual void RenderRow(ReportRow row, RenderHintsCollection hints) { Html.AppendLine("<tr>"); foreach (RowField field in row.Fields) { if (row.RowType == ReportRowType.HeaderRow) { Html.AppendFormat("<th style='{1}' align='left'>{0}</th>", field.HeaderText, GetCellStyle(row, field)); } else if (row.RowType == ReportRowType.DataRow) { if (hints.BooleanCheckboxes) { if (field.DataType == typeof(bool) || field.DataType == typeof(bool?)) { string html = "<input type='checkbox'"; if (GetBooleanValue(row[field.Name]) == true) { html += " checked='checked'"; } html += " />"; row[field] = html; } } Html.AppendFormat("<td style='{1}'>{0}</td>", row.GetFormattedValue(field), GetCellStyle(row, field)); } else if (row.RowType == ReportRowType.FooterRow) { Html.AppendFormat("<td style='{1}'>{0}</td>", row.GetFormattedValue(field), GetCellStyle(row, field)); } } Html.AppendLine("</tr>"); }
/// <summary> /// Renders the header. /// </summary> /// <param name="globalTable">The global table.</param> /// <param name="textFields">The text fields.</param> /// <param name="renderHints">The render hints.</param> protected virtual void RenderHeader(PdfPTable globalTable, ReportTextFieldCollection textFields, RenderHintsCollection renderHints) { int rowCount = 0; if (!string.IsNullOrEmpty(textFields.Title)) { ReportStyle reportStyle = renderHints[TitleStyle] as ReportStyle ?? GetDefaultTitleStyle(); globalTable.AddCell(CreateTextCell(reportStyle, renderHints[FontFamily] as string, textFields.Title)); rowCount++; } if (!string.IsNullOrEmpty(textFields.SubTitle)) { ReportStyle reportStyle = renderHints[SubTitleStyle] as ReportStyle ?? GetDefaultSubTitleStyle(); globalTable.AddCell(CreateTextCell(reportStyle, renderHints[FontFamily] as string, textFields.SubTitle)); rowCount++; } if (!string.IsNullOrEmpty(textFields.Header)) { ReportStyle reportStyle = renderHints[HeaderStyle] as ReportStyle ?? GetDefaultHeaderStyle(); globalTable.AddCell(CreateTextCell(reportStyle, renderHints[FontFamily] as string, textFields.Header)); rowCount++; } if (rowCount > 0) { PdfPCell cell = CreateTextCell(new ReportStyle(), renderHints[FontFamily] as string, string.Empty); cell.PaddingBottom = 10; globalTable.AddCell(cell); rowCount++; } globalTable.HeaderRows = rowCount; }
/// <summary> /// Renders the footer. /// </summary> /// <param name="worksheet">The worksheet.</param> /// <param name="fieldsCount">The fields count.</param> /// <param name="textFields">The text fields.</param> /// <param name="renderHintsCollection">The render hints collection.</param> /// <param name="currentRow">The current row.</param> /// <returns>The last row it wrote on.</returns> protected virtual int RenderFooter(IXLWorksheet worksheet, int fieldsCount, ReportTextFieldCollection textFields, RenderHintsCollection renderHintsCollection, int currentRow) { if (!string.IsNullOrEmpty(textFields.Footer)) { currentRow = RenderTextItem(worksheet, fieldsCount, textFields.Footer, currentRow, renderHintsCollection[FooterStyle] as ReportStyle ?? GetDefaultFooterStyle()); } return(currentRow); }
/// <summary> /// Renders the header. /// </summary> /// <param name="worksheet">The worksheet.</param> /// <param name="fieldsCount">The fields count.</param> /// <param name="textFields">The report text field collection.</param> /// <param name="renderHints">The render hints collection.</param> /// <returns>The last row the header was written on.</returns> protected virtual int RenderHeader(IXLWorksheet worksheet, int fieldsCount, ReportTextFieldCollection textFields, RenderHintsCollection renderHints) { int rowCount = 0; if (!string.IsNullOrEmpty(textFields.Title)) { rowCount = RenderTextItem(worksheet, fieldsCount, textFields.Title, rowCount, renderHints[TitleStyle] as ReportStyle ?? GetDefaultTitleStyle()); } if (!string.IsNullOrEmpty(textFields.SubTitle)) { rowCount = RenderTextItem(worksheet, fieldsCount, textFields.SubTitle, rowCount, renderHints[SubTitleStyle] as ReportStyle ?? GetDefaultSubTitleStyle()); } if (!string.IsNullOrEmpty(textFields.Header)) { rowCount = RenderTextItem(worksheet, fieldsCount, textFields.Header, rowCount, renderHints[HeaderStyle] as ReportStyle ?? GetDefaultHeaderStyle()); } if (rowCount > 0) { rowCount++; worksheet.Range(rowCount, 1, rowCount, fieldsCount).Merge(); } return(rowCount); }
public PdfDocument BuildDocument(ReportTextFieldCollection textFields, RenderHintsCollection hints, ReportRowCollection rows) { Document = hints.Orientation == ReportOrientation.Portrait ? new PdfDocument(ReportOrientation.Portrait) : new PdfDocument(); Document.Font = Document.AddFont("Helvetica"); Document.FontSize = 6; XRect docCoords = Document.Rect; double height = Document.Rect.Height; double width = Document.Rect.Width; Document.Rect.Inset(10, 40); Document.Rect.Height = Document.Rect.Height - 50; int fieldCount = 0; if (rows[0] != null) { fieldCount = rows[0].Fields.Count(f => f.Hidden == false); } var table = new PDFTable(Document, fieldCount) { CellPadding = 5, RepeatHeader = true }; if (hints.ContainsKey("PdfWidths")) { double[] widths = hints["PdfWidths"] as double[]; table.SetColumnWidths(widths); } foreach (ReportRow row in rows) { table.NextRow(); int cellIndex = 0; foreach (RowField field in row.Fields) { table.NextCell(); string cellHtml; if (row.RowType == ReportRowType.HeaderRow) { cellHtml = string.Format("<StyleRun FontSize=7><B><U>{0}</U></B></StyleRun>", field.HeaderText); } else { // TODO: Support DataRow styling, etc cellHtml = row.GetFormattedValue(field); } table.AddHtml(cellHtml); cellIndex++; } if (hints.ContainsKey("PdfUnderline")) { if (hints["PdfUnderline"] as bool? == true) { table.UnderlineRow("800 800 800", table.Row); } } } // HEADER Document.Rect.Position(10, height - 90); Document.Rect.Height = 80; Document.Rect.Width = width; for (int i = 1; i <= Document.PageCount; i++) { Document.PageNumber = i; Document.AddHtml(string.Format("<h3 align='center'>{0}</h3>", textFields.Title.FormatHtml())); Document.AddHtml(string.Format("<h5 align='center'>{0}</h5>", textFields.SubTitle.FormatHtml())); Document.AddHtml(string.Format("<p><b>{0}</b></p>", textFields.Header.FormatHtml())); } // TODO: Support for sub-totals on each page, for columns that ask for totals // TODO: Need to add support for the Report Footer text, currently only supports page numbers // FOOTER if (hints.IncludePageNumbers) { Document.Rect.Position(10, Document.MediaBox.Bottom); Document.Rect.Height = 30; Document.Rect.Width = width; Document.HPos = 0.5; Document.VPos = 0.5; for (int i = 1; i <= Document.PageCount; i++) { //Document.AddBookmark("Page " + i.ToString(), true); Document.PageNumber = i; Document.AddText(string.Format("Page {0} of {1}", i, Document.PageCount)); } } for (int i = 1; i <= Document.PageCount; i++) { Document.PageNumber = i; Document.Flatten(); } return(Document); }