Excel Encryption for XLSX in C# and VB.NET

XLSX encryption enables you to securely protect the content of your Excel workbook (XLSX) from unwanted viewers.

Following example shows how to load encrypted XLSX file and how to save workbook as encrypted XLSX file in C# and VB.NET.

Input and output password should be specified in the appropriate text box. If password is empty, file won't be decrypted / encrypted.

Screenshot

XLSX Encryption Screenshot

See the full code below, use RUN EXAMPLE to execute.

Upload your file (Drag files here)

1using GemBox.Spreadsheet;
2using System.IO;
3
4class Sample
5{
6    [STAThread]
7    static void Main(string[] args)
8    {
9        // If using Professional version, put your serial key below.
10        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
11
12        string inputPassword = "inpass";
13        string outputPassword = "outpass";
14
15        var ef = ExcelFile.Load("XlsxEncryption.xlsx", new XlsxLoadOptions() { Password = inputPassword });
16
17        ef.Save("XLSX Encryption.xlsx", new XlsxSaveOptions() { Password = outputPassword });
18    }
19}
1Imports GemBox.Spreadsheet
2Imports System.IO
3
4Module Samples
5
6    Sub Main()
7
8        ' If using Professional version, put your serial key below.
9        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
10
11        Dim inputPassword As String = "inpass"
12        Dim outputPassword As String = "outpass"
13
14        Dim ef = ExcelFile.Load("XlsxEncryption.xlsx", New XlsxLoadOptions With {.Password = inputPassword})
15        ef.Save("XLSX Encryption.xlsx", New XlsxSaveOptions With {.Password = outputPassword})
16
17    End Sub
18
19End Module

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.