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.

Tue Apr 14, 2020 8:47 pm

Hi, per first, let me sorry about a lot of topic asking.
To be honest, I'm appreciating so much, but the documentation is a little confused.

Now, I need to insert a new table in a Word Document.
I find this solution:
Section section = new Section(document);
Table table = section.AddTable(true);
table.ResetCells(2, 3);

TableRow Row= table.Rows[0];
for (int i = 0; i <= 3; i++)
{
Paragraph p = Row.Cells[i].AddParagraph();
TextRange txtRange = p.AppendText("Text");
}


That's work!

To be honest, I don't know how that's working, because I just set a Row.Cell into a new Paragraph, and normally, I supposed to insert a Paragraph into a Table.Cell, but no problem, the main is it works xD

But in that cell, I need to insert more than one paragraph, something like this
Hello dear,
Thanks for help me with this stuffs
I aprecciate that!


Can I set a fews Paragraph for the same Row.Cell?
That'll not overwhite?
Example:
Paragraph p = Row.Cells[i].AddParagraph();
TextRange txtRange = p.AppendText("Text");
Paragraph p2 = Row.Cells[i].AddParagraph();
TextRange txtRange = p.AppendText("Text2");

Please, simplify as much you can the Demonstration Code, if the answer will have one xD

Really thank's!!!!!

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Wed Apr 15, 2020 3:47 am

Hello,

Thanks for your inquiry.
Yes, you can insert multiple paragraphs in one table cell. Please refer to the following code.
Code: Select all
    Document document = new Document();
    Section section = document.AddSection();
    Table table = section.AddTable(true);
    table.ResetCells(2, 2);
    TableCell cell = table.Rows[0].Cells[0];
    //Add the first paragraph
    Paragraph p = cell.AddParagraph();
    TextRange txtRange = p.AppendText("Hello dear,");
    txtRange.CharacterFormat.Bold = true;
    //Add the second paragraph
    p = cell.AddParagraph();
    p.AppendText("Thanks for help me with this stuffs.");
    //Add the third paragraph
    p = cell.AddParagraph();
    p.AppendText("I aprecciate that!"); 
    document.SaveToFile("result.docx", FileFormat.Docx);


My output:
output.png

If you have further questions, please feel free to let us know.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Apr 15, 2020 1:54 pm

Cool!
But have a way to insert a existed paragraph into a Cell?
Something like that
Paragraph p= new Paragraph(doc);
p.AppendText("Test");

p = cell.AddParagraph();

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Thu Apr 16, 2020 1:21 am

Hello,

Thanks for your response.
Below code is for your kind reference. If there is any other question, please feel free to let us know.
Code: Select all
    Paragraph p = new Paragraph(doc);
    p.AppendText("Test");
    cell.Paragraphs.Add(p);


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc