This project is read-only.

How to open/edit a protected document (.xls, .xlsx)

Oct 15, 2014 at 7:48 PM
Hi, i'm trying to open a xls/xlsx file that is protected by a password.

First, I would like to know: Is it possible to do it with NPOI?

If it is, how can I do it?

I found some code like this:

IWorkbook workBook;
            NPOI.POIFS.FileSystem.POIFSFileSystem fs = new NPOI.POIFS.FileSystem.POIFSFileSystem(stream);
            NPOI.POIFS.Crypt.EncryptionInfo info = new NPOI.POIFS.Crypt.EncryptionInfo(fs);
            if ((extension).Contains("sx"))
                //workBook = new XSSFWorkbook(stream);
                workBook = new XSSFWorkbook(NPOI.POIFS.Crypt.Decryptor.GetInstance(info).GetDataStream(fs));

                //workBook = new HSSFWorkbook(stream);                    
                workBook = new HSSFWorkbook(NPOI.POIFS.Crypt.Decryptor.GetInstance(info).GetDataStream(fs));

But it's not working. If this is the way to do it, I'll send the erros that I got.


ps: I found this project that contains the classes for this example here: