コード例 #1
0
        /// <summary>
        /// Create an Allignment object which manages indentation, alignment and text rotation and applies it to the cellFormat.
        /// </summary>
        /// <param name="cellInfo"></param>
        /// <param name="stylesheet"></param>
        /// <param name="cellFormat"></param>
        private static void UpdateTextAlignmentAndRotation(ExcelCellStyleInfo cellInfo, ref CellFormat cellFormat)
        {
            if (cellFormat == null)
            {
                throw new ArgumentNullException("cellFormat");
            }

            if (cellInfo.AlignmentInfo != null)
            {
                cellFormat.Alignment = new Alignment()
                {
                    Indent       = new UInt32Value((uint)cellInfo.AlignmentInfo.LeftMargin / 2),
                    Horizontal   = new EnumValue <HorizontalAlignmentValues>(StyleTranslator.Translate(cellInfo.AlignmentInfo.TextAlignment)),
                    Vertical     = new EnumValue <VerticalAlignmentValues>(StyleTranslator.Translate(cellInfo.AlignmentInfo.VerticalAlignment)),
                    WrapText     = new BooleanValue(cellInfo.AlignmentInfo.TextWrapping != TextWrapping.NoWrap),
                    TextRotation = (uint)cellInfo.AlignmentInfo.TextRotationAngle,
                };
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates and appends a new border to the supplied <see cref="Stylesheet"/> based on properties of the <see cref="ExcelCellBorderInfo"/>.<br/>
        /// Returns the index of the newly created border.
        /// </summary>
        /// <param name="stylesheet"></param>
        /// <param name="borderInfo"></param>
        /// <returns></returns>
        private static uint CreateNewBorder(Stylesheet stylesheet, ExcelCellBorderInfo borderInfo)
        {
            Border border = new Border();

            // LEFT
            if (borderInfo.HasLeftBorder)
            {
                border.LeftBorder = new LeftBorder()
                {
                    Color = new DocumentFormat.OpenXml.Spreadsheet.Color()
                    {
                        Rgb = new HexBinaryValue(StyleTranslator.Translate(borderInfo.ColourLeft.Value))
                    },
                    Style = StyleTranslator.Translate(borderInfo.WidthLeft)
                };
            }

            // TOP
            if (borderInfo.HasTopBorder)
            {
                border.TopBorder = new TopBorder()
                {
                    Color = new DocumentFormat.OpenXml.Spreadsheet.Color()
                    {
                        Rgb = new HexBinaryValue(StyleTranslator.Translate(borderInfo.ColourTop.Value))
                    },
                    Style = StyleTranslator.Translate(borderInfo.WidthTop)
                };
            }

            // RIGHT
            if (borderInfo.HasRightBorder)
            {
                border.RightBorder = new RightBorder()
                {
                    Color = new DocumentFormat.OpenXml.Spreadsheet.Color()
                    {
                        Rgb = new HexBinaryValue(StyleTranslator.Translate(borderInfo.ColourRight.Value))
                    },
                    Style = StyleTranslator.Translate(borderInfo.WidthRight)
                };
            }

            // BOTTOM
            if (borderInfo.HasBottomBorder)
            {
                border.BottomBorder = new BottomBorder()
                {
                    Color = new DocumentFormat.OpenXml.Spreadsheet.Color()
                    {
                        Rgb = new HexBinaryValue(StyleTranslator.Translate(borderInfo.ColourBottom.Value))
                    },
                    Style = StyleTranslator.Translate(borderInfo.WidthBottom)
                };
            }

            stylesheet.Borders.Append(border);
            uint borderId = (uint)new List <object>(stylesheet.Borders.Cast <object>()).IndexOf(border);

            return(borderId);
        }
コード例 #3
0
        /// <summary>
        /// Updates the supplied <see cref="CellFormat"/> with a font index which relates to the fund in the supplied <see cref="ExportStyle"/>
        /// </summary>
        /// <param name="stylesheet"></param>
        /// <param name="cellInfo"></param>
        /// <returns></returns>
        private static void UpdateFont(ExcelStylesManager stylesManager, ExcelCellStyleInfo cellInfo, ref Stylesheet stylesheet, ref CellFormat cellFormat)
        {
            if (cellFormat == null)
            {
                throw new ArgumentNullException("cellFormat");
            }

            // Anything to apply?
            if (cellInfo.FontInfo == null)
            {
                return;
            }

            // Look up existing...
            var         fontItem = stylesManager.fonts.Find(cellInfo.FontInfo);
            UInt32Value id       = fontItem.Value;

            if (id == null)
            {
                // Fonts
                Font font = new Font();

                if (cellInfo.FontInfo.FontFamily != null)
                {
                    font.FontName = new FontName()
                    {
                        Val = new StringValue(cellInfo.FontInfo.FontFamily.ToString())
                    };
                }

                font.FontSize = new FontSize()
                {
                    Val = new DoubleValue(cellInfo.FontInfo.FontSize)
                };

                if ((cellInfo.FontInfo.FontWeight != null) &&
                    (cellInfo.FontInfo.FontWeight == FontWeights.Bold))
                {
                    font.Bold = new Bold();
                }

                if (cellInfo.FontInfo.FontStyle != null)
                {
                    if (cellInfo.FontInfo.FontStyle == FontStyles.Italic)
                    {
                        font.Italic = new Italic();
                    }
                }

                font.Color = new DocumentFormat.OpenXml.Spreadsheet.Color()
                {
                    Rgb = new HexBinaryValue(StyleTranslator.Translate(cellInfo.FontInfo.FontColour))
                };

                if (cellInfo.FontInfo.FontUnderlined)
                {
                    font.Underline = new Underline();
                }

                id = stylesheet.AddFont(font);
                stylesManager.fonts.Add(cellInfo.FontInfo, id);
            }

            cellFormat.FontId = id;
        }