Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Jan 04, 2025 9:44 am

Hello
I use appendhtml that my table insert to my word file.
But when open word after process all td of table have 8pt afterspacing by default
I want to set this 0pt
Help me
I check paragraph of cells of table in debugging and afterspacing prop in format is 0 but i dont know how change to 8pt.

Solarispirozi
 
Posts: 1
Joined: Sat Jan 04, 2025 9:37 am

Mon Jan 06, 2025 7:36 am

Hello,

Thank you for your inquiry. According to your description, the afterpacing setting for the paragraph you added will inherit from your original document. You can modify it through the following settings.
Code: Select all
            String htmlText = "<table>\n.....";
            //Load file
            Document document = new Document();
            document.LoadFromFile(@"in.docx");
            Spire.Doc.Section sec = document.Sections[0];

            // Add a new paragraph to the section and append the HTML content to it.
            Spire.Doc.Documents.Paragraph para= sec.AddParagraph();
            para.Format.AfterSpacing = 0f;
            para.AppendHTML(htmlText);
           
            Spire.Doc.Table table = sec.Tables[0] as Spire.Doc.Table;
            foreach (Spire.Doc.TableRow row in table.Rows)
            {
                // Iterate through each cell in the row
                foreach (Spire.Doc.TableCell cell in row.Cells)
                {
                    // Iterate through each paragraph in the cell
                    foreach (Spire.Doc.Documents.Paragraph p in cell.Paragraphs)
                    {
                        p.Format.AfterSpacing = 0f;
                    }
                }
            }
            //save
            document.SaveToFile("out.docx", Spire.Doc.FileFormat.Docx);

If there are any other questions, please provide your original document and test code for further testing and investigation.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1362
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc