POI - 在 Excel 中打开文件时无法写入文件? [英] POI - Cannot write to file while it is opened in Excel?

查看:40
本文介绍了POI - 在 Excel 中打开文件时无法写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网站上的新手.我尝试在打开时写入 excel 文件(使用 POI/JAVA).

I'm new on the website. I try to write to an excel file while it is opened (using POI / JAVA).

当我尝试创建文件输出流以写入文件时,出现 java.io.FileNotFoundException 错误.

I got a java.io.FileNotFoundException error when i attempt to create a file output stream to write to the file.

FileOutputStream 不起作用.我收到以下消息:

FileOutputStream didn't work. I receive this following message:

进程无法访问该文件,因为它正被另一个进程使用过程.

the process cannot access the file because it is being used by another process.

         try {
           FileOutputStream fileOut;
           XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("Classeur.xlsm")); 
           ...
           ...
           fileOut = new FileOutputStream("Classeur.xlsm");
           wb.write(fileOut);
           fileOut.close();
           }
        catch (FileNotFoundException e){
           e.printStackTrace();
           } 
        catch (IOException e) {
           e.printStackTrace();
           }

有人知道我该如何解决吗?我正在编写一个(POI-Java-Swing)应用程序来动态读/写excel文件.

Does anybody know how i can fix it? i'm writting an (POI-Java-Swing) application to dynamically read/write in excel files.

感谢您的帮助

推荐答案

Windows 本身不会让您这样做.恐怕您的代码中没有任何内容可以让您这样做.您需要先在 Excel 中关闭该文件.

Windows itself will not let you do this. Nothing in your code will let you do so, I'm afraid. You need to close the file in Excel first.

编辑 - 根据您的描述,我假设您已经在 Excel 中自己打开了文件.你可能不是.然而,当然还有其他事情 - 例如,它可能是您的 Java 应用程序的另一个实例.甚至确保像 Windows 资源管理器这样的东西没有访问/使用该文件,例如检查属性.在您排除这种可能性之前,正如前面提到的,Windows 本身会阻止您访问它.

Edit - I am assuming from your description that you've got the file open yourself, in Excel. You might not be. However something else certainly does - it could be another instance of your Java application, for example. Even make sure stuff like Windows Explorer isn't accessing/using the file, e.g. to check attributes. And until you rule that out, as mentioned Windows itself will block you accessing it.

这篇关于POI - 在 Excel 中打开文件时无法写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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