Home » excel » asp.net – How to unhide an excel sheet through c# without using interop

asp.net – How to unhide an excel sheet through c# without using interop

Posted by: admin April 23, 2020 Leave a comment

Questions:

My server guy is not ready to install office

I have written the following code in my form. It works fine from my machine but when I upload on the net; it does not work. This requires the interop dlls but the server guy is not ready to install office on the server. can any one help me as I need to unhide sheet from excel.

using excel;

        Excel.Application excelApp = new Excel.Application();

        string myPath = @fileLocation;
        excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value,Missing.Value, Missing.Value);//,Missing.Value, Missing.Value);

        //Get the first sheet.
        Excel.Worksheet objSheet = (Excel.Worksheet)excelApp.ActiveWorkbook.Sheets["abc"];

        //Unhide the worksheet.
        objSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible;
        //Save As the Excel file.
        excelApp.ActiveWorkbook.Save();
How to&Answers:

Use Open XML SDK and set the Sheet‘s State property to SheetStateValues.Hidden.

Sheet.State property

http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheet.state.aspx

Open XML SDK 2.5 for Microsoft Office

http://www.microsoft.com/en-us/download/details.aspx?id=30425

Don’t use office automation on a server.

enter image description here