How to set vertical and horizontal alignment in table's cell using C#

Hi

i have the following code to loop a table

for (int rowcnt = 0; rowcnt < NewTable.Rows.Count; rowcnt++)

{

for (int colcnt = 0; colcnt < NewTable.Rows[rowcnt].Cells.Count; colcnt++)

{

----Here i need to assign the vertical as well as the horizontal align for a cell

that is NewTable.Rows[rowcnt].Cells[colcnt].somthing

}

}

Hi Ajeesh,


Thanks for your inquiry. According to my understanding you want to apply the cell formatting in the word document. Aspose has already provided a detailed solution of the problem that you are facing. You can definitely apply horizontal and vertical cell formatting. Please refer to the following article

Table Formatting in C#|Aspose.Words for .NET

I hope this will resolve your issue. However, please feel free to reply in case of any confusions or issues.

Best Regards,

Amir Ghias

Hi Ajeesh,

Thanks for your query. Please use the following code snippet to set the vertical and horizontal text alignment. Hope this answers your query. Please let us know, If you have any more queries.

Document doc = new Document(MyDir + "in.docx");

Node[] tables = doc.GetChildNodes(NodeType.Table, true).ToArray();

Table table = (Table)tables[0];

foreach (Row row in table.Rows)

{

foreach (Cell cell in row.Cells)

{

cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;

foreach (Paragraph paragraph in cell.Paragraphs)

{

paragraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;

}

}

}

doc.Save(MyDir + "Out.doc");