Beispiel #1
0
        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 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 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>");
        }
Beispiel #4
0
        /// <summary>
        /// Renders the row.
        /// </summary>
        /// <param name="rowCount">The row count.</param>
        /// <param name="reportRow">The row.</param>
        /// <param name="dataRow">The data row.</param>
        protected virtual void RenderRow(int rowCount, ReportRow reportRow, IXLRow dataRow)
        {
            int colCount = 0;

            foreach (var field in reportRow.Fields.Where(f => !f.Hidden))
            {
                colCount++;

                if (reportRow.RowType == ReportRowType.HeaderRow)
                {
                    var cell = dataRow.Cell(colCount);
                    cell.Value = field.HeaderText;
                    field.HeaderStyle.CopyToXlStyle(cell.Style);
                }
                else if (reportRow.RowType == ReportRowType.DataRow)
                {
                    var cell = dataRow.Cell(colCount);
                    field.DataStyle.CopyToXlStyle(cell.Style);
                    if (field.DataType == typeof(bool))
                    {
                        cell.SetDataType(XLDataType.Boolean);
                        cell.Value = reportRow[field];
                    }
                    else if (field.DataType.IsNumericType())
                    {
                        cell.SetDataType(XLDataType.Number);
                        if (!string.Equals("{0}", field.DataFormatString))
                        {
                            cell.Style.NumberFormat.Format = GetOpenXmlDataFormatString(field.DataFormatString);
                            cell.Value = reportRow[field];
                        }
                        else
                        {
                            cell.Value = reportRow.GetFormattedValue(field);
                        }
                    }
                    else if (field.DataType == typeof(DateTime) || field.DataType == typeof(DateTime?))
                    {
                        cell.SetDataType(XLDataType.DateTime);
                        cell.Value = reportRow.GetFormattedValue(field);
                    }
                    else
                    {
                        cell.Value = reportRow.GetFormattedValue(field);
                    }

                    var url = reportRow.GetUrlString(field);
                    if (url != null)
                    {
                        cell.Hyperlink = new XLHyperlink(url);
                    }
                }
                else if (reportRow.RowType == ReportRowType.FooterRow)
                {
                    if (field.ShowTotals)
                    {
                        var cell = dataRow.Cell(colCount);
                        cell.SetDataType(XLDataType.Number);
                        cell.FormulaA1 = string.Format(CultureInfo.InvariantCulture, "=SUM({0}{1}:{0}{2})", cell.Address.ColumnLetter, 2, rowCount - 1);
                        if (!string.Equals("{0}", field.DataFormatString))
                        {
                            cell.Style.NumberFormat.Format = GetOpenXmlDataFormatString(field.DataFormatString);
                        }

                        field.FooterStyle.CopyToXlStyle(cell.Style);
                    }
                }
            }
        }
        protected virtual void DefineTables(Document document, Report report)
        {
            ReportRowCollection rptrows = report.GetRows();
            int rowCount = rptrows.Count;

            if (rowCount <= 1)
            {
                return;
            }

            Table table = new Table();

            table.Format.Alignment = ParagraphAlignment.Center;
            table.Borders.Width    = 0.75;


            ReportRow headerRow   = rptrows[0];
            int       columnCount = 0;

            foreach (RowField field in headerRow.Fields)
            {
                columnCount++;
            }


            Unit      columnWidth = 100;
            PageSetup pageSetup   = document.DefaultPageSetup;

            if (Landscape)
            {
                columnWidth = (pageSetup.PageHeight - pageSetup.TopMargin - pageSetup.BottomMargin) / columnCount;
            }
            else
            {
                columnWidth = (pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin) / columnCount;
            }


            foreach (RowField field in headerRow.Fields)
            {
                table.AddColumn(columnWidth);
            }

            int  columnIndex = 0;
            Row  row         = table.AddRow();
            Cell cell        = null;

            row.Shading.Color = Colors.PaleGoldenrod;
            foreach (RowField field in headerRow.Fields)
            {
                cell = row.Cells[columnIndex++];
                cell.AddParagraph(field.HeaderText);
            }

            for (int rowIndex = 1; rowIndex < rowCount; ++rowIndex)
            {
                ReportRow rptrow = rptrows[rowIndex];
                row = table.AddRow();

                if (rptrow.RowType == ReportRowType.DataRow)
                {
                    columnIndex = 0;
                    foreach (RowField field in rptrow.Fields)
                    {
                        cell = row.Cells[columnIndex++];
                        cell.AddParagraph(rptrow.GetFormattedValue(field));
                    }
                }
            }

            document.LastSection.Add(table);
        }