How to Center Align Table

Hi, I would like to center align a table after it has been created, can this be done using aspose slides? Kind Regards

1 Like

Hi Faisal,

I have observed your requirement and it seems that you are probably looking for option to set the text alignment of contents inside the table cells to center. Please try using the following sample code on your end to serve the purpose.

public static void TestTableVertical()
{

Presentation pres = new Presentation(“d:\Aspose Data\Vertical.pptx”);
//Accessing a slide using its slide position
ISlide slide = pres.Slides [0];;
for (int i = 0; i < slide.Shapes.Count; i++)
{
if (slide.Shapes[i] is ITable)
{
ITable tbl = (ITable)slide.Shapes[i]; ;

for (int j = 0; j < tbl.Rows.Count; j++)
{
for (int k = 0; k < tbl.Columns.Count; k++)
{

ICell cell = tbl[k, j];
ITextFrame tf = tbl[k, j].TextFrame;
tf.Paragraphs[0].ParagraphFormat.Alignment = TextAlignment.Center;

tf.Text = “Welcome”;

}

}
}
}
pres.Save(“D:\Aspose Data\TestCenter.pptx”,SaveFormat.Pptx);
}


Many Thanks,

Hi Mudassir, thank you for the quick reply! However I am wanting to align the table for example I am using Microsoft Powerpoint 2013 and if you select the table you are working with - goto Layout tab, you can click on “Align” and have options on how to choose how to align your table e.g “Align Left”, “Align Right”. I ask this because there is a requirement from a client wanting tables center aligned. Hope you can help. Thanks again.

Hi Faisal,

Thanks for your further elaboration. I have verified from PowerPoint that when you set the alignment either to left, right or center on table level, it gets set for every cell inside the table. On back end, even MS PowerPoint sets the alignment of each cell to selected alignment individually. You do the same using Aspose.Slides and the code sample shared in my last post iterates through every cell and sets the alignment of the cell to selected one. I hope this will clarify the concept.

Please share, if I may help you further in this regard.

Many Thanks,

A post was split to a new topic: How to Align a Table to the Center?