// Hook: AfterPacketGeneration // Remove worksheets that have no data after the packet was assembled. // // Empty sheets usually mean a merge step produced no rows for that segment. // If removing the empties leaves the workbook with zero sheets, that is // almost always a configuration mistake worth catching before distribution. if (Workbook == null) { AddError($"No workbook available for '{OutputName}'; cannot validate packet."); return; } var toRemove = new List(); foreach (Worksheet sheet in Workbook.Worksheets) { if (sheet.Cells.MaxDataRow < 0 && sheet.Cells.MaxDataColumn < 0) toRemove.Add(sheet.Name); } foreach (var name in toRemove) { Workbook.Worksheets.RemoveAt(name); Logger.LogInformation($"Removed empty sheet '{name}' from '{OutputName}'."); } if (Workbook.Worksheets.Count == 0) { AddError($"Packet '{OutputName}' has no sheets after empty-sheet cleanup; refusing to distribute."); } if (toRemove.Count > 0) { AddWarning($"Removed {toRemove.Count} empty sheet(s) from '{OutputName}': {string.Join(", ", toRemove)}."); }