Setting FillType.SOLID sets the cell as FillType.GRADIENT

Hi,

When I try to set the cell background color to a solid type it always sets it as a gradient type. Here is the code I am using.

cell.getFillFormat().setType(FillType.SOLID);
cell.getFillFormat().setBackColor(Color.decode("#6095C1"));

Is this a known bug or do I need to set it some other way?

Thanks,
Parth

Hi Parth,

I have observed the part of code snippet shared by you and have not been able to identify whether you are looking for feature in case of PPT or PPTX. Please visit the example shared in this thread link for your convenience.

Many Thanks,

Hi Mudassir,

I am working with PPT (Presentaion). I can set all other fill types but while setting the filltype as SOLID it sets gradient to the ppt. Please let me know whether it's a bug or I need to do that some other way.

Thanks,

Parth

Hi Parth,


I have worked over the requirements shared by you and have generated the following code snippet for setting the cell color. Please share, if I may help you further in this regard.

public static void AddTable()
{
try
{
//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();


//Accessing a slide using its slide position
Slide slide = pres.getSlideByPosition(1);


//Setting table parameters
int xPosition=880;
int yPosition=1400;
int tableWidth=4000;
int tableHeight=500;
int columns=4;
int rows=4;
float borderWidth=2;


//Adding a new table to the slide using specified table parameters
com.aspose.slides.Table table=slide.getShapes().addTable(xPosition,yPosition,tableWidth,tableHeight,columns,rows,borderWidth,java.awt.Color.BLUE);


//Setting the alternative text for the table that can help in future to find
//and identify this specific table
table.setAlternativeText(“myTable”);


//Merging 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).getTextFrame();

com.aspose.slides.Cell tableCell=table.getCell(0,0);
tableCell.getFillFormat().setType(com.aspose.slides.FillType.SOLID);
// tableCell.getFillFormat().setForeColor(java.awt.Color.RED);
tableCell.getFillFormat().setForeColor(java.awt.Color.decode("#6095C1"));
int fil=tableCell.getFillFormat().getType();

//If text frame is not null then add some text to the cell
if(tf!=null)
{
tf.getParagraphs().get(0).getPortions().get(0).setText(“Welcome to Aspose.Slides for Java”);
}


//Writing the presentation as a PPT file
pres.write(new FileOutputStream(new File(“D:\Aspose Data\modified.ppt”)));
int ss=0;
}
catch(Exception ex)
{
System.out.println(ex.toString());
}

}

Many Thanks,

Thanks Mudassir,

Actually I was trying to set the cell Background color with setBackColor() method. Can you please tell me the difference between the two methods setForeColor() and setBackColor()?

Best,

Parth

Hi Parth,


I like to share that FillFormat class is actually generic class that has been used for fill formats of all shapes in PPT using Aspose.Slides. There may be some shapes that can have different Back and Fore color. But in case of Cell, we have only to set background color of cell and that is set by setForeColor(). Hope, this will answer your question.

Many Thanks,