I want to delete some worksheets from an Excel workbook. When my program is loaded, it reads the sheets in the workbook, lists them in a gridview where the user can select which sheets should be in the output file. When the user hits the save button, I delete worksheets based on the selection and save the workbook. All that works. EXCEPT for when there is actually content in the worksheet. This will delete empty worksheets, but not worksheets with content.
foreach (var item in _view.Sheets)
{
Exc.Worksheet ws = wb.Worksheets[item.Name];
if (!item.Include)
{
ws.Delete();
}
}
Any clues?
try to turn off alerts:
app.DisplayAlerts = false;
foreach (var item in _view.Sheets)
{
Exc.Worksheet ws = wb.Worksheets[item.Name];
if (!item.Include)
{
ws.Delete();
}
}
app.DisplayAlerts = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With