From: Richard de Garis on
"Sander Aerts" <remove.this.sander.aerts(a)be.atlascopco.com> wrote in message <hcs0qb$ren$1(a)fred.mathworks.com>...
> Hello,
>
> I am writing an application that calculates some values, compares them to the previous version and then writes the result to an excel file. Depending on the comparisson with the previous value, the background color of a cell should be set.
>
> Excel by itself provides 56 colors all of which do not meet my demands, so i want to change the color palette which shouldn't be all too difficult (or so i thought).
> If i take the colors provided by the jet function and convert those to the hexadecimal form used by excel (in hex form: 0xBBGGRR) i can make a new palette (or part of it) like:
>
> pal = jet(56)*255;
> pal = SomeFuncToConvertToHexFormForExcel(pal);
>
> Now, assuming there is a global variable called Excel, with a workbook loaded. It is possible to view the current colorpalette (and reset it) like:
>
> Excel.ActiveWorkbook.Colors % this shows the palette
> Excel.ActiveWorkbook.ResetColors % This resets the palette to the not desired form
>
> Yet if i try to set the palette:
>
> Excel.ActiveWorkbook.Colors = pal
>
> I get an error stating:
> ??? Invoke Error, Dispatch Exception:
> Source: Microsoft Excel
> Description: Unable to set the Colors property of the Workbook class
> Help File: c:\program files\Microsoft Office\Office10\1033\xlmain10.chm
> Help Context ID: 0
>
> After googling this error I found out (and I hope this is wrong) that the colors property can only be modified by fully trusted callers
> (http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.colors.aspx)
> which basically means (i think) that the Matlab com server interface is partially trusted code.
> (http://msdn.microsoft.com/en-us/library/8skskf63.aspx)
>
> Hence my question:
> Does anybody know how to change the color palette of a workbook from within Matlab. I am clueless.

I don't know how to do what you are asking, but I write data to excel all the time. In many cases the receiving cells are conditionally formatted, within Excel, so that the color changes according to the number that is written by Matlab. You said Excel only provides 56 colors; what version of excel are you using, because on Excel 2007 you get millions of colors?