You have to install
Open XML SDK 2.5 for Office | Microsoft Docs[
^]
Tehn you have to read MSDN documentation (which contains examples):
Spreadsheets (Open XML SDK) | Microsoft Docs[
^]
Quote:
Sample Code
The CreateSpreadsheetWorkbook
method shown here can be used to create a basic Excel document, a workbook with one sheet named "mySheet
". To call it in your program, you can use the following code example that creates a file named "Sheet2.xlsx" in the public documents folder.
CreateSpreadsheetWorkbook(@"c:\Users\Public\Documents\Sheet2.xlsx")
Notice that the file name extension, .xlsx, matches the type of file specified by the SpreadsheetDocumentType.Workbook parameter in the call to the Create method.
Following is the complete sample code
public static void CreateSpreadsheetWorkbook(string filepath)
{
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
Create(filepath, SpreadsheetDocumentType.Workbook);
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.
AppendChild<Sheets>(new Sheets());
Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.
GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
sheets.Append(sheet);
workbookpart.Workbook.Save();
spreadsheetDocument.Close();
}