コード例 #1
0
ファイル: StyleManager.cs プロジェクト: Stoeoeoe/NanoXLSX
        /// <summary>
        /// Adds a style component to the manager
        /// </summary>
        /// <param name="style">Component to add</param>
        /// <returns>Hash of the added or determined component</returns>
        private string AddStyleComponent(AbstractStyle style)
        {
            string hash = style.Hash;

            if (style.GetType() == typeof(NanoXLSX.Style.Style.Border))
            {
                if (GetComponentByHash(ref borders, hash) == null)
                {
                    borders.Add(style);
                }
                Reorganize(ref borders);
            }
            else if (style.GetType() == typeof(NanoXLSX.Style.Style.CellXf))
            {
                if (GetComponentByHash(ref cellXfs, hash) == null)
                {
                    cellXfs.Add(style);
                }
                Reorganize(ref cellXfs);
            }
            else if (style.GetType() == typeof(NanoXLSX.Style.Style.Fill))
            {
                if (GetComponentByHash(ref fills, hash) == null)
                {
                    fills.Add(style);
                }
                Reorganize(ref fills);
            }
            else if (style.GetType() == typeof(NanoXLSX.Style.Style.Font))
            {
                if (GetComponentByHash(ref fonts, hash) == null)
                {
                    fonts.Add(style);
                }
                Reorganize(ref fonts);
            }
            else if (style.GetType() == typeof(NanoXLSX.Style.Style.NumberFormat))
            {
                if (GetComponentByHash(ref numberFormats, hash) == null)
                {
                    numberFormats.Add(style);
                }
                Reorganize(ref numberFormats);
            }
            else if (style.GetType() == typeof(NanoXLSX.Style.Style))
            {
                NanoXLSX.Style.Style s = (NanoXLSX.Style.Style)style;
                if (styleNames.Contains(s.Name) == true)
                {
                    throw new StyleException("StyleAlreadyExistsException", "The style with the name '" + s.Name + "' already exists");
                }
                if (GetComponentByHash(ref styles, hash) == null)
                {
                    int?id;
                    if (s.InternalID.HasValue == false)
                    {
                        id           = int.MaxValue;
                        s.InternalID = id;
                    }
                    else
                    {
                        id = s.InternalID.Value;
                    }
                    string temp = AddStyleComponent(s.CurrentBorder, id);
                    s.CurrentBorder       = (NanoXLSX.Style.Style.Border)GetComponentByHash(ref borders, temp);
                    temp                  = AddStyleComponent(s.CurrentCellXf, id);
                    s.CurrentCellXf       = (NanoXLSX.Style.Style.CellXf)GetComponentByHash(ref cellXfs, temp);
                    temp                  = AddStyleComponent(s.CurrentFill, id);
                    s.CurrentFill         = (NanoXLSX.Style.Style.Fill)GetComponentByHash(ref fills, temp);
                    temp                  = AddStyleComponent(s.CurrentFont, id);
                    s.CurrentFont         = (NanoXLSX.Style.Style.Font)GetComponentByHash(ref fonts, temp);
                    temp                  = AddStyleComponent(s.CurrentNumberFormat, id);
                    s.CurrentNumberFormat = (NanoXLSX.Style.Style.NumberFormat)GetComponentByHash(ref numberFormats, temp);
                    styles.Add(s);
                }
                Reorganize(ref styles);
                hash = s.CalculateHash();
            }
            return(hash);
        }
コード例 #2
0
ファイル: StyleManager.cs プロジェクト: Stoeoeoe/NanoXLSX
        /* ****************************** */


        /// <summary>
        /// Adds a style component to the manager
        /// </summary>
        /// <param name="style">Style to add</param>
        /// <returns>Added or determined style in the manager</returns>
        public NanoXLSX.Style.Style AddStyle(NanoXLSX.Style.Style style)
        {
            string hash = AddStyleComponent(style);

            return((NanoXLSX.Style.Style)GetComponentByHash(ref styles, hash));
        }