var filename = Path.Combine(_env.WebRootPath, "files", "data.xlsx"); using (SpreadsheetDocument myDoc = SpreadsheetDocument.Create(filename, SpreadsheetDocumentType.Workbook)) { WorkbookPart workbookpart = myDoc.AddWorkbookPart(); workbookpart.Workbook = new Workbook(); // Add a WorksheetPart to the WorkbookPart. WorksheetPart worksheetPart = workbookpart.AddNewPart(); SheetData sheetData = new SheetData(); //add the first row Row firstRow = new Row(); firstRow.RowIndex = (UInt32)1; //create a cell in A1 (the upper left most cell of the merged cells) Cell dataCell = new Cell(); dataCell.CellReference = "A1"; CellValue cellValue = new CellValue(); cellValue.Text = "Raw Matrials and Price List"; dataCell.Append(cellValue); firstRow.AppendChild(dataCell); sheetData.AppendChild(firstRow); //add the second row Row secondrow = new Row(); secondrow.RowIndex = (UInt32)2; //create a cell in A2 (the upper left most cell of the merged cells) Cell secdataCell = new Cell(); secdataCell.CellReference = "A2"; CellValue seccellValue = new CellValue(); seccellValue.Text = "From: 121"; Cell secdataCell2 = new Cell(); secdataCell2.CellReference = "C2"; CellValue seccellValue2 = new CellValue(); seccellValue2.Text = "To: 250"; secdataCell.Append(seccellValue); secdataCell2.Append(seccellValue2); secondrow.AppendChild(secdataCell); secondrow.AppendChild(secdataCell2); sheetData.AppendChild(secondrow); //based on the table data to add row and cell. // Add a WorkbookPart to the document. worksheetPart.Worksheet = new Worksheet(sheetData); //create a MergeCells class to hold each MergeCell MergeCells mergeCells = new MergeCells(); //append a MergeCell to the mergeCells for each set of merged cells mergeCells.Append(new MergeCell() { Reference = new StringValue("A1:d1") }); mergeCells.Append(new MergeCell() { Reference = new StringValue("A2:b2") }); mergeCells.Append(new MergeCell() { Reference = new StringValue("c2:d2") }); worksheetPart.Worksheet.InsertAfter(mergeCells, worksheetPart.Worksheet.Elements().First()); //this is the part that was missing from your code Sheets sheets = myDoc.WorkbookPart.Workbook.AppendChild(new Sheets()); sheets.AppendChild(new Sheet() { Id = myDoc.WorkbookPart.GetIdOfPart(myDoc.WorkbookPart.WorksheetParts.First()), SheetId = 1, Name = "Sheet1" }); }