Set font to every cells in a table

Hi,

I've created a table and set the background cell color and font of each cell. Do I have to set the color and font for every cell? It's a very lengthly code. Am I doing the right way? And how do I set the height of the row?

//Setting table parameters

int xPosition = 880;

int yPosition = 1000;

int tableWidth = 4000;

int tableHeight = 500;

int columns = 2;

int rows = 2;

double borderWidth = 1;

//Adding a new table to the slide

Table table = slide.Shapes.AddTable(xPosition, yPosition, tableWidth,

tableHeight, columns, rows, borderWidth, System.Drawing.Color.Black);

//Setting the alternative text for the table that can help in future to find

//and identify this specific table

table.AlternativeText = "Table";

//Merging first two cells

table.MergeCells(table.GetCell(0, 0), table.GetCell(1, 0));

//Accessing the text frame of the first cell of the first row in the table

TextFrame tf = table.GetCell(0, 0).TextFrame;

tf.Paragraphs[0].Portions[0].Text = "Table of Figures";

tf.Paragraphs[0].Alignment = TextAlignment.Center;

Portion port = tf.Paragraphs[0].Portions[0];

port.FontBold = true;

port.FontHeight = 12;

TextFrame tfTitle1 = table.GetCell(0, 1).TextFrame;

table.GetCell(0, 1).FillFormat.Type = FillType.Solid;

table.GetCell(0, 1).FillFormat.ForeColor = System.Drawing.Color.FromArgb(1, 131, 183);

tfTitle1.Paragraphs[0].Portions[0].Text = "Name";

Portion portTitle1 = tfTitle1.Paragraphs[0].Portions[0];

portTitle1.FontBold = true;

portTitle1.FontColor = System.Drawing.Color.White;

portTitle1.FontHeight = 12;

TextFrame tfTitle2 = table.GetCell(1, 1).TextFrame;

table.GetCell(1, 1).FillFormat.Type = FillType.Solid;

table.GetCell(1, 1).FillFormat.ForeColor = System.Drawing.Color.FromArgb(1, 131, 183);

tfTitle2.Paragraphs[0].Alignment = TextAlignment.Center;

tfTitle2.Paragraphs[0].Portions[0].Text = "Count";

Portion portTitle2 = tfTitle2.Paragraphs[0].Portions[0];

portTitle2.FontBold = true;

portTitle2.FontColor = System.Drawing.Color.White;

portTitle2.FontHeight = 12;

int startRow = 2;

int total = 0;

for (int i = 0; i < arrColumnAndData.GetUpperBound(0); i++)

{

string name = arrColumnAndData[i, 0];

string value = arrColumnAndData[i, 1];

total = total + Convert.ToInt32(value);

table.AddRow();

TextFrame tfName = table.GetCell(0, startRow).TextFrame;

TextFrame tfValue = table.GetCell(1, startRow).TextFrame;

tfName.Paragraphs[0].Portions[0].Text = name;

tfValue.Paragraphs[0].Portions[0].Text = value;

tfValue.Paragraphs[0].Alignment = TextAlignment.Center;

table.GetCell(0, startRow).FillFormat.Type = FillType.Solid;

table.GetCell(0, startRow).FillFormat.ForeColor = System.Drawing.Color.White;

Portion portBody1 = tfName.Paragraphs[0].Portions[0];

portBody1.FontColor = System.Drawing.Color.Black;

portBody1.FontHeight = 12;

portBody1.FontBold = false;

table.GetCell(1, startRow).FillFormat.Type = FillType.Solid;

table.GetCell(1, startRow).FillFormat.ForeColor = System.Drawing.Color.White;

Portion portBody2 = tfValue.Paragraphs[0].Portions[0];

portBody2.FontColor = System.Drawing.Color.Black;

portBody2.FontHeight = 12;

portBody2.FontBold = false;

startRow++;

}

// add total

table.AddRow();

TextFrame tfTotal1 = table.GetCell(0, startRow).TextFrame;

tfTotal1.Paragraphs[0].Portions[0].Text = "Total";

table.GetCell(0, startRow).FillFormat.Type = FillType.Solid;

table.GetCell(0, startRow).FillFormat.ForeColor = System.Drawing.Color.FromArgb(1, 131, 183);

Portion portTotal1 = tfTotal1.Paragraphs[0].Portions[0];

portTotal1.FontBold = true;

portTotal1.FontColor = System.Drawing.Color.White;

portTotal1.FontHeight = 12;

TextFrame tfTotal2 = table.GetCell(1, startRow).TextFrame;

tfTotal2.Paragraphs[0].Portions[0].Text = total.ToString();

tfTotal2.Paragraphs[0].Alignment = TextAlignment.Center;

table.GetCell(1, startRow).FillFormat.Type = FillType.Solid;

table.GetCell(1, startRow).FillFormat.ForeColor = System.Drawing.Color.FromArgb(1, 131, 183);

Portion portTotal2 = tfTotal2.Paragraphs[0].Portions[0];

portTotal2.FontBold = true;

portTotal2.FontColor = System.Drawing.Color.White;

portTotal2.FontHeight = 12;

Dear faerie,

Thanks for considering Aspose.Slides for .NET

Yes, you are setting them in a right way and there is no other way to set them. To change row height, you can use Table.SetRowHeight method.