예제 #1
0
        void ExportCell(IXlRow row, int gridRowHandle, GridColumn gridColumn)
        {
            using (IXlCell cell = row.CreateCell()) {
                // Set cell value
                cell.Value = XlVariantValue.FromObject(this.view.GetRowCellValue(gridRowHandle, gridColumn));

                // Get cell appearance
                AppearanceObject appearance = GetCellAppearance(gridRowHandle, gridColumn);

                // Apply alignment
                XlCellAlignment alignment = new XlCellAlignment()
                {
                    WrapText            = appearance.TextOptions.WordWrap.HasFlag(WordWrap.Wrap),
                    VerticalAlignment   = ConvertAlignment(appearance.TextOptions.VAlignment),
                    HorizontalAlignment = ConvertAlignment(appearance.TextOptions.HAlignment)
                };
                cell.ApplyFormatting(alignment);

                // Apply borders
                Color borderColor = appearance.GetBorderColor();
                if (!DXColor.IsTransparentOrEmpty(borderColor))
                {
                    cell.ApplyFormatting(XlBorder.OutlineBorders(borderColor));
                }

                // Apply fill
                if (appearance.Options.UseBackColor)
                {
                    cell.ApplyFormatting(XlFill.SolidFill(appearance.BackColor));
                }

                // Apply font
                Font   appearanceFont = appearance.Font;
                XlFont font           = XlFont.CustomFont(appearanceFont.Name);
                font.Size          = appearanceFont.SizeInPoints;
                font.Bold          = appearanceFont.Bold;
                font.Italic        = appearanceFont.Italic;
                font.StrikeThrough = appearanceFont.Strikeout;
                font.Underline     = appearanceFont.Underline ? XlUnderlineType.Single : XlUnderlineType.None;
                if (appearance.Options.UseForeColor)
                {
                    font.Color = appearance.ForeColor;
                }
                cell.ApplyFormatting(font);
            }
        }