I'm using the TMS FMX grid but can't convert a Flexcel cell color to an FMX color - TExcelColor seems to expect a VCL color. I'm using
format := FExcelFile.GetCellVisibleFormatDef(ARow, ACol);
and then trying to set the cell fill color (ALayout.Fill.Color) - how do I convert Excel colors to FMX?
TExcelColor uses VCL colors when you use VCL.FlexCel.Core, and FMX colors when you use FMX.FlexCel.Core.
In fact, one of the reasons to have a TExcelColor struct is to isolate from the different TColors in the different platforms.
Now, while TAlphaColor will convert to TExcelColor automatically, the inverse isn't true. You need to specifiaclly convert TExcelColor to TAlphaColor: This is because a TExcelColor can have an indexed color inside, and the RGB color corresponding to the index depends on the color palette. So in order to convert, FlexCel needs to know the color palette of the file, and you need to pass a TExcelFile object to the conversion as TExcelFile has the color palette.
After the explanation, this should do it:
Alayout.Fill.Color = SomeExcelColor.ToColor(FExcelFile);
Where SomeExcelColor is normally FgColor if the cell has a solid fill. (note that in Excel we use FbColor and not BgColor for the fill in solid fills)
Thanks Adrian - works a treat.
For anyone else trying this remember to also check for a solid fill using something like:
if format.FillPattern.Pattern = TFlxPatternStyle.Solid then
ALayout.Fill.Color := format.FillPattern.FgColor.ToColor(FExcelFile);
Before applying the color to the cell.