简体   繁体   English

Excel更改单元格颜色

[英]Excel change cell color

I'm using Office interop to generate an excel file containing a calendar. 我正在使用Office interop生成包含日历的excel文件。

My issue is that i change the color of a cell once (let's say when i generate the table. Example: coloring for weekends). 我的问题是我改变了一次单元格的颜色(比如当我生成表格时。例如:周末着色)。

For example: 例如:

tableRange = worksheet.Range["B1", "B6"];
tableRange.Interior.Color = ColorTranslator.FromHtml(entry.color);

Then i loop through some data and insert it into the calendar. 然后我遍历一些数据并将其插入日历。 First, i get the starting cell and insert color, font, value cell = worksheet.Cells[rowIndex, column]; ... 首先,我得到起始单元格并插入颜色,字体,值cell = worksheet.Cells[rowIndex, column]; ... cell = worksheet.Cells[rowIndex, column]; ... . cell = worksheet.Cells[rowIndex, column]; ... After that i get the range and merge the cells 之后,我得到范围并合并细胞

tableRange = worksheet.Range[column[start] + row, column[end] + row];
tableRange.Select();
tableRange.Merge();

The previous code works, but the color of the starting cell does not change to my new color 前面的代码有效,但起始单元格的颜色不会更改为我的新颜色

So the colors were actually changing. 所以颜色实际上在变化。 The issue was the order in which the cell got the color. 问题是细胞获得颜色的顺序。

First, it got the second color and second it got the first color. 首先,它获得第二种颜色,然后获得第一种颜色。 Now i grouped and ordered my data differently and it works 现在我对数据进行了分组和排序,并且有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM