FNCDataGrid + FNCDataGridExcelIO + Importing XLS = fill colors don't match.

Fill colors used in XLS file shows very different when imported to DataGrid.

There’s a UseExcelStandardColorPalette, but it seems to work only for exporting.

Is there some way to show the correct colors ? Any known manual conversion that could be done?

No way.

It’s a “modern Office” vs “XLS color pallet” issue. It needs a 100% native XLS file with old 56 colors management to match well.

Hi,
UseExcelStandardColorPalette is indeed only used for exporting, because it should be not needed for importing.

  • When exporting: xls file format only allows a palette of 56 colors, so we need to convert whatever colors you are using to those 56 colors. If UseExcelStandardColorPalette = true, we will just map those colors to Excel's standard palette If UseExcelStandardColorPalette = false, we will create a palette that matches the colors you are exporting more closely, and use that palette in the file.
  • When importing: We just read which of the 56 indexed colors you are using, and use that in the grid. There is no need to adapt any palette.

The most likely thing here is that the file doesn't use the actual 56 colors, but more. When Excel introduced xlsx in 2007, it moved colors from indexed to "true color", and it saves the color twice in the xls file: Once in the xls format, as an indexed color, and again in xlsx file format, as a true color. Old applications which don't understand xlsx (like say Excel 2003 or FlexCel 3, which is what AdvGridExcelIO uses) will keep reading the old color and showing that, but newer apps (like FlexCel 7 or newer Excels) will discard that indexed color value and use the "true color" value stored as xlsx inside the xls file.

If you can send me a xls file with the issue, I can confirm if that is the problem by opening in Excel 2003. It should show the same as the DataGrid.

If that is the problem, sadly the only alternative is to move to TAdvExcelImport (TMS VCL Grid Excel bridge User Guide | TMS VCL Grid Excel bridge documentation) which uses FlexCel 7 under the hood, and FlexCel 7 can understand true colors inside a xls file (and of course inside xlsx files too)

I blogged about the color difference years ago: TMS Software | Blog
If you save the file in the second screenshot as xls, it will show in Excel 2003 (or FlexCel 3) as the first screenshot. Even when Excel 2007 will be able to read that xls file and show the true colors. This is just because inside the xls file Excel 2007 will save huge amounts of repeated information in the xlsx file format, which old xls readers can't read. Newer engines like FlexCel 7 can read both the xls and xlsx parts inside the file and show it correctly. Sadly to do so it requires a lot more of code (FlexCel 7 is more than a million lines of code, most of it is to deal with all the little issues in xlsx), and we can't ship an embedded FlexCel 7 to power AdvGridExcelIO (like we can with FlexCel 3)

As an extra note: If you go to File->Options->Save->Colors in Excel, you can see the color palette used by your file:

You can check if those colors are the ones you are seeing in the datagrid. If they aren't, as said, please send me the xls file to adrian@tmssoftware.com and we will take a look.

Hi !
You gave me the AdvGrid family alternative, but I’m using TTMSFNCDataGrid with TTMSFNCDataGridExcelIO.

Thanks to your answer I found this TTMSFNCDataGridExcelImport, and there are no color issues anymore ! :smiley:

Thanks!

Sorry, I forgot this was fnc when I searched for the link (even if it is in the title!) :slight_smile: Anyway, glad you could solve it. Indeed, there is a vcl and a fnc version.