Color a range with different colors

M

Magnus.Moraberg

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top