What property dictates a cell's background colour?

Hi,

I am trying to apply a table style to a table. The problem I am having is that for some styles, after applying the style, the background colour of the cells in Word doesn’t match the background colour of CellFormat.Shading.BackgroundPatternColor and I can’t work out what other property is overwriting this colour.

For example:

Table table = … // Some code to retrieve my table from the document
table.Style = style; // “Dark List Accent 3” for example

Cell cell = … // Code to find a cell in the middle of the table

If I now check cell.CellFormat.Shading.BackgroundPatternColor, the colour the will be listed as green
But then if I save the document here and open it the cells are actually grey
The correct colour is grey (as this is what the style looks like in Word), so I don’t know why cell.CellFormat.Shading.BackgroundPatternColor is green
document.ExpandTableStylesToDirectFormatting() doesn’t have an effect either

Some styles work fine and have matching cell.CellFormat.Shading.BackgroundPatternColor colours
But for some such as “Dark List Accent 3”, “Colorful List Accent 5”, “Colorful List Accent 4”, “Colorful Grid Accent 3” some colours don’t appear as I’d expect

On the left are the colours dictated by cell.CellFormat.Shading.BackgroundPatternColor, and on the right are the correct colours
colours.png (275 Bytes)

So my question is: Is cell.CellFormat.Shading.BackgroundPatternColor not actually the background colour of the cell and I should be looking elsewhere for it?

Hope this makes some sense,
Will

@WillR27

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please share the output that shows the undesired behavior.
  • Please share the expected output.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

aspose.zip (28.2 KB)

Attached above is a console app, an input document and two output documents.

What I would expect to happen is that the cell.CellFormat.Shading.BackgroundPatternColor match the background colour of the cells in the output Word document, however, for ‘DarkListAccent3’ it won’t match, but for ‘GridTable2Accent1’ it will match.

Hopefully this is enough information, thanks.

Edit: Just to add, the way the table’s appear in the Word document is the way the styles appear in the style editor dialog, so they seem to be correct, it’s just the BackgroundPatternColor that don’t always seem to match.

@WillR27

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-18557. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@tahir.manzoor

Thanks.

There actually seems to be a similar issue with some of the font colours.

For instance when applying the “List Table 1 Light” table style, the font colour for each run in the table is set to transparent but then once in the document it is black again.

@WillR27

Could you please share some more detail about this query along with code example to elaborate this issue? We will investigate the issue and provide you more information on it.

It seems that the font colour is only transparent for black fonts, maybe this is actually because the font colours are ‘Automatic’ and this is just how they are represented.

Here is the example though just to show you what I mean:
Aspose.zip (18.8 KB)

@WillR27

Please note that formatting is applied on a few different levels. For example, let’s consider formatting of simple text. Text in documents is represented by Run element and a Run can only be a child of a Paragraph. You can apply formatting

  1. to Run nodes by using Character Styles e.g. a Glyph Style .
  2. to the parent of those Run nodes i.e. a Paragraph node ( possibly via paragraph Styles ).
  3. you can also apply direct formatting to Run nodes by using Run attributes ( Font ). In this case the Run will inherit formatting of Paragraph Style, a Glyph Style and then direct formatting.

The table style is applied to tables. There is no direct formatting is applied to text. So, please do not use Run.Font property.

That makes sense, thanks.

The issues you have found earlier (filed as WORDSNET-18557) have been fixed in this Aspose.Words for .NET 19.6 update and this Aspose.Words for Java 19.6 update.