Unable to change table cell color after inserting an HTML table

I am working on an application where we have some content that is provided by our users as HTML and that content can contain HTML. If we insert some HTML in an Aspose Word Document that contains a table, it seems to prevent us from changing the color of future tables created directly without HTML.

Here’s a repro-case:

String html = "<table><tbody><tr><td style='background: red'>Red HTML</td></tr></tbody></table>";

DocumentBuilder docBuilder = new DocumentBuilder();

docBuilder.insertHtml(html);

docBuilder.insertBreak(BreakType.LINE_BREAK);

docBuilder.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);

docBuilder.startTable();
Cell cell = docBuilder.insertCell();
docBuilder.write("I should be blue, green or yellow");
docBuilder.endRow();
docBuilder.endTable();

cell.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
docBuilder.getCellFormat().getShading().setBackgroundPatternColor(Color.YELLOW);

docBuilder.getDocument().save("test.doc");

In this code, an HTML table is inserted with a cell with a red background. Then a second table is inserted but I can’t do anything to get the cells in this table to not be red. As you can see, I’ve tried using the CellFormat property on the DocumentBuilder both before and after as well as the CellFormat on the cell itself. In the above, the code that tries to set the cell color to blue and then green and then yellow, but none of those work. The cell remains red.

If I comment out the insertHtml call, then I get a green cell as I would expect.

I am using Aspose.Words 2.4.2 for JDK 1.5.

Hello Damon!
Thank you for your interesting case.
I have reproduced it but this is not a defect. MS Word shading is defined with two pattern colors and shading type (texture). When you specify background in HTML it becomes foreground color of solid shading (TEXTURE_SOLID). After that you are trying to override background pattern color that is evidently ignored. Please switch to using setForegroundPatternColor. You can also change texture to TEXTURE_NONE with calling setTexture. In this case visible background will be sensitive to background pattern color. The same happens when you comment out insertHtml call.
You might be a bit confused with the fact that background can be filled with foreground color. In general two colors are combined according to the rule given by texture. TEXTURE_SOLID and TEXTURE_NONE mean “fill with foreground color” and “fill with background color” correspondingly. They are the particular cases using only one color and ignoring another.
Regards,

Thank you very much, that did the trick.