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>");
        }
Beispiel #2
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);
                    }
                }
            }
        }