How to merge word table cells cells from c#?

  • Thread starter Thread starter YigalB
  • Start date Start date
Y

YigalB

Guest
Based on Jack's help from previous thread, I can create word file with table using code like:

static void Main(string[] args)
{
string path = "D:\\example.docx";
var doc = DocX.Create(path);
Table table = doc.AddTable(2, 6);
table.Alignment = Alignment.center;
table.Rows[0].Cells[0].Paragraphs.First().Append("ID");
table.Rows[0].Cells[1].Paragraphs.First().Append("first Name");
table.Rows[0].Cells[2].Paragraphs.First().Append("Sex");
table.Rows[0].Cells[3].Paragraphs.First().Append("Birthday");
table.Rows[0].Cells[4].Paragraphs.First().Append("Deadday");
table.Rows[0].Cells[5].Paragraphs.First().Append("LastName");
table.Rows[1].Cells[0].Paragraphs.First().Append("1001");
table.Rows[1].Cells[1].Paragraphs.First().Append("שמח");
table.Rows[1].Cells[2].Paragraphs.First().Append("male");
table.Rows[1].Cells[3].Paragraphs.First().Append("2019-03-05");
table.Rows[1].Cells[4].Paragraphs.First().Append("2119-03-05");
table.Rows[1].Cells[5].Paragraphs.First().Append("אל תדאג");
doc.InsertTable(table);
doc.Save();
Console.WriteLine("success");
Console.ReadKey();
}

What if I want to merge 2 cells? (before value is assigned)

For example, I would like first row to have 2 columns, second and third row to have 2 columns (merge the 2nd and 3rd), then 3 columns, etc?

Or in general, what methods can I use to control the table? (change cell's colors? change specific cell's fonts? etc)

Continue reading...
 
Back
Top