【发布时间】:2016-04-07 11:51:07
【问题描述】:
我正在使用Microsoft.Office.Interop.Excel 库。
我有一个值为“Green Red”的单元格。我想要的很简单。我想将“Green”文本插入绿色,将“Red”插入红色,如下所示:
我正在使用此代码在单元格中插入数据:
Excel.Application excelApp = new Excel.Application();
excelApp.Workbooks.Add();
// single worksheet
Excel._Worksheet workSheet = excelApp.ActiveSheet;
for (int startIndex = 0; startIndex < 10; startIndex++)
{
workSheet.Cells[1, (startIndex + 1)] ="Green" + " Red";
}
怎么做?
我有tried this approach,但我不知道[RangeObject]是什么:
[RangeObject].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
【问题讨论】:
-
stackoverflow.com/questions/5667842/… 对您有帮助吗?您使用的是哪种 C# 中的 Excel 集成方式?
-
@weismat 哎呀,我无法理解你的问题。我正在使用
Microsoft.Office.Interop.Excel库。 -
@AdamCalvetBohl 是的,我试过了,但无法弄清楚
[RangeObject]是什么。 -
范围对象
Represents a cell, a row, a column, a selection of cells containing one or more contiguous blocks of cells, or a 3-D range.对于您的情况,将两种颜色应用于一个单元格将没有用。