Java – How to read an excel when it is already open (Which is opened by clicking open button in a web application)?

huangapple go评论72阅读模式
英文:

Java - How to read an excel when it is already open (Which is opened by clicking open button in a web application)?

问题

我有一个应用程序,里面有一个按钮,当我点击它时,会提供两个选项,以保存或打开Excel报告。

当我保存后,我可以使用APACHE POI从下载文件夹中读取下载的Excel的数据。

但是当我点击“打开”按钮并打开Excel时,是否有任何方法可以从已打开的Excel中读取数据呢?(我需要验证Excel中的数据)。

谢谢,
Subbu。

英文:

I have an application where I have a button and when I click on it, it will provide me two options to save or open an excel report.

When I save it I can read the data from the downloads folder for the excel downloaded using APACHE POI.

But when I click on Open button and open the excel, is there any way to read data from the opened excel.(I need to verify the data in the excel).

Thank you,
Subbu.

答案1

得分: 1

在Excel中打开文件时,文件会被锁定,因此其他程序无法打开同一文件。

这种行为是有意设计的,它内建于Windows系统中,无法绕过。

您可以这样做:制作一个副本,然后在Excel中打开一个副本,在您的Java程序中打开另一个副本。

或者,您可以尝试找到一种以共享只读模式打开文件的方法 - 这是允许的,但只读模式必须由Excel和您的Java程序共同请求。

英文:

While the file is open in Excel it is locked, so the same file cannot be opened by any other program.

This behaviour is by design, it is built into Windows and there is no way around it.

What you can do is to make a copy, then open one copy in Excel and other in your Java program.

Alternatively, you could try to find a way to open the file in shared read-only mode - this is permitted, but the read-only mode has to be requested by both Excel and your Java program.

huangapple
  • 本文由 发表于 2020年10月25日 06:05:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/64518455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定