使用ExcelDataReader和Epplus访问受保护的Excel文件 [英] Access Protected Excel File with ExcelDataReader and Epplus

查看:355
本文介绍了使用ExcelDataReader和Epplus访问受保护的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题几乎说明了一切.寻找一种使用ExcelDataReader和Epplus访问受密码保护的excel文件的方法,找不到正确的答案.

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.

如果使用ExcelDataReader,我的代码如下

If using ExcelDataReader, my code looks like

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

如果使用EPPlus,我的连接代码如下

If using EPPlus my connection code looks like

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

EPPlus具有一些与保护相关的方法,但我不知道如何使用它们. ExcelDataReader似乎没有任何与保护有关的方法.

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.

感谢任何提示,谢谢.

我已经知道密码

推荐答案

使用EPPlus,您可以使用

With EPPlus you can use

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

ExcelDataReader现在支持打开受密码保护的工作表.我在他们的GitHub上打开了 issue ,询问他们是否有这种支持,并收到回复说他们没有,但是一段时间后,他们增加了对某些密码方法的支持.他们仍然不支持的密码方法的详细信息在链接中.

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.

这篇关于使用ExcelDataReader和Epplus访问受保护的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆