Example #1
0
        public void AddCustomStyle(FormatStyle customStyle)
        {
            if (customStyle == null)
                throw new ArgumentNullException("customStyle");
            if (string.IsNullOrEmpty(customStyle.StyleId))
                throw new ArgumentNullException("StyleId");
            if (string.IsNullOrEmpty(customStyle.Name))
                throw new ArgumentNullException("Name");

            StyleCreator styleCreator = new StyleCreator(this._package);
            styleCreator.AddCustomStyle(customStyle);
        }
Example #2
0
        internal void CreateTextParagraph(WordprocessingDocument package, string style, HorizontalAlignmentType alignment, string text, FormatStyle formatStyle)
        {
            Body body = package.MainDocumentPart.Document.Body;

            if (!string.IsNullOrEmpty(style) && !WordHelper.IsStyleIdInDocument(package, style)) {

                throw new System.ArgumentOutOfRangeException(style);
            }

            Run textRun = new Run();

            if (formatStyle != null) {

                // Get a reference to the RunProperties object.
                RunProperties runProperties = textRun.AppendChild(new RunProperties());

                if (formatStyle.IsBold) {

                    Bold bold = new Bold();
                    //bold.Val = OnOffValue.FromBoolean(true);
                    runProperties.AppendChild(bold);
                }
            }

            textRun.AppendChild(new Text(text));

            // Add a paragraph with a run and some text.
            Paragraph newParagraph = new Paragraph(textRun);

            // If the paragraph has no ParagraphProperties object, create one.
            WordHelper.CreateParagraphPropertiesIfNonExists(newParagraph);

            // Set paragraph alignment
            WordHelper.SetParagraphAlignment(newParagraph, alignment);

            if (!string.IsNullOrEmpty(style)) {

                // Get a reference to the ParagraphProperties object.
                ParagraphProperties pPr = newParagraph.ParagraphProperties;

                // If a ParagraphStyleId object doesn't exist, create one.
                if (pPr.ParagraphStyleId == null)
                    pPr.ParagraphStyleId = new ParagraphStyleId();

                // Set the style of the paragraph.
                pPr.ParagraphStyleId.Val = style;
            }

            // Append new paragraph
            body.AppendChild(newParagraph);
        }
Example #3
0
 public void CreateTextParagraph(WordprocessingDocument package, TextParagraphType paragraphType, HorizontalAlignmentType alignment, string text, FormatStyle formatStyle)
 {
     switch (paragraphType) {
         case TextParagraphType.Title:
             CreateTextParagraph(package, StyleCreator.TitleStyle, alignment, text, formatStyle);
             break;
         case TextParagraphType.Normal:
             CreateTextParagraph(package, StyleCreator.NormalStyle, alignment, text, formatStyle);
             break;
         case TextParagraphType.Heading1:
             CreateTextParagraph(package, StyleCreator.HeadingOneStyle, alignment, text, formatStyle);
             break;
         case TextParagraphType.Heading2:
             CreateTextParagraph(package, StyleCreator.HeadingTwoStyle, alignment, text, formatStyle);
             break;
         case TextParagraphType.Heading3:
             CreateTextParagraph(package, StyleCreator.HeadingThreeStyle, alignment, text, formatStyle);
             break;
         case TextParagraphType.None:
         default:
             CreateTextParagraph(package, string.Empty, alignment, text, formatStyle);
             break;
     }
 }
Example #4
0
        private Style ParseStyle(FormatStyle customStyle)
        {
            // Create a new paragraph style and specify some of the properties.
            Style style = new Style() {
                Type = StyleValues.Paragraph,
                StyleId = customStyle.StyleId,
                CustomStyle = true
            };

            StyleName styleName1 = new StyleName() { Val = customStyle.Name };

            BasedOn basedOn1 = new BasedOn() { Val = customStyle.BasedOn };

            NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle() { Val = customStyle.NextParagraphStyle };
            style.Append(styleName1);
            style.Append(basedOn1);
            style.Append(nextParagraphStyle1);

            // Create the StyleRunProperties object and specify some of the run properties.
            StyleRunProperties styleRunProperties1 = new StyleRunProperties();

            string color = string.Format("#{0:X2}{1:X2}{2:X2}",
                                         customStyle.Color.R,
                                         customStyle.Color.G,
                                         customStyle.Color.B);

            Color color1 = new Color() { Val = color };

            RunFonts font1 = new RunFonts() { Ascii = customStyle.FontName };

            // Specify a custom point size.
            FontSize fontSize1 = new FontSize() { Val = customStyle.FontSize.ToString() };

            if (customStyle.IsBold)
                styleRunProperties1.Append(new Bold());

            if (customStyle.HighlightColor != FormatStyle.HighlightColors.None)
                styleRunProperties1.Append(new Highlight() { Val = (HighlightColorValues)(int)customStyle.HighlightColor });

            styleRunProperties1.Append(color1);
            styleRunProperties1.Append(font1);
            styleRunProperties1.Append(fontSize1);

            if (customStyle.IsItalic)
                styleRunProperties1.Append(new Italic());

            style.Append(styleRunProperties1);

            return style;
        }
Example #5
0
        internal void AddCustomStyle(FormatStyle customStyle)
        {
            var newStyle = ParseStyle(customStyle);

            RegisterStyles(new Style[] { newStyle });
        }
Example #6
0
 public void CreateTextParagraph(TextParagraphType paragraphType, HorizontalAlignmentType alignment, string text, FormatStyle formatStyle)
 {
     var titleCreator = new ParagraphCreator();
     titleCreator.CreateTextParagraph(this._package, paragraphType, alignment, text, formatStyle);
 }
Example #7
0
 public void CreateTextParagraph(string styleName, string text, FormatStyle formatStyle)
 {
     var titleCreator = new ParagraphCreator();
     titleCreator.CreateTextParagraph(this._package, styleName, HorizontalAlignmentType.Left, text, formatStyle);
 }