POI - 无法写入,而它在Excel中打开到文件? [英] POI - Cannot write to file while it is opened in Excel?
问题描述
我在网站上新的。我尝试打开它(使用POI / JAVA),而写入到一个Excel文件。
我得到了一个 java.io.FileNotFoundException
错误,当我试图创建一个文件输出流写入到文件中。
的FileOutputStream
没有工作。我收到此以下消息:
,因为它被另一个进程不能访问该文件
流程。
块引用>{尝试
FileOutputStream中FILEOUT;
XSSFWorkbook WB =新XSSFWorkbook(新的FileInputStream(Classeur.xlsm));
...
...
FILEOUT =新的FileOutputStream(Classeur.xlsm);
wb.write(FILEOUT);
fileOut.close();
}
赶上(FileNotFoundException异常五){
e.printStackTrace();
}
赶上(IOException异常五){
e.printStackTrace();
}有谁知道我怎么能解决这个问题?我正在一个书面方式(POI-Java的Swing的)应用程序动态读取Excel文件/写。
感谢您的帮助。
解决方案Windows本身不会让你这样做。在code没有什么让你这样做,我害怕。您需要首先关闭Excel中的文件。
编辑 - 我从你的描述,你有文件打开自己,在Excel中假设。您可能不会。但是别的东西肯定不会 - 它会成为你的Java应用程序的另一个实例,例如。即使做出这样Windows资源管理器的东西肯定不访问/使用文件,例如检查属性。直到你排除这一可能性,提到Windows本身会阻止你访问它。
I'm new on the website. I try to write to an excel file while it is opened (using POI / JAVA).
I got a
java.io.FileNotFoundException
error when i attempt to create a file output stream to write to the file.
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(); }
Does anybody know how i can fix it? i'm writting an (POI-Java-Swing) application to dynamically read/write in excel files.
Thanks for your help
解决方案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.
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屋!