private static Paragraph CreateParagraph(WordParagraph paragraph) { if (paragraph != null) { Paragraph docParagraph = new Paragraph(); docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); foreach (var run in paragraph.Texts) { Run docRun = new Run(); RunProperties properties = new RunProperties(); properties.AppendChild(new FontSize { Val = paragraph.TextProperties.Size }); if (paragraph.TextProperties.Bold) { properties.AppendChild(new Bold()); } docRun.AppendChild(properties); docRun.AppendChild(new Text { Text = run, Space = SpaceProcessingModeValues.Preserve }); docParagraph.AppendChild(docRun); } return(docParagraph); } return(null); }
/// <summary> /// Создание абзаца с текстом /// </summary> /// <param name="paragraph"></param> /// <returns></returns> private static Paragraph CreateParagraph(WordParagraph paragraph) { if (paragraph == null) { return(null); } Paragraph docParagraph = new Paragraph(); docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); for (int i = 0; i < paragraph.Texts.Count; i++) { Run docRun = new Run(); RunProperties properties = new RunProperties(); properties.AppendChild(new FontSize { Val = paragraph.TextProperties.Size }); if (paragraph.TextProperties.Bold) { properties.AppendChild(new Bold()); } docRun.AppendChild(properties); docRun.AppendChild(new Text { Text = " " + paragraph.Texts[i], Space = SpaceProcessingModeValues.Preserve }); docParagraph.AppendChild(docRun); } return(docParagraph); }
private static Run CreateBoldText(WordParagraph paragraph, int index) { Run docRun = new Run(); RunProperties properties = new RunProperties(); properties.AppendChild(new FontSize { Val = paragraph.TextProperties.Size }); properties.AppendChild(new Bold()); docRun.AppendChild(properties); docRun.AppendChild(new Text { Text = paragraph.Texts[index], Space = SpaceProcessingModeValues.Preserve }); return(docRun); }
public void TestWrite() { string file = Path.GetTempFileName() + ".doc"; using (WordDocument doc = WordDocument.CreateDocument()) { WordSection section = doc.GetAllSections()[0]; WordParagraph paragraph = section.CreateParagraph(); paragraph.Text = "Hello World"; WordFormatter formatter = paragraph.Formatter; formatter.Background = Color.Red; formatter.Foreground = Color.Yellow; formatter.Font = new Font("Courier New", 12, FontStyle.Underline | FontStyle.Bold); Assert.AreEqual(Color.FromArgb(0, 255, 0, 0), formatter.Background); Assert.AreEqual(Color.FromArgb(0, 255, 255, 0), formatter.Foreground); doc.Save(file); } }
public TestSequence(WordParagraph d) { Description = d; }