예제 #1
0
        public Word.Paragraph GenerateParagraph(string val, bool bold = false, string sz = "12", string s = "style22", string f = "Courier New", Word.JustificationValues align = Word.JustificationValues.Left)
        {
            Word.ParagraphStyleId pstyle = new Word.ParagraphStyleId {
                Val = s
            };
            Word.Justification jut = new Word.Justification {
                Val = new EnumValue <Word.JustificationValues>(align)
            };
            Word.ParagraphProperties pprop = new Word.ParagraphProperties(pstyle, jut);

            Word.RunProperties rprop = new Word.RunProperties(
                new Word.RunFonts {
                Ascii = f, ComplexScript = f, HighAnsi = f
            },
                new Word.Bold {
                Val = new OnOffValue(bold)
            },
                new Word.BoldComplexScript {
                Val = new OnOffValue(bold)
            },
                new Word.FontSize {
                Val = sz
            });

            Word.Text text = new Word.Text(val);
            Word.Run  run  = new Word.Run(rprop, text);

            return(new Word.Paragraph(pprop, run));
        }
예제 #2
0
 protected word.Paragraph GetParagraph(string text, word.ParagraphStyleId styleID = null)
 {
     word.Paragraph paragraph = new word.Paragraph();
     paragraph.Append(new word.Run(new word.Text(text)));
     if (styleID != null)
     {
         paragraph.ParagraphProperties = new word.ParagraphProperties
         {
             ParagraphStyleId = styleID
         };
     }
     return(paragraph);
 }
        public static DocumentFormat.OpenXml.OpenXmlElement[] GetFormattedChapter(Chapter chapter)
        {
            if(!stylesAdded) StyleCreator.AddStylePart();

            List<OpenXmlElement> result = new List<OpenXmlElement>();

            //Setting up Heading style
            Word.ParagraphProperties paraProps = new Word.ParagraphProperties();
            Word.ParagraphStyleId style = new Word.ParagraphStyleId()
            {
                Val = "Heading1"
            };
            paraProps.Append(style);

            //Adding chapter title
            Word.Paragraph para = new Word.Paragraph();
            Word.Run run = new Word.Run();
            Word.Text text = new Word.Text()
            {
                Text = chapter.Title
            };

            run.Append(text);
            para.Append(paraProps);
            para.Append(run);

            result.Add(para);

            //Add all child elements
            foreach (Element element in chapter.SubElements)
            {
                if (element.GetElementType() == ElementType.MultiColumnSection)
                {
                    result.AddRange(MultiColumnSectionFormatter.GetFormattedSection((MultiColumnSection)element));
                }
                else if (element.GetElementType() == ElementType.Section) result.AddRange(SectionFormatter.GetFormattedSection((Section)element));

                else throw new InvalidSubFeatureException( chapter.GetElementType().ToString() , element.GetElementType().ToString());
            }

            return result.ToArray();
        }