xlsm java 读取,使用Java的Apache POI从只读XLSM文件中读

博主在尝试使用Java的Apache POI库读取只读xlsm文件时遇到问题,指出代码无法进入工作簿阶段。解决办法在于提供正确的文件路径,并怀疑路径问题或文件本身可能引起的问题。讨论了路径格式和权限影响。
摘要由CSDN通过智能技术生成

I'm trying to read data from a read only xlsm using java apache poi, but when i use XSSF workbook it doesn't seem to be able to access the file and HSSF workbooks only work for xls files. My code looks like this:

try {

FileInputStream file = new FileInputStream(new File("file.xlsm"));

System.out.println("found file");

XSSFWorkbook workbook = new XSSFWorkbook(file);

System.out.println("in workbook");

XSSFSheet sheet = workbook.getSheet("Shipments");

System.out.println("got sheet");

The code never reaches the "in workbook" print line and I'm not sure why. Please help!

解决方案

I copied your code and gave the file a proper path and it worked.

My version:

FileInputStream file = new FileInputStream(new File("C:\\Users\\user\\Desktop\\filet.xlsm"));

System.out.println("found file");

XSSFWorkbook workbook = new XSSFWorkbook(file);

System.out.println("in workbook");

XSSFSheet sheet = workbook.getSheet("Shipments");

System.out.println("got sheet");

I think it has something to do with your pathing, or the file itself.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值