Free Support Forum - aspose.com

Hide/Unhide sheets using password

Hi,

Can password be used to hide/unhide sheets?
I am using Aspose.cells fro .net version 8.0.0.0.

@Xavier.S,

Thanks for your query.

I think this feature (hide/unhide worksheet using password) is not available in MS Excel either (using its options and menu commands). Aspose.Cells follows MS Excel standards and specifictions, so if something is not done in MS Excel manually, it cannot be done by Aspose.Cells APIs. Anyways, if you find this can be done in MS Excel manually, kindly provide complete details and steps involved to accomplish the task, we will check on how to do it via Aspose.Cells APIs.

Furthermore, we recommend you to protect a worksheet instead via Aspose.Cells APIs. You may password protect a whole worksheet, so if any user needs to edit the worksheet, he has to provide a valid password to do that. See the documents in the section for your reference:
https://docs.aspose.com/display/cellsnet/Security+Features

thanks for the reply.

Here is what you do in Excel

In your sheet of interest, go to Format->Sheet->Hide and hide your sheet.
Go to File->Protect workbook->Protect Workbook structure, and enter your password of choice.
Once this is done, the sheet is hidden and cannot be unhidden without the password.

@Xavier.S,

Thanks for the details.

See the following sample code to accomplish your task via Aspose.Cells APIs for your reference.
e.g
Sample code:

Workbook workbook = new Workbook("e:\\test2\\Book1.xlsx");

// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];

// Hiding the first worksheet of the Excel file
worksheet.IsVisible = false;
 
// Protecting the workbook with a password "1234".
workbook.Protect(ProtectionType.All, "1234"); 

workbook.save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.

Thanks. This works for me.

@Xavier.S,

Good to know that the suggested code figures out your issue now. Let us know if you encounter any other issue, we will be glad to look into it and help you further.