简体   繁体   中英

How to change the background color of an Excel sheet cell in C#

How can I change the background color of an Excel sheet cell with C#?

在此处输入图片说明

I would do it that way:

xlWorksheet.Cells[1, 1].Interior.Color = Excel.XlRgbColor.rgbRed;

But don't forget to declare the right using:

using Excel = Microsoft.Office.Interop.Excel;

And I declared the following variables

Excel.Application xlApplication;
Excel.Workbook xlWoorkbook;
Excel.Worksheet xlWorksheet;

xlApplication = new Excel.Application();
xlWoorkbook = xlApplication.Workbooks.Add();
xlWorksheet = xlWoorkbook.Worksheets[1];

Hopefully that works for you too!

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