Setting Table Cell Color

I have been banging my head trying to set the background color of a table cell. Just some background before I jump into the problem, I have set up a pseudo html language for helping generate word documents and where I’m stuck is with tables. I’m utilizing coldfusion which is able to create and call methods on java objects. For some reason the background color doesn’t appear to stick on the cell once I call the ‘objCell.getCellFormat().clearFormatting()’ method. Thoughts? Here is the code (please note this is in colfusion, but the syntax is quasi java):

if (xmlParagraphNode.XmlName eq "table")
{
    objBuilder.pushFont();
    objBuilder.startTable();
    table_props = xmlParagraphNode.XmlAttributes;
    CreateFont(objBuilder.getFont(), table_props);
    if (IsValidAttr(xmlParagraphNode, "tr"))
    {
        CreateBorder(objBuilder.getRowFormat().getBorders(), table_props);
        if (IsValidAttr(table_props, "align"))
        {
            objBuilder.getRowFormat().setAlignment(CreateRowAlignment(table_props.align));
        }
        xmlRows = xmlParagraphNode.tr; //tr
        for (xmlRowIndex = 1; xmlRowIndex lte ArrayLen(xmlRows); xmlRowIndex = xmlRowIndex + 1)
        {
            xmlRow = xmlRows[xmlRowIndex];
            xmlCells = xmlRow.XmlChildren;
            row_props = xmlRow.XmlAttributes;
            objBuilder.pushFont();
            CreateFont(objBuilder.getFont(), row_props);
            for (xmlCellIndex = 1; xmlCellIndex lte ArrayLen(xmlCells); xmlCellIndex = xmlCellIndex + 1)
            {
                xmlCell = xmlCells[xmlCellIndex];
                cell_props = xmlCell.XmlAttributes;
                objBuilder.pushFont();
                CreateFont(objBuilder.getFont(), cell_props);
                objCell = objBuilder.insertCell();
                // Default the alignment to left
                objBuilder.getParagraphFormat().setAlignment(CreateParagraphAlignment("left"));
                if (IsValidAttr(cell_props, "align"))
                {
                    objBuilder.getParagraphFormat().setAlignment(CreateParagraphAlignment(cell_props.align));
                }
                if (IsValidAttr(cell_props, "width"))
                {
                    objCell.getCellFormat().setWidth(CreateInchToPoint(cell_props.width));
                }
                if (IsValidAttr(row_props, "backgroundcolor"))
                {
                    objCell.getCellFormat().getShading().setForegroundPatternColor(CreateColor(row_props.backgroundcolor));
                    objCell.getCellFormat().getShading().setBackgroundPatternColor(CreateColor(row_props.backgroundcolor));
                }
                objBuilder.write(xmlCell.xmlText);
                if (IsValidAttr(cell_props, "colspan"))
                {
                    objCellMerge = CreateObject('java', 'com.aspose.words.CellMerge');
                    objCell.getCellFormat().setHorizontalMerge(objCellMerge.FIRST);
                    for (colSpanIndex = 1; colSpanIndex lte cell_props.colspan - 1; colSpanIndex = colSpanIndex + 1)
                    {
                        objNewCell = objBuilder.insertCell();
                        objNewCell.getCellFormat().setHorizontalMerge(objCellMerge.Previous);
                    }
                }
                objCell.getCellFormat().clearFormatting();
                objBuilder.popFont();
            }
            objBuilder.popFont();
            objBuilder.endRow();
        }
    }
    objBuilder.endTable();
    objBuilder.popFont();
}

Hi

Thanks for your inquiry. objCell.getCellFormat().clearFormatting() reset all formatting you have set. This method should be used if you need to set default formation.
https://reference.aspose.com/words/java/com.aspose.words/cellformat/#clearFormatting
In your case, you should not call this method.
Best regards.