Apache Poi 格式或扩展名无效,正在使用的文件被锁定以供其他用户编辑

问题描述 投票:0回答:0

我正在使用 Apache Poi 为我的项目创建一个 Excel 文件,但我在尝试时遇到了一些奇怪的问题。

public void createfile(Request request, Response response) throws Exception {
try {
        Integer id = ParamUtils.getParamInt(request, "id", null);
        Workbook workbook = new HSSFWorkbook();
        Sheet sheet = workbook.createSheet("new sheet");
        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        workbook.write(fileOut);
        fileOut.close();
        }
        catch (IncorrectData e) {
            return e;
        }

    }

首先,当我尝试打开使用此功能创建的文件时,出现 format or extension that is not valid 错误。其次,我得到了 file in use locked for editing by another user 但我在代码末尾明确关闭了 OutputStream。 最后一个问题,它是我服务器上的一个功能,我想知道我是否可以将这个 Excel 文件传递/返回到前端以下载它?

谢谢!

java excel apache apache-poi fileoutputstream
© www.soinside.com 2019 - 2024. All rights reserved.