How to create Excel files (.XLS and .XLSX) in C# without installed Microsoft Office?
Hello everyone! I'm a beginner in C# and I've encountered a task: 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 application will be deployed, and it cannot be installed. I tried using the Microsoft.Office.Interop.Excel libraries, but they require Office to be installed and throw an error if it's not present.
My current code looks like this:
```csharp
using Microsoft.Office.Interop.Excel;
public void CreateExcelFile(string filePath)
{
Application excelApp = new Application();
Workbook workbook = excelApp.Workbooks.Add();
Worksheet worksheet = (Worksheet)workbook.Sheets[1];
worksheet.Cells[1, 1] = "Hello, world!";
workbook.SaveAs(filePath);
workbook.Close();
```