Row properties of Table

Hi,

1) I would like to apply the properties (Background & text properties) of a particular row to some other row. Could you tell me how this is possible? with reference to screen shot, i would like to apply the header formatting to the total rows.

2) I would like to know how to make a text rotated. i.e as shown in screenshot. (bangalore, chennai, grand total etc)

Regards,

Kiran.

Hi Kiran,

I have observed both requirements shared by you. You can set the text direction for the cell by using TextVerticalTypeEx enumeration. I have shared the sample project whereby I have shared how to use property and set the text vertically.

Now, coming to first part of your query regarding applying table row (background + text properties) properties from one to another row. I regret to share that there is no direct method available in this regard and one has to implement his own logic in this regard to map properties from one row to another. Aspose.Slides does offer the row or columns cloning feature that you can use generate new rows. The row cloning means to generate a new row based on selected row that you want to clone. This way the entire properties of the row will get copied from source row to new row and you can then add the text in the cells of that row on paragraph level. I have shared this approach in following sample code.

public static void GenPptxTable()
{
PresentationEx pres = new PresentationEx();
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];

tbl.HorizontalBanding = true;
tbl.FirstRow = false;


//setting fill format for first row
tbl[0, 0].FillFormat.FillType = FillTypeEx.Solid;
tbl[0, 0].FillFormat.SolidFillColor.Color = Color.Green;


//Set border format for each cell
foreach (RowEx row in tbl.Rows)
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";

//setting vertical text
tbl[0, 0].TextVerticalType = TextVerticalTypeEx.Vertical;


//Cloning row
tbl.Rows.InsertClone(tbl.Rows.Count,tbl.Rows[0], true);


//Write PPTX to Disk
pres.Write("d:\\Aspose Data\\table.pptx");


}


The other option is access every cell inside the desired row and copies the properties on cell level, paragraph level & portions level and apply them on respective cell in desired row. Please not those properties inside the row are defined in cells of row rather than row. Please use this documentation link as reference for copying paragraph and portions. You can devise your own logic for copying the other related properties of cells as well.

Many Thanks,