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

Free Support Forum - aspose.com

How to set RGB colours in a table?


I am trying to set the colors of a table cell background and font to particular RGB values with this code. But it only sets bright red - see attached! to bits of it. So my question is what is the syntax to set the RGB values of a cell background an the font.:

pptxTableCell = oTable(intCount, intRow + intStart)

intRangeColourRed = Int32.Parse(ColourRow(0).ToString)

intRangeColourGreen = Int32.Parse(ColourRow(1).ToString)

intRangeColourBlue = Int32.Parse(ColourRow(2).ToString)

intFontColourRed = Int32.Parse(ColourRow(3).ToString)

intFontColourGreen = Int32.Parse(ColourRow(4).ToString)

intFontColourBlue = Int32.Parse(ColourRow(5).ToString)

pptxTableCell.FillFormat.FillType = FillTypeEx.Solid

pptxTableCell.FillFormat.SolidFillColor.ColorType = ColorTypeEx.RGBPercentage

pptxTableCell.FillFormat.SolidFillColor.FloatR = CType(intRangeColourRed, Single)

pptxTableCell.FillFormat.SolidFillColor.FloatG = CType(intRangeColourGreen, Single)

pptxTableCell.FillFormat.SolidFillColor.FloatB = CType(intRangeColourBlue, Single)

pptxTableCell.TextFrame.Text = Right(sCurRowVal, Len(sCurRowVal) - 8)

pptxTableCell.TextFrame.Paragraphs(0).Portions(0).FillFormat.FillType = FillTypeEx.Solid

pptxTableCell.TextFrame.Paragraphs(0).Portions(0).FillFormat.SolidFillColor.ColorType = ColorTypeEx.RGBPercentage

pptxTableCell.TextFrame.Paragraphs(0).Portions(0).FillFormat.SolidFillColor.FloatR = CType(intFontColourRed, Single)

pptxTableCell.TextFrame.Paragraphs(0).Portions(0).FillFormat.SolidFillColor.FloatG = CType(intFontColourGreen, Single)

pptxTableCell.TextFrame.Paragraphs(0).Portions(0).FillFormat.SolidFillColor.FloatB = CType(intFontColourBlue, Single)


I have observed the requirements shared by you and suggest you to please try using the following sample code. Please share, if I may help you further in this regard.

Public Shared Sub TableFormatting()
‘Instantiate PresentationEx class that represents PPTX file
Dim pres As New PresentationEx()

‘Access first slide
Dim sld As SlideEx = pres.Slides(0)

‘Define columns with widths and rows with heights
Dim dblCols() As Double = {50, 50, 50}
Dim dblRows() As Double = {50, 30, 30, 30, 30}

‘Add table shape to slide
Dim idx As Integer = sld.Shapes.AddTable(100, 50, dblCols, dblRows)
Dim tbl As TableEx = CType(sld.Shapes(idx), TableEx)

‘Add text to the merged cell
tbl(0, 0).TextFrame.Text = “Merged Cells”
Dim pptxTableCell As CellEx = tbl(0, 0)

Dim intRangeColourRed As Integer = 255
Dim intRangeColourGreen As Integer = 0
Dim intRangeColourBlue As Integer = 255

Dim intFontColourRed As Integer = 0
Dim intFontColourGreen As Integer = 255
Dim intFontColourBlue As Integer = 0

Dim fillColor As System.Drawing.Color = New System.Drawing.Color().FromArgb(255, intRangeColourRed, intRangeColourGreen, intRangeColourBlue)
Dim fontColor As System.Drawing.Color = New System.Drawing.Color().FromArgb(255, intFontColourRed, intFontColourGreen, intFontColourBlue)

pptxTableCell.FillFormat.FillType = FillTypeEx.Solid
pptxTableCell.FillFormat.SolidFillColor.Color = fillColor

pptxTableCell.TextFrame.Paragraphs(0).Portions(0).PortionFormat.FillFormat.FillType = FillTypeEx.Solid
pptxTableCell.TextFrame.Paragraphs(0).Portions(0).PortionFormat.FillFormat.SolidFillColor.ColorType = ColorTypeEx.RGB
pptxTableCell.TextFrame.Paragraphs(0).Portions(0).PortionFormat.FillFormat.SolidFillColor.Color = fontColor
'Write PPTX to Disk
pres.Write(“D:\Aspose Data\table.pptx”)

End Sub

Many Thanks,


That's perfect! Worked a charm thanks.