Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
Deleting default worksheet
posted

Hi

I am populating the excel with data from various datatables. My spreadsheet will have around 18 worksheets.

The default WorkSheet1 is the last worksheet. My client don't want to see the default worksheet.

I could not find a way to delete the default WorkSheet1. Below is the code which throws an error - Key not found.

Worksheet workSheet1 = workbook.Worksheets["WorkSheet1"];

workbook.Worksheets.Remove(workSheet1);

Please help.

Parents
No Data
Reply
  • 16310
    Offline posted

    Hi,

    Actually the error seems pretty descriptive and I guess it throws the error on the first line because it fails to find this worksheet. Please make sure about the key, however you can try to get the worksheet by its index.

    Please let me know if you have any questions.

Children
No Data