Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue with WOrd Table SetParagrahp #28

@rikthefrog

Description

@rikthefrog

When a paragraph is added to a cell the text is also created outside the table as a separate paragraph.

           XWPFDocument document = null;
            var parList = new List<XWPFParagraph>();
            try
            {
                using (FileStream file = new FileStream("C:\\Temp\\TechSpec_Documentation.docx", FileMode.Open, FileAccess.Read))
                {
                    document = new XWPFDocument(file);
                    
                    foreach (var paragraph in document.Paragraphs)
                    {
                        var par = paragraph.Style;
                        if (paragraph.Style == "Heading1")
                        {
                            parList.Add(paragraph);
                        }
                        
                    }
                }
            }
            catch (Exception e)
            {

            } 
            XWPFParagraph p1 = document.CreateParagraph();

            XWPFRun r3 = p1.CreateRun();
            r3.IsBold= true;
            r3.SetText("The quick brown fox");
            r3.IsBold= true;
            r3.SetFontFamily("Courier", FontCharRange.Ascii);
            r3.SetUnderline(UnderlinePatterns.DotDotDash);
            r3.SetTextPosition(100);

            table1.GetRow(0).GetCell(0).SetParagraph(p1);
            var sw = new FileStream("C:\\Temp\\TechSpec_ReleaseDocumentation2.docx", FileMode.Create);


            table1.GetRow(2).GetCell(2).SetText("only text");
            document.Write(sw);
            sw.Close();

image

Is there something changed as in the example files this the way shown to add a paragraph to a table cell.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions