Created
November 13, 2023 12:17
-
-
Save d47447/9a70f862f9e759ee0ae51dc2317736df to your computer and use it in GitHub Desktop.
TheAxaptaCellBackground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using OfficeOpenXml; | |
| using OfficeOpenXml.Style; | |
| internal final class TheAxaptaExcelExportWithColor | |
| { | |
| /// <summary> | |
| /// Class entry point. The system will call this method when a designated menu | |
| /// is selected or when execution starts and this class is set as the startup class. | |
| /// </summary> | |
| /// <param name = "_args">The specified arguments.</param> | |
| public static void main(Args _args) | |
| { | |
| using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) | |
| { | |
| using (var package = new ExcelPackage(stream)) | |
| { | |
| ExcelWorksheet worksheet = package.Workbook.Worksheets.Add('TheAxaptaCellBackground'); | |
| ExcelRange cell = worksheet.Cells.get_Item('A1');//Cell number | |
| cell.Value = 'RedColor'; // Value | |
| ExcelFill fill = cell.Style.Fill; | |
| fill.PatternType = ExcelFillStyle::Solid; | |
| ExcelColor backgroundColor = fill.BackgroundColor; | |
| backgroundColor.SetColor(System.Drawing.Color::FromArgb(255, 00, 000)); //Background color, This is basically RGB code color | |
| cell = worksheet.Cells.get_Item('B1'); | |
| cell.Value = 'Green/LightGreen'; | |
| fill = cell.Style.Fill; | |
| fill.PatternType = ExcelFillStyle::Solid; | |
| backgroundColor = fill.BackgroundColor; | |
| backgroundColor.SetColor(System.Drawing.Color::FromArgb(144, 238, 144)); //Background color, This is basically RGB code color | |
| cell = worksheet.Cells.get_Item('C1'); | |
| cell.Value = 'Green/LightGreen'; | |
| fill = cell.Style.Fill; | |
| fill.PatternType = ExcelFillStyle::Solid; | |
| backgroundColor = fill.BackgroundColor; | |
| backgroundColor.SetColor(System.Drawing.Color::FromArgb(0, 0, 255)); //Background color, This is basically RGB code color | |
| //You can write seprate method for major colors and assing them based on other business logic | |
| package.Save(); | |
| } | |
| File::SendFileToUser(stream, 'TheAxaptaCellBackground.xlsx'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment