We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Need to add a table with multiple style

Hi,


I need to add a table to the slide with multiple styles to the cells as like the attached presentation.

Kindly share me the code snippet for the pptx.

Thanks in advance.
Laxmikanta

Hi Laxmikanta,

I have observed your requirements and like to share that you can manage to create the similar tables on your end by using Aspose.Slides. Please visit this documentation link to see how to add tables using Aspose.Slides. The every cell inside the table actually has a text frame in it and every text frame has collection of paragraphs inside that. Likewise, every paragraph has collection of portions inside it. There are certain properties of text that are set on paragraph levels like bullets and indents. There are many properties that are set for text on portion level like font height, font family, underline, hyperlink, boldness and color. Please visit the documentation link 1 and link 2 for your convenience. Please also visit this link for setting hyperlinks and this for more about portions and paragraphs. I am hopeful you will be able to figure out the use of properties on your end to achieve the desired results with information shared.

Many Thanks,

Hi Mudassir,


Please help me on how to set the vertical alignment=“Middle” to the cell of a table and how to set the row height of the table.

Thanks,
Laxmikanta

Hi Laxmikanta,


I have observed the requirements shared. Please try using following sample code on your end to serve the purpose.

public static void TestTable()
{
//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx();

//Access first slide
SlideEx sld = pres.Slides[0];

//Define columns with widths and rows with heights
double[] dblCols = { 50, 50, 50 };
double[] dblRows = { 50, 30, 30, 30, 30 };

//Add table shape to slide
int idx = sld.Shapes.AddTable(100, 50, dblCols, dblRows);
TableEx tbl = (TableEx)sld.Shapes[idx];

//Set border format for each cell
foreach (RowEx row in tbl.Rows)
{
row.MinimalHeight = 100;
foreach (CellEx cell in row)
{
cell.BorderTop.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderTop.Width = 5;

cell.BorderBottom.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderBottom.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderBottom.Width = 5;

cell.BorderLeft.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderLeft.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderLeft.Width = 5;

cell.BorderRight.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderRight.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderRight.Width = 5;


}
}

//Merge cells 1 & 2 of row 1
tbl.MergeCells(tbl[0, 0], tbl[1, 0], false);

//Add text to the merged cell
tbl[0, 0].TextFrame.Text = “Merged Cells”;

tbl[0, 0].TextAnchorType = TextAnchorTypeEx.Center;
//Write PPTX to Disk
pres.Write(“d:\Aspose Data\table.pptx”);
}

Many Thanks,