Пример #1
0
        public static TagBuilder Render(this ICell cell, int renderIndex, TagBuilder builder = null)
        {
            TagBuilder thisCell =
                cell.Parent.RowType switch
            {
                RowEnum.Header => new TagBuilder("th"),
                _ => new TagBuilder("td"),
            };

            thisCell.Attributes.Add("id", cell.Identifier);

            if (cell.Parent != null)
            {
                cell.Parent.Styles.Cast <IHtmlStyle>().ToList().ForEach(style =>
                {
                    style.Render(thisCell, cell, cell.GetValue(renderIndex));
                });
            }

            if (cell.ColSpan > 1)
            {
                thisCell.Attributes.Add("colspan", cell.ColSpan.ToString());
            }

            if (cell.RowSpan > 1)
            {
                thisCell.Attributes.Add("rowspan", cell.RowSpan.ToString());
            }

            var style =
                cell.Styles.Count > renderIndex ? (IHtmlStyle)cell.Styles[renderIndex] :
                cell.Values.Count == 1 ? (IHtmlStyle)cell.Styles[0] : null;

            if (style != null)
            {
                style.Render(thisCell, cell, cell.GetValue(renderIndex));
            }

            if (cell is ICustomHtmlCell customCell)
            {
                customCell.Render(thisCell, renderIndex, builder);
            }
            else
            {
                thisCell.AddCssClass("align-center");

                switch (cell.TextPosition)
                {
                case TextPositionEnum.Center:
                    thisCell.AddCssClass("text-center");
                    thisCell.AddCssClass("center");
                    break;
                }

                var value = cell.GetValueAsString(renderIndex);

                value = value == "0" ? "" :
                        value == "0,0" ? "" :
                        value == "0,00" ? "" :
                        value == "0,000" ? "" :
                        value == "0" ? "" :
                        value == "0.0" ? "" :
                        value == "0.00" ? "" :
                        value == "0.000" ? "" : value;

                if (value != null && value != "")
                {
                    thisCell.InnerHtml.AppendHtml(value.Replace("\r\n", "<br>"));

                    if (cell.Parent != null && cell.Parent.RowType == RowEnum.Record)
                    {
                        thisCell.Attributes.Add("data-title", cell.Parent.GetTitleFor(cell));
                    }
                }
                else
                {
                    thisCell.AddCssClass("hidden");
                }
            }

            if (cell.CanPopup())
            {
                thisCell.Attributes.Add("data-toggle", "popover");
                thisCell.Attributes.Add("data-trigger", "hover");
                thisCell.Attributes.Add("data-content", cell.PopupText);
                thisCell.Attributes.Add("data-original-title", cell.PopupTitle);
            }

            return(thisCell);
        }
Пример #2
0
        public static void Render(this ICell cell, int renderIndex, ExcelRange range)
        {
            var cellValue = cell.GetValue(renderIndex);

            if (cellValue != null && cellValue.Value != null)
            {
                if (cellValue.Value is double dValue)
                {
                    if (dValue != 0)
                    {
                        range.Value = cellValue.Value;
                    }
                }
                else if (cellValue.Value is int iValue)
                {
                    if (iValue != 0)
                    {
                        range.Value = cellValue.Value;
                    }
                }
                else if (cellValue.Value is string sValue)
                {
                    range.Style.WrapText = true;
                    range.Value          = cellValue.Value;
                }
                else
                {
                    range.Value = cellValue.Value;
                }

                if (cellValue is DoubleValue doubleValue)
                {
                    range.Style.Numberformat.Format = doubleValue.NumberFormat;
                }
                else if (cellValue.Value is DateTime)
                {
                    range.Style.Numberformat.Format = "dd/MM/yyyy";
                }
            }

            cell.Styles.Cast <ISheetStyle>().ToList().ForEach(style =>
            {
                if (style != null)
                {
                    style.Render(range, cell, cell.GetValue(renderIndex));

                    if (style.NumberFormat != null)
                    {
                        range.Style.Numberformat.Format = style.NumberFormat;
                    }
                }
            });

            if (cell.CanPopup())
            {
                range.AddComment($"{cell.PopupTitle}:\n{cell.PopupText}", "mustafa.dagci");
                range.Comment.AutoFit = true;
            }

            if (cell is ICustomSheetCell customCell)
            {
                customCell.Render(range, cell.Parent, cell);
            }
        }