//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); var fileStream = this.GetResourceStream("xlsx\\Medical office start-up expenses 1.xlsx"); workbook.Open(fileStream); //Use a password to protect all the worksheet. If you forget the password, you cannot unprotect the worksheet. foreach (IWorksheet worksheet in workbook.Worksheets) { worksheet.Protect("Y6dh!et5"); } // Save to an excel file workbook.Save("ProtectWorksheetWithPassword.xlsx");
' Create a new Workbook Dim workbook As New Workbook 'Open an excel file Dim fileStream = GetResourceStream("xlsx\\Medical office start-up expenses 1.xlsx") workbook.Open(fileStream) ' Use a password to protect all the worksheet. ' If you forget the password, you cannot unprotect the worksheet. For Each worksheet In workbook.Worksheets worksheet.Protect("Y6dh!et5") Next ' save to an excel file workbook.Save("ProtectWorksheetWithPassword.xlsx")