static void CloneSheet(SpreadsheetDocument spreadsheetDocument, string sheetName, string clonedSheetName) { WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart; WorksheetPart sourceSheetPart = GetWorkSheetPart(workbookPart, sheetName); Sheets sheets = workbookPart.Workbook.GetFirstChild<Sheets>(); SpreadsheetDocument tempSheet = SpreadsheetDocument.Create(new MemoryStream(), spreadsheetDocument.DocumentType); WorkbookPart tempWorkbookPart = tempSheet.AddWorkbookPart(); WorksheetPart tempWorksheetPart = tempWorkbookPart.AddPart(sourceSheetPart); WorksheetPart clonedSheet = workbookPart.AddPart(tempWorksheetPart); Sheet copiedSheet = new Sheet(); copiedSheet.Name = clonedSheetName; copiedSheet.Id = workbookPart.GetIdOfPart(clonedSheet); copiedSheet.SheetId = (uint)sheets.ChildElements.Count + 1; sheets.Append(copiedSheet); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter