Document Builder Table background color

Hi,

How to give gradient background color for document builder table?

Hi there,


Thanks for your inquiry. I am afraid currently Aspose.Words does not support gradient background color. We have logged a new feature request WORDSNET-15458 for your requirement. We will appreciate it if you please share a sample expected document here, it will help us in investigation and implementation of the feature.

Best Regards,

@anupuga,

Thanks for your patience. In reference to above issue, there is the Shading class allowing you to set background color of a table cell or paragraph, you can use various shading colors and textures. Please check this sample code to create a table with 4 cells having different shading, hopefully it will help you to accomplish the task.

com.aspose.words.Document doc = new com.aspose.words.Document();
 
DocumentBuilder builder = new DocumentBuilder(doc);
 
builder.startTable();
 
builder.insertCell();
 
builder.getCellFormat().getShading().setTexture(TextureIndex.TEXTURE_SOLID);
 
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);
 
builder.getCellFormat().getShading().setForegroundPatternColor(Color.BLUE);
 
builder.insertCell();
 
builder.getCellFormat().getShading().setTexture(TextureIndex.TEXTURE_DIAGONAL_CROSS);
 
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.YELLOW);
 
builder.getCellFormat().getShading().setForegroundPatternColor(Color.PINK);
 
builder.endRow();
 
builder.insertCell();
 
builder.getCellFormat().getShading().setTexture(TextureIndex.TEXTURE_50_PERCENT);
 
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.CYAN);
 
builder.getCellFormat().getShading().setForegroundPatternColor(Color.MAGENTA);
 
builder.insertCell();
 
builder.getCellFormat().getShading().setTexture(TextureIndex.TEXTURE_HORIZONTAL);
 
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
 
builder.getCellFormat().getShading().setForegroundPatternColor(Color.LIGHT_GRAY);
 
builder.endRow();
 
builder.endTable();
 
doc.save("out.docx");

Best Regards,