Esempio n. 1
0
        /// <summary>
        /// Adds OpenXml <see cref="CellFormat"/> to document stylesheet CellStyleFormats.
        /// </summary>
        /// <param name="documentContext">Source document.</param>
        /// <param name="cellFormat">CellFormat to add.</param>
        /// <param name="name">Name attached to cellFormat.</param>
        /// <returns>The same document context.</returns>
        public static DocumentContext AddCellStyleFormat(this DocumentContext documentContext, CellFormat cellFormat, string name)
        {
            Stylesheet stylesheet = documentContext.GetStylesheet();

            if (stylesheet.CellStyleFormats == null)
            {
                stylesheet.CellStyleFormats = new CellStyleFormats();
            }

            stylesheet.CellStyleFormats.AppendChild(cellFormat.SetStyleSheetName(name));
            stylesheet.CellStyleFormats.Count = (uint)stylesheet.CellStyleFormats.ChildElements.Count;

            return(documentContext);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds OpenXml <see cref="CellFormat"/> to document stylesheet CellFormats.
        /// </summary>
        /// <param name="documentContext">Source document.</param>
        /// <param name="cellFormat">CellFormat to add.</param>
        /// <param name="name">Name attached to cellFormat.</param>
        /// <param name="replaceOldIfExists">Replace old if exists.</param>
        /// <returns>The same document context.</returns>
        public static DocumentContext AddCellFormat(this DocumentContext documentContext, CellFormat cellFormat, string name, bool replaceOldIfExists = true)
        {
            Stylesheet stylesheet = documentContext.GetStylesheet();

            if (stylesheet.CellFormats == null)
            {
                stylesheet.CellFormats = new CellFormats();
            }

            if (replaceOldIfExists)
            {
                var existent = documentContext.TryGetCellFormat(name);
                if (existent != null)
                {
                    stylesheet.CellFormats.RemoveChild(existent);
                }
            }

            stylesheet.CellFormats.AppendChild(cellFormat.SetStyleSheetName(name));
            stylesheet.CellFormats.Count = (uint)stylesheet.CellFormats.ChildElements.Count;

            return(documentContext);
        }