excel cell coloring

前端 未结 6 1793
刺人心
刺人心 2020-12-06 12:06

I am using c# to color particular cells of excel file. I am using:

Application excel = new Application();
Workbook wb = excel.Workbooks.Open(destPath);
 Work         


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-06 12:18

    Make sure you are using:

    using Excel = Microsoft.Office.Interop.Excel;
    

    If you have a variable for the range you want to change, then use:

    chartRange = xlWorkSheet.get_Range("a5", "a8");    
    chartRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
    

    If you want to just change the color of a specific cell, then use:

    xlWorkSheet.Cells[row, col].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
    

    ...where 'row' is the row number, and 'col' is the column number assigned to the given lettered columns (starting at 1).

提交回复
热议问题