How to add color to cell without using Excel application scope

is it possible to set color cell ? Microsoft office is not installed in VM so cant use Excel application scope and VBA.
Is their any other way to achieve this

1 Like

we can check an OpenXML Approach

Hi @ppr , can you please give more details on the same

Hi,

Try below c# code:-

Response form chatgpt:-

// Import necessary namespaces
using Microsoft.Office.Interop.Excel;

// Create an instance of Excel application
Application excelApp = new Application();

// Make Excel visible (optional)
excelApp.Visible = true;

// Open the workbook
Workbook workbook = excelApp.Workbooks.Open(“C:\path\to\your\workbook.xlsx”);

// Get the worksheet
Worksheet worksheet = workbook.Sheets[1]; // Assuming you want to work with the first worksheet

// Set the color of a specific cell (e.g., A1) to blue
Range cell = worksheet.Cells[1, 1];
cell.Interior.Color = XlRgbColor.rgbBlue;

// Save and close the workbook
workbook.Save();
workbook.Close();

// Quit Excel application
excelApp.Quit();

Thanks

@TUSHAR_DIWASE
We can start with this prototype:
grafik

XLWorkbook wb = new XLWorkbook(@"C:\_demo\Excel\OpenXMLCellColor.xlsx");
IXLWorksheet ws = wb.Worksheet("Tabelle1");
ws.Cell("A1").Style.Fill.BackgroundColor = XLColor.Amber;
ws.Cell("A1").Value = "This cell should have light blue background";
wb.Save();

and rework it to a more dynamic approach e.g. arguments for filepath, worksheetname, …

1 Like