Esempio n. 1
0
        public void AddParagraph()
        {
            WordprocessingDocument word = WordProcessingExtensions.WordDocument();

            word.AddParagraph(@"Parrado 1");
            Assert.True(!word.IsNotValid());
        }
Esempio n. 2
0
 /// <summary>
 /// Adds a set of paragraphs into the body of the given word document
 /// </summary>
 /// <param name="word">Word document reference</param>
 /// <param name="list">Collection of paragraphs</param>
 /// <returns>True or False</returns>
 public static void AddParagraphs(this WordprocessingDocument word, List <string> list)
 {
     if (word.IsNotValid() || list.IsNotValid())
     {
         return;
     }
     for (int x = 0; x < list.Count; x++)
     {
         word.AddParagraph(list.ElementAt(x));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Adds a text value as paragraph into the body of the given word document
        /// </summary>
        /// <param name="word">Word document reference</param>
        /// <param name="text">Paragraph text</param>
        /// <returns>True or False</returns>
        public static void AddParagraph(this WordprocessingDocument word, string text)
        {
            if (word.IsNotValid() || text.IsNotValid())
            {
                return;
            }
            //Bond the body of the document or else create a new one
            Body body = word.MainDocumentPart.Document.Body;
            //Add text to the body via paragraphs
            Paragraph paragraph = body.AppendChild(new Paragraph());
            Run       run       = paragraph.AppendChild(new Run());

            run.AppendChild(new Text(text));
            word.Save();
        }
Esempio n. 4
0
 /// <summary>
 /// Adds an image element into the body of the given word document
 /// </summary>
 /// <param name="word">Word document reference</param>
 /// <param name="stream">Stream containing the image data</param>
 /// <param name="imageType">Type of image</param>
 /// <returns>True or False</returns>
 public static bool AddImage(this WordprocessingDocument word, Stream stream, ImagePartType imageType = ImagePartType.Jpeg)
 {
     if (word.IsNotValid() || stream.IsNotValid())
     {
         return(false);
     }
     try
     {
         MainDocumentPart main      = word.MainDocumentPart;
         ImagePart        imagePart = main.AddImagePart(imageType);
         using (Stream s = stream)
         {
             imagePart.FeedData(s);
         }
         AddImageToBody(word, main.GetIdOfPart(imagePart));
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }