public static void RandomColors(int j) { var app = NetOffice.ExcelApi.Application.GetActiveInstance(); NetOffice.ExcelApi.Range sel = (NetOffice.ExcelApi.Range)app.Selection; Random r = new Random(); for (var i = 0; i < j; i++) { System.Drawing.Color c = r.NextDouble() < 0.5 ? System.Drawing.Color.Red : System.Drawing.Color.Blue; sel.Characters(i, 1).Font.Color = colors[i]; } }
public static void ColorSelection(object[] data) { var app = NetOffice.ExcelApi.Application.GetActiveInstance(); NetOffice.ExcelApi.Range sel = (NetOffice.ExcelApi.Range)app.Selection; for (var i = 0; i < data.Length; i += 3) { int j = (int)data[i]; int k = (int)data[i + 1]; double l = (double)data[i + 2]; sel.Characters(j, k).Font.Color = l; } }