When Excel draws lines on a chart, it assigns default colors to the traces for each data series. Black for the first, cyan for the second, etc. Is the assignment of these colors documented? I want to draw traces on a graph using Delphi but want to keep the colors the same as Excel would use (the Delphi app is replacing stuff currently done with Excel workbooks).
‘Chart fill’ and ‘chart line’ default colors are accessible from the menu: Tools -> Options -> Colors (at least when excel had a menu – I don’t know about newer versions). Default colors can be changed per workbook and hence they’re a property of the workbook. There are 56 colors in total on the ‘Color’ option page, with 8 of them belonging to chart fills and 8 to chart lines.
If you’re doing automation you can retrieve a workbook default color by:
TColor(XL.Workbooks[1].Colors[Index])
where ‘XL’ is the excel application, ‘1’ is the workbook index and ‘Index’ is a number between 1 and 56. A little test with an earlier excel version shows index 17-24 are fill colors and 25-32 are line colors. But you do your own tests in case there has been changes.
BTW, I am surprised about your problem that Delphi overriding default colors..
Tags: delphi, delphiexcel