Exemplo n.º 1
0
        /// <summary>
        /// Adds the style for provided heading type if it's not already added.
        /// </summary>
        /// <param name="headingType"></param>
        public static void AddHeadingStyle(Model.HeadingType headingType)
        {
            if (IsStylePresent(StyleIds.GetStyleId(headingType))) {
                return;
            }

            int outlineLevel;

            switch (headingType)
            {
                case DocGen.ObjectModel.HeadingType.H1:
                    outlineLevel = 0;
                    break;
                case DocGen.ObjectModel.HeadingType.H2:
                    outlineLevel = 1;
                    break;
                case DocGen.ObjectModel.HeadingType.H3:
                    outlineLevel = 2;
                    break;
                case DocGen.ObjectModel.HeadingType.H4:
                    outlineLevel = 3;
                    break;
                case DocGen.ObjectModel.HeadingType.H5:
                    outlineLevel = 4;
                    break;
                case DocGen.ObjectModel.HeadingType.H6:
                    outlineLevel = 5;
                    break;
                default:
                    throw new NotImplementedException(headingType + ": Enum value not added");
            }

            Word.Styles styles =  DocumentPackager.GetInstance().GetStylePart().Styles;

            Word.Style style1 = new Word.Style() { Type = Word.StyleValues.Paragraph, StyleId = StyleIds.GetStyleId(headingType) };
            Word.BasedOn basedOn1 = new Word.BasedOn() { Val = "Normal" };

            Word.StyleParagraphProperties styleParagraphProperties1 = new Word.StyleParagraphProperties();
            Word.KeepNext keepNext1 = new Word.KeepNext();
            Word.KeepLines keepLines1 = new Word.KeepLines();
            Word.SpacingBetweenLines spacingBetweenLines1 = new Word.SpacingBetweenLines() { Before = "480", After = "0" };
            Word.OutlineLevel outlineLevel1 = new Word.OutlineLevel() { Val = outlineLevel };

            styleParagraphProperties1.Append(keepNext1);
            styleParagraphProperties1.Append(keepLines1);
            styleParagraphProperties1.Append(spacingBetweenLines1);
            styleParagraphProperties1.Append(outlineLevel1);

            style1.Append(basedOn1);
            style1.Append(styleParagraphProperties1);

            // Add the style to the styles part.
            styles.Append(style1);
        }
Exemplo n.º 2
0
        private static void AddNewStyle(StyleDefinitionsPart styleDefinitionsPart, string styleid, string stylename)
        {
            // Get access to the root element of the styles part.
            Word.Styles styles = styleDefinitionsPart.Styles;

            Word.Style style1 = new Word.Style() { Type = Word.StyleValues.Paragraph, StyleId = "Heading1" };
            Word.StyleName styleName1 = new Word.StyleName() { Val = "heading 1" };
            Word.BasedOn basedOn1 = new Word.BasedOn() { Val = "Normal" };

            Word.StyleParagraphProperties styleParagraphProperties1 = new Word.StyleParagraphProperties();
            Word.KeepNext keepNext1 = new Word.KeepNext();
            Word.KeepLines keepLines1 = new Word.KeepLines();
            Word.SpacingBetweenLines spacingBetweenLines1 = new Word.SpacingBetweenLines() { Before = "480", After = "0" };
            Word.OutlineLevel outlineLevel1 = new Word.OutlineLevel() { Val = 0 };

            styleParagraphProperties1.Append(keepNext1);
            styleParagraphProperties1.Append(keepLines1);
            styleParagraphProperties1.Append(spacingBetweenLines1);
            styleParagraphProperties1.Append(outlineLevel1);

            style1.Append(styleName1);
            style1.Append(basedOn1);
            style1.Append(styleParagraphProperties1);

            // Add the style to the styles part.
            styles.Append(style1);
        }