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

Oct 15, 2014 at 6: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);
            NPOI.POIFS.Crypt.Decryptor.GetInstance(info).VerifyPassword("password");
            if ((extension).Contains("sx"))
            {
                //workBook = new XSSFWorkbook(stream);
                workBook = new XSSFWorkbook(NPOI.POIFS.Crypt.Decryptor.GetInstance(info).GetDataStream(fs));

            }
            else
            {
                //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.

Thanks!!!

ps: I found this project that contains the classes for this example here: https://github.com/svn2github/npoi/tree/master/main/POIFS/Crypt.