Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        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 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%'>");
        }
        /// <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;
        }
Exemple #10
0
        public string ExcelHeaderHtml(ReportTextFieldCollection textFields)
        {
            var sb = new StringBuilder();

            sb.Append("<html xmlns:o='urn:schemas-microsoft-com:office:office'\n" +

                      "xmlns:x='urn:schemas-microsoft-com:office:excel'\n" +
                      "xmlns='http://www.w3.org/TR/REC-html40'>\n" +

                      "<head>\n");
            sb.Append("<style>\n");

            sb.Append("@page");
            sb.Append("{margin:.5in .75in .5in .75in;\n");

            sb.Append("mso-header-margin:.5in;\n");
            sb.Append("mso-footer-margin:.5in;\n");

            sb.Append("mso-page-orientation:landscape;}\n");

            sb.Append("@print { mso-print-title-row:\"$1:$7\"; }");

            sb.Append("thead { display:table-header-group; }");
            sb.Append("tbody { display:table-body-group; }");
            sb.Append("tfoot { display:table-footer-group; }");

            sb.Append("</style>\n");

            sb.Append("<!--[if gte mso 9]><xml>\n");
            sb.Append("<x:ExcelWorkbook>\n");

            sb.Append("<x:ExcelWorksheets>\n");
            sb.Append("<x:ExcelWorksheet>\n");

            sb.AppendFormat("<x:Name>{0}</x:Name>\n", textFields.Title);
            sb.Append("<x:WorksheetOptions>\n");

            int numberOfHeaderLines = textFields.Title.NumberOfLines() + textFields.SubTitle.NumberOfLines();

            // Header contains a <hr /> which is converted into <br/><br/> so it has 1 extra line break if it isn't empty
            if (!string.IsNullOrEmpty(textFields.Header))
            {
                numberOfHeaderLines += textFields.Header.NumberOfLines() + 1;
            }

            sb.AppendFormat(@"
                <x:FreezePanes/>
                <x:FrozenNoSplit/>
                <x:SplitHorizontal>{0}</x:SplitHorizontal>
                <x:TopRowBottomPane>{0}</x:TopRowBottomPane>",
                            numberOfHeaderLines + 1);


            sb.Append("<x:FitToPage/>\n");

            sb.Append("<x:Print>\n");
            sb.Append("<x:FitHeight>999</x:FitHeight>\n");
            sb.Append("<x:ValidPrinterInfo/>\n");
            sb.Append("<x:PaperSizeIndex>9</x:PaperSizeIndex>\n");
            sb.Append("<x:Scale>67</x:Scale>\n");
            sb.Append("<x:HorizontalResolution>600</x:HorizontalResolution\n");
            sb.Append("<x:VerticalResolution>600</x:VerticalResolution\n");
            sb.Append("</x:Print>\n");

            sb.Append("<x:Selected/>\n");
            sb.Append("<x:DoNotDisplayGridlines/>\n");

            sb.Append("<x:ProtectContents>False</x:ProtectContents>\n");
            sb.Append("<x:ProtectObjects>False</x:ProtectObjects>\n");

            sb.Append("<x:ProtectScenarios>False</x:ProtectScenarios>\n");
            sb.Append("</x:WorksheetOptions>\n");

            sb.Append("</x:ExcelWorksheet>\n");
            sb.Append("</x:ExcelWorksheets>\n");

            sb.Append("<x:WindowHeight>12780</x:WindowHeight>\n");
            sb.Append("<x:WindowWidth>19035</x:WindowWidth>\n");

            sb.Append("<x:WindowTopX>0</x:WindowTopX>\n");
            sb.Append("<x:WindowTopY>15</x:WindowTopY>\n");

            sb.Append("<x:ProtectStructure>False</x:ProtectStructure>\n");
            sb.Append("<x:ProtectWindows>False</x:ProtectWindows>\n");

            sb.Append("</x:ExcelWorkbook>\n");
            sb.Append("</xml><![endif]-->\n");

            sb.Append("</head><body>\n");


            return(sb.ToString());
        }
        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);
        }