How to set color or background with “excelpackage”

核能气质少年 提交于 2019-12-21 07:01:37

问题


I use this package: ExcelPackage though I can't figure out how to set the background color for the cell. I tried to use this:

ws.Cells["A1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;

But it shows that the properties are not found.

Sounds like I should use something similar to this:

worksheet.Cell(5, columnIndex + 1).Style = "background-color: red";

But I am not sure how it works and I couldn't find the tutorial for it. Please help.


回答1:


Try something along these lines (Taken from the EPPlus sample files provided):

using (var range = worksheet.Cells[1, 1, 1, 5]) 
    {
        range.Style.Fill.PatternType = ExcelFillStyle.Solid;
        range.Style.Fill.BackgroundColor.SetColor(Color.DarkBlue);
    }



回答2:


For ExcelPackage

workSheet.Cells["A1:B1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.LightTrellis; workSheet.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightSeaGreen); var allCells = workSheet.Cells["A1:B1"]; var cellFont = allCells.Style.Font;



来源:https://stackoverflow.com/questions/17156118/how-to-set-color-or-background-with-excelpackage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!