//Open a word Document instance
WordDocument document = new WordDocument("Template.docx");
//Create a new table.
WTable table = new WTable(document);
//sets lineWidth and color
table.TableFormat.Borders.LineWidth = 2f;
table.TableFormat.Borders.Color = Color.Black;
//Sets number of rows and columns.
table.ResetCells(2, 2);
//Selects the first row and appends text in each cell.
WTableRow row0 = table.Rows[0];
row0.Cells[0].AddParagraph().AppendText("1");
row0.Cells[0].CellFormat.Borders.LineWidth = 2f;
row0.Cells[0].CellFormat.Borders.Color = Color.Black;
row0.Cells[1].AddParagraph().AppendText("2");
//Selects the second row and appends text in each cell.
WTableRow row1 = table.Rows[1];
row1.Cells[0].AddParagraph().AppendText("4");
row1.Cells[1].AddParagraph().AppendText("5");
row1.Cells[1].CellFormat.Borders.LineWidth = 2f;
row1.Cells[1].CellFormat.Borders.Color = Color.Black;
//Creates TextBodyPart and insert the table.
TextBodyPart part = new TextBodyPart(document);
part.BodyItems.Insert(0, table);
// replaces the specified text with a part.
document.Replace("ReplaceText", part, false, false);
//Save document and dispose the Word document instance |