简体   繁体   中英

Excel change cell color

I'm using Office interop to generate an excel file containing a calendar.

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]; ... . 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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