受密码保护的 Excel 文件 [英] Password Protected Excel File

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

问题描述

我有一个受密码保护的 Excel 电子表格.我需要打开这个电子表格并从中读取数据.我一直在尝试使用 POI API 无济于事.首选 Java 解决方案,但任何想法都会有所帮助.

I have an excel spreadsheet that is password-protected. I need to open this spreadsheet and read the data from it. I've been attempting to use the POI API to no avail. A Java solution would be preferred but any ideas would be helpful.

是的,我有密码.该文件在excel中受密码保护;必须输入密码才能查看电子表格.

Yes, I have the password. The file is password protected in excel; a password must be entered to view the spreadsheet.

Edit2:我无法使用带有密码的 POI 打开它,我正在寻找替代解决方案.

I am unable to open it with POI with the password, I am looking for an alternate solution.

推荐答案

您可以使用 JExcelApi.

我已经有一段时间没有这样做了,所以我可能不会告诉你如何正确地做到这一点,但肯定有一种方法可以使用 JExcelApi 做到这一点.试试下面的来源:

It has been a while since I have done this, so I may not be telling you how to do it correctly, but there is definitely a way to do this using JExcelApi. Try the source below:

Workbook workbook = Workbook.getWorkbook(new File("/path/to/protected.xls"));
workbook.setProtected(false);
WritableWorkbook copy = Workbook.createWorkbook(new File("/path/to/unprotected.xls"), workbook);
WritableSheet[] sheets = copy.getSheets();

for (WritableSheet sheet : sheets){
    sheet.getSettings().setProtected(false);
}

copy.write();
copy.close();

当然,您需要导入必要的类并捕获必要的异常.

Of course, you will need to import necessary classes and catch necessary exceptions.

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

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