Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Protected Excel File with ExcelDataReader and Epplus

title pretty much says it all. Looking for a way to access a password protected excel file with ExcelDataReader and Epplus, can't find a proper answer.

If using ExcelDataReader, my code looks like

                excelStream = File.Open(excelFilePath, FileMode.Open, FileAccess.Read);
                excelReader = ExcelReaderFactory.CreateOpenXmlReader(excelStream);
                excelDataSet = excelReader.AsDataSet();

If using EPPlus my connection code looks like

            excelPackage = new ExcelPackage(new FileInfo(excelFilePath));
            excelWorkbook = excelPackage.Workbook;
            excelSheet = excelWorkbook.Worksheets[1];

EPPlus has some protection related methods but i can't figure out how to use them. ExcelDataReader doesnt seem to have any protection related methods.

Any tips appreciated, thanks.

EDIT: I do already know the password

like image 456
Mike H Avatar asked Jul 07 '17 19:07

Mike H


People also ask

How do I open an encrypted spreadsheet?

Open the MS Excel file by double click on it. If you have protected the file with a password, then a pop up will appear on the screen. The pop up will indicate you that your Excel file is password protected and you will need a password to open it. Just enter the password to unlock the password-protected Excel file.

What is EPPlus DLL?

EPPlus is a very helpful open-source 3rd party DLL for writing data to excel. EPPlus supports multiple properties of spreadsheets like cell ranges, cell styling, charts, pictures, shapes, comments, tables, protection, encryption, pivot tables, data validation, conditional formatting, formula calculation, etc.

What is EPP Plus?

EPPlus is a . NET Framework/. NET Core library for managing Office Open XML spreadsheets, distributed via Nuget . Version 5 supports . NET Framework from version 3.5 and .

Can EPPlus read CSV?

EPPlus is a library for working with . XLSX files, which it does incredibly well, but it does not support . CSV files.


2 Answers

With EPPlus you can use

excelPackage = new ExcelPackage(new FileInfo(excelFilePath), "mypassword");

ExcelDataReader now supports opening password protected sheets. I opened an issue on their GitHub asking if they have such support and received a response saying that they do not, but after sometime they added support for some password methods. Details on the password methods they still do not support are in the link.

like image 120
hellyale Avatar answered Sep 25 '22 13:09

hellyale


With ExcelDataReadr you can access your protected file like this:

var conf = new ExcelReaderConfiguration { Password = "yourPassword" };
excelReader = ExcelReaderFactory.CreateOpenXmlReader(excelStream, conf);
like image 20
shA.t Avatar answered Sep 25 '22 13:09

shA.t