使用 JAVA 和 APACHE-POI 3.6 访问时打开的 Excel 如何关闭?
我们正在 JAVA 中开发应用程序,并使用 APACHE POI 3.6 来访问 Ms-Excel 文件。假设,我的Excel文件正在打开,当运行我的程序时,它会引发错误并终止程序。所以,首先我想检查我的Excel是否打开。如果它正在打开,那么我想关闭我的Excel文件,然后打开并读取该文件...
We are developing application in JAVA AND using APACHE POI 3.6 for accessing Ms-Excel files. Suppose,my Excel file is opening, when running my program, then it raising the error and program terminated.So, First i want to check that whether my excel is opened or not.If it is opening, then i want to close my excel file and then open and read that file...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
POI 根本不运行 Excel。它是打开 Excel 文件并解释内容的独立代码。 java 代码没有直接的方法与 Excel 进行通信并检查它是否正在运行。您可以研究 Java/COM 桥来尝试协调的复杂机制。
POI does not run Excel at all. It is independent code that opens your excel file and interprets the contents. There is no straightforward way for you java code to communicate with Excel and check to see if it is running. You can look into Java/COM bridges for complex mechanisms for trying to coordinate.
我认为在 Java 中您能做的最好的事情就是检查是否有人使用
File
的canWrite()
方法锁定文件进行编辑。班级。不过,您无法强制用户关闭 Excel 文件。如果应用程序有 GUI,您可以向用户发布一条消息,请求他们手动关闭文件。
I think the best you're going to be able to do from within Java is to check if someone has the file locked for editing using the
canWrite()
method of theFile
class.You're not going to be able to force the user to close the excel file though. If the application has a GUI you could post a message to the user requesting they close the file manually.