View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] Magnus.Moraberg@gmail.com is offline
external usenet poster
 
Posts: 3
Default Color a range with different colors

Hi,

I'd like to do something like this -

int[,] colorMatrix = { { System.Drawing.Color.Yellow.To ToArgb(),
System.Drawing.Color.Red.ToArgb() },
{ System.Drawing.Color.Green.ToArgb(),
System.Drawing.Color.Blue.ToArgb() } };

range = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2,
2]);

range.Interior.Color = colorMatrix;

But it doesn't work. Instead I just get one color in all cells. Is it
possible to set a range with different colors? It works for text as
follows -

string[,] textMatrix = { { "A","B" }, { "C", "D" } };

range = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2,
2]);

range.Value2 = textMatrix;

The reason I wish to fill a range is that setting the value of a
single cell is really slow when you do it for a large number of cells.
As follows -

for(int i = 1; i<=10000; i++)
worksheet.Cells[i,1] = "A"; // really slow

Any suggestions?

Barry.