Table table = new Table(); // Create a new row. TableRow row = new TableRow(); // Create a new cell and add a paragraph of text. TableCell cell = new TableCell(); Paragraph para = new Paragraph("This is the first cell."); cell.AddParagraph(para); // Add the cell to the row and the row to the table. row.Cells.Add(cell); table.Rows.Add(row);
Table table = new Table(); // Create a new row. TableRow row = new TableRow(); // Create a new cell and add two paragraphs of text. TableCell cell = new TableCell(); Paragraph para1 = new Paragraph("This is the first paragraph."); Paragraph para2 = new Paragraph("This is the second paragraph."); cell.AddParagraph(para1); cell.AddParagraph(para2); // Add the cell to the row and the row to the table. row.Cells.Add(cell); table.Rows.Add(row);This example is similar to the previous one, but we are adding two paragraphs of text to the same cell instead of just one. We do this by calling the AddParagraph method on the cell object twice, each time passing in a different paragraph object. The package library for these examples is most likely the DocumentFormat.OpenXml package, which provides a set of classes for working with OpenXML documents in C#. These examples are using the Table, TableRow, TableCell, and Paragraph classes from this package.