Set The Color Text in a Table Cell

Hello there,


I load a slide from disk with a table in it. The text in the table has font color set to white.
I set the text of a cell through code. The Text in the cell is set, but the format is lost. I am trying to re-set the color per code.

I am using the following code

table[i, i].TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.White;

Alternatively

table[i, i].TextFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.White;

Both don’t change the color of the text.

I see in the documentation a property FontColor but I cannot find it.

I would really appreciate your help on this issue.

Best regards.

Hi Nasser,


I have observed the requirement shared by you and suggest you to please try using the sample code given over this documentation link by using Aspose.Slides for .NET 15.1.0. If there is still an issue then please share the working sample application and generated output reproducing the issue. I will investigate the issue further on my end to help you out.

Many Thanks,

Hello Mudassir,


the requirment is to change the color of a text portion that is part of a table. This doens’t work. Please use my code sample from 606422. Please try to set the color of a text portion and you will see that it is not possible.

Again, this works in version 14. I can set color, FontHeight, Boldness, etc. All works.

Version 15 has problems dealing with table cells. Could you please confirm this and treat this issue accordingly? Version 15 solves problems that I need in my work, but breaks text functionality in tables.

Best regards, thank you for your help!




Hi Nasseer,

I like to share that there is no issue while setting the font color. The issue that you are only setting the color but not defining the FillType. You need to first set the FillType then the color. Please try using the following sample code to serve the purpose.


public static void FormatTableText()
{
String path = @“D:\Aspose Data”;
using (Presentation pres = new Presentation())
{

//Access first slide
ISlide 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
ITable tbl = sld.Shapes.AddTable(100, 50, dblCols, dblRows);

//Set border format for each cell
foreach (IRow row in tbl.Rows)
foreach (ICell cell in row)
{
cell.BorderTop.FillFormat.FillType = FillType.Solid;
cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderTop.Width = 5;

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

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

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

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

tbl[0, 0].FillFormat.FillType = FillType.Solid;
tbl[0, 0].FillFormat.SolidFillColor.Color = Color.Red;


ITextFrame txtFrame = tbl[0, 0].TextFrame;

txtFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillType.Solid;
txtFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.White;


//Write PPTX to Disk
pres.Save(path + “table.pptx”, SaveFormat.Pptx);
}
}

I hope this will be helpful.

Many Thanks,