locked
How to Hide/Delete Excel sheet using Openxml RRS feed

  • Question

  • User-1779190663 posted

    i've done excel export using OpenXml instead of excel objects.

    I've Sheet1 and sheet2.In sheet one i have dropdown list in column "C1",where i used the source data from sheet2 . Now i want to delete/hide sheet2 while exporting excel sheet without effecting dropdown data.

    When i tried below code sheet2 has been deleted but i dint get any data in my dropdown.

    var theSheet = workbookPart.Workbook.Descendants<DocumentFormat.OpenXml.Spreadsheet.Sheet>()
    .FirstOrDefault(s => s.Id == relId1);
    theSheet.Remove();
    workbookPart.DeletePart(worksheetPart);


    Kindly Lemme know if any other way for making it without effecting ddl.

    thanks in advance.

    Tuesday, November 24, 2015 4:12 AM

Answers

  • User1724605321 posted

    Hi RajahRajah,

    where i used the source data from sheet2 . Now i want to delete/hide sheet2 while exporting excel sheet without effecting dropdown data.

    Then you could try to hide the second sheet which may not effect dropdownlist data ,set status of the sheet :

    SheetStateValues.Hidden

    Please refer to links below for details and demo:

    http://stackoverflow.com/questions/11921994/how-to-hide-a-sheet-in-excel-using-openxml-c .

    https://msdn.microsoft.com/en-us/library/office/hh370976(v=office.14).aspx .

    Or when you export to the excel . You could directly set the dropdownlist value and not create the second sheet .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 24, 2015 8:21 AM
  • User-1779190663 posted

    This Solution worked for me after some alteration

    https://social.msdn.microsoft.com/Forums/en-US/7191e89b-ef46-423f-b099-d98750f3fefd/hide-column-in-excel-using-openxml

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 24, 2015 9:01 AM

All replies

  • User1724605321 posted

    Hi RajahRajah,

    where i used the source data from sheet2 . Now i want to delete/hide sheet2 while exporting excel sheet without effecting dropdown data.

    Then you could try to hide the second sheet which may not effect dropdownlist data ,set status of the sheet :

    SheetStateValues.Hidden

    Please refer to links below for details and demo:

    http://stackoverflow.com/questions/11921994/how-to-hide-a-sheet-in-excel-using-openxml-c .

    https://msdn.microsoft.com/en-us/library/office/hh370976(v=office.14).aspx .

    Or when you export to the excel . You could directly set the dropdownlist value and not create the second sheet .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 24, 2015 8:21 AM
  • User-1779190663 posted

    This Solution worked for me after some alteration

    https://social.msdn.microsoft.com/Forums/en-US/7191e89b-ef46-423f-b099-d98750f3fefd/hide-column-in-excel-using-openxml

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 24, 2015 9:01 AM