private void RemoveEmptySheets(SpreadsheetDocument spreadSheet, OpportunityReportDto data) { var sheetIdsToRemove = new List <string>(); if (data.ReferralItems.Count == 0) { sheetIdsToRemove.Add(spreadSheet.GetSheetId(0)); } if (data.ProvisionGapItems.Count == 0) { sheetIdsToRemove.Add(spreadSheet.GetSheetId(1)); } foreach (var sheetId in sheetIdsToRemove) { spreadSheet.DeleteSheet(sheetId); } }