We want to read an Excel template, fill it with data and then write it back to another Excel file. In the generated Excel file the colors differ from the original color . The code basically looks like this:
Workbook w = Workbook.Load("File1.xlsx");w.Save("File2.xlsx");
Some research showed that all the original colors are mapped to a maximum of 46 colors in the target file. Any idea how to fix that?
Thanks Thomas
Hi Thomas,
There was a 46-color limit in Excel prior to Office2007. I'm not sure, but I think that this restriction might have been lifted in Office2007.
Do I understand you correctly in that your original Excel file has more than 46 colors and you are able to load that file, modify it, and save it, and then at that point, the colors are reduced to 46? If that's the case, it sounds like the Excel engine engine is still enforcing the old limitation even though it does not need to, in which case this is a bug.
Hi Mike,
It would be better to describe the problem differently: It does not matter how many colors there are in the original excel sheet. The problem is that any color - no matter if imported or assigned - is mapped to one of the 46 available colors.
E.g. after executing the statement
c.CellFormat.FillPatternForegroundColor = Color.FromArgb(136, 40, 16 );
FillPatternForgroundColor.A: 255FillPatternForgroundColor.R: 153FillPatternForgroundColor.G: 51FillPatternForgroundColor.B: 0 This 'mapping' applies to assigned colors and loaded colors. It applies only if the workbook was opened from a template with Workbook.Load(). Best regards Thomas
FillPatternForgroundColor.A: 255FillPatternForgroundColor.R: 153FillPatternForgroundColor.G: 51FillPatternForgroundColor.B: 0
This 'mapping' applies to assigned colors and loaded colors. It applies only if the workbook was opened from a template with Workbook.Load().
Best regards Thomas
the values of c.CellFormat.FillPatternForgroundColor will be
We do not support all the ways in which Excel 2007 stores their color palettes. However, it is probably a bug that we use the standard color palette when a non-supported palette format is used. We should probably use a custom palette in this case. I have forwarded this post to the Developer Support Manager and a DS engineer will be contacting you about this issue.
I have the same issue. I've created my own custom styles and they're all messed up after the save, quite badly. Can you add me in the loop?