Using Aspose.Words 19.2 in Java.
I have a document which contains a styled table. The table header row contains white text. I need to be able to read the text color from this DOCX, and am unable to do so. I’ve tried looking in the following spots for a White color: cell shading (foreground), paragraph shading (foreground), run font color, run font shading (foreground). All return rgb 0,0,0; not 255, 255, 255 as expected.
Additionally, I am using expandTableStylesToDirectFormatting()
but I don’t know that it’s doing anything.
I’ve attached a sample project that reproduces this (includes a sample DOCX file in resources). Can you verify whether this is a bug, or whether I’m just looking for the text color in the wrong place?
Thanks!
Repro source:
public static void main(String[] args) throws Exception {
byte[] docx = IOUtils.toByteArray(getSystemResourceAsStream("table_header_text_color.docx"));
Document document = new Document(new ByteArrayInputStream(docx));
document.expandTableStylesToDirectFormatting(); // Unsure of whether this has an effect, but worth trying.
Table table = document.getFirstSection().getBody().getTables().get(0);
Row row = table.getFirstRow();
Cell cell = row.getFirstCell();
System.out.println("Cell text: " + cell.getText());
Color colorWhite = Color.WHITE;
// Expect white color to be found somewhere. Why doesn't it exist in any of these spots?
System.out.println("Expecting: " + colorWhite);
// Check cell properties.
System.out.println("Cell Shading (Foreground): " + cell.getCellFormat().getShading().getForegroundPatternColor());
// Check paragraph properties
for(Paragraph paragraph : cell.getParagraphs()) {
System.out.println("Paragraph Shading (Foreground):" + paragraph.getParagraphFormat().getShading().getForegroundPatternColor());
// Check run properties
for(Run run : paragraph.getRuns()) {
System.out.println("Run Font Color: " + run.getFont().getColor());
System.out.println("Run Shading (Foreground): " + run.getFont().getShading().getForegroundPatternColor());
}
}
}
Attachment:
asposebug.zip (87.8 KB)