using Microsoft.Office.Interop.Excel; // ... Application excel = new Application(); Workbook wb = excel.Workbooks.Open(@"C:\example.xlsx");
Worksheet ws = wb.Worksheets[1]; ws.Cells[1, 1].Value = "Name"; ws.Cells[1, 2].Value = "Salary"; ws.Cells[2, 1].Value = "John"; ws.Cells[2, 2].Value = 50000; ws.Cells[3, 1].Value = "Jane"; ws.Cells[3, 2].Value = 60000;
Range headerRange = ws.Range("A1:B1"); headerRange.Font.Bold = true; headerRange.Interior.Color = Color.Yellow; Range dataRange = ws.Range("A2:B3"); dataRange.Font.Bold = false; dataRange.Interior.Color = Color.White;These examples demonstrate how you can use the Microsoft.Office.Interop.Excel application to interact with Excel files, manipulate data, and format the worksheet. To use this library in your C# project, you will need to add a reference to the Microsoft.Office.Interop.Excel package.