POI从只读XLSM文件中读

POI从只读XLSM文件中读

本文介绍了使用Java的Apache POI从只读XLSM文件中读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取使用Java的Apache POI从只读XLSM数据,但是当我使用XSSF工作簿它似乎并不能够访问该文件,并HSSF的工作簿只为XLS文件。我的code是这样的:

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");

在code从来没有达到工作簿中的打印行,我不知道为什么。请帮助!

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

推荐答案

我复制你的$ C $并给出该文件的正确的路径和它的工作。

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

我的版本:

 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.

这篇关于使用Java的Apache POI从只读XLSM文件中读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:53