コード例 #1
0
        private void RecurseRender(Element elmt, decimal top, decimal left)
        {
            top  += elmt.Top;
            left += elmt.Left;

            if (elmt is TextElement)
            {
                TextElement te = elmt as TextElement;
                TextStyle   ts = null;
                if (te.Style is TextStyle)
                {
                    ts = (TextStyle)te.Style;
                }

                Int32 row = _rows.FindIndex(delegate(decimal d) { return(d == top); });
                Int32 col;
                if (ts != null && ts.TextAlign == RdlEngine.Style.TextAlignEnum.Right)
                {
                    col = _cols.FindIndex(delegate(decimal d) { return(d == left + elmt.Width); }) - 1;
                }
                else
                {
                    col = _cols.FindIndex(delegate(decimal d) { return(d == left); });
                }

                WorksheetCell cell = _ws.Rows[row].Cells[col];
                cell.Value = te.Text;

                if (ts != null)
                {
                    int fontHeight = (int)(ts.FontSize.points * _fontHeight);

                    if (ts.BorderStyle != null && ts.BorderStyle != null)
                    {
                        BorderStyle bs = ts.BorderStyle;

                        cell.CellFormat.TopBorderStyle    = ExcelBorderStyleFromRdlBorderStyle(bs.Top);
                        cell.CellFormat.BottomBorderStyle = ExcelBorderStyleFromRdlBorderStyle(bs.Bottom);
                        cell.CellFormat.LeftBorderStyle   = ExcelBorderStyleFromRdlBorderStyle(bs.Left);
                        cell.CellFormat.RightBorderStyle  = ExcelBorderStyleFromRdlBorderStyle(bs.Right);
                    }
                    if (ts.BorderColor != null)
                    {
                        cell.CellFormat.TopBorderColor    = System.Drawing.Color.FromName(ts.BorderColor.Top);
                        cell.CellFormat.BottomBorderColor = System.Drawing.Color.FromName(ts.BorderColor.Bottom);
                        cell.CellFormat.LeftBorderColor   = System.Drawing.Color.FromName(ts.BorderColor.Left);
                        cell.CellFormat.RightBorderColor  = System.Drawing.Color.FromName(ts.BorderColor.Right);
                    }
                    cell.CellFormat.Font.Name   = ts.FontFamily;
                    cell.CellFormat.Font.Height = fontHeight;
                    RdlEngine.Style.FontStyleEnum style = ts.FontStyle;
                    if (style == RdlEngine.Style.FontStyleEnum.Italic)
                    {
                        cell.CellFormat.Font.Italic = ExcelDefaultableBoolean.True;
                    }
                    switch (ts.FontWeight)
                    {
                    case RdlEngine.Style.FontWeightEnum.Bold:
                    case RdlEngine.Style.FontWeightEnum.Bolder:
                    case RdlEngine.Style.FontWeightEnum._600:
                    case RdlEngine.Style.FontWeightEnum._700:
                    case RdlEngine.Style.FontWeightEnum._800:
                    case RdlEngine.Style.FontWeightEnum._900:
                        cell.CellFormat.Font.Bold = ExcelDefaultableBoolean.True;
                        break;
                    }
                    cell.CellFormat.Font.Color = System.Drawing.Color.FromName(ts.Color);
                    cell.CellFormat.Alignment  = (HorizontalCellAlignment)Enum.Parse(typeof(HorizontalCellAlignment), ts.TextAlign.ToString(), true);
                    if (ts.BackgroundColor != null)
                    {
                        cell.CellFormat.FillPatternForegroundColor = System.Drawing.Color.FromName(ts.BackgroundColor);
                        cell.CellFormat.FillPatternBackgroundColor = System.Drawing.Color.White;
                        cell.CellFormat.FillPattern = FillPatternStyle.Solid;
                    }
                }
            }

            if (elmt is Container)
            {
                foreach (Element child in ((Container)elmt).Children)
                {
                    RecurseRender(child, top, left);
                }
            }
        }