Avatar ·

How to create an Excel file (.xls/.xlsx) in C# without installed Microsoft Office?

Hello everyone! I'm a beginner C# developer and I've run into a problem: I need to programmatically create Excel files (both the old .xls format and the new .xlsx) in my application. The problem is that Microsoft Office is not installed on the server where the program will run, and it cannot be installed there. Initially, I tried to use the Microsoft.Office.Interop.Excel library, but the code throws an error because the COM object cannot be created without Office installed. Here is my old code that I tried to use: ```csharp using Microsoft.Office.Interop.Excel; Application excelApp = new Application(); Workbook workbook = excelApp.Workbooks.Add(); Worksheet worksheet = workbook.Worksheets[1]; worksheet.Cells[1, 1] = "Hello, world!"; workbook.SaveAs("test.xlsx"); workbook.C