简体   繁体   English

Apache POI和EXCEL

[英]Apache POI and EXCEL

I'm using Apache POI API to access an Excel .xlsx file, using the API I can read/write cells. 我正在使用Apache POI API来访问Excel .xlsx文件,并且使用可以读取/写入单元格的API。 My problem is: How can I do that with the .xlsx file opened in Excel GUI? 我的问题是:如何在Excel GUI中打开.xlsx文件来执行此操作? If I try to do that I have conflict arising from concurrent access to the same resource (The process cannot access the file because it is being used by another process). 如果我尝试这样做,则会因并发访问同一资源而产生冲突(该进程无法访问该文件,因为该文件正在被另一个进程使用)。 I have been told that the answer is Excel RTD and c#, c++ or other languages. 有人告诉我答案是Excel RTD和c#,c ++或其他语言。 BUT I want to stick with Java,what could I do? 但是我想坚持使用Java,该怎么办? Is switching to linux an option? 是否可以选择切换到linux? THANKS!!! 谢谢!!!

AFAIK poi only works on the file system, so there is no interaction through Real-Time Data. AFAIK poi仅适用于文件系统,因此没有通过实时数据进行交互。 I think you should not edit the xlsx file while it is still open in excel if you want to prevent corruption. 我想,如果您想防止损坏,则不应在excel中打开xlsx文件的同时对其进行编辑。

If you want to use RTD, you should try to find java bindings for that. 如果要使用RTD,则应尝试为此找到Java绑定。 I think they are COM based, so maybe JACOB can help you. 我认为它们基于COM,所以也许JACOB可以为您提供帮助。 http://sourceforge.net/projects/jacob-project/ http://sourceforge.net/projects/jacob-project/

See also this discussion: http://sourceforge.net/p/jacob-project/discussion/375946/thread/946012e8/ 另请参阅以下讨论: http : //sourceforge.net/p/jacob-project/discussion/375946/thread/946012e8/

Oh. 哦。 Btw. 顺便说一句。 COM is Windows only, so I would stay on Windows :) COM仅是Windows,所以我将停留在Windows上:)

Accessing and modifying a resources by 2 separate entities at the same time does not imply that you'll end up with a synchronized version at both ends. 同时由2个单独的实体访问和修改资源并不意味着您最终将在两端获得同步版本。 On the contrary, provided you manage to do so you have all the chances of ending up with an incorrect/bogus/corrupted result. 相反,只要您设法做到这一点,您就很有可能以错误/伪造/损坏的结果告终。 Translated into java, you may think of it as multiple threads altering a variable in an unsynchronized way. 转换成Java,您可能会认为它是多个线程以不同步的方式更改变量。

Some programs (notepad++, idea, eclipse on editor reactivation, etc) have implemented additional mechanisms which will detect if a file has been modified on the file-system outside the program itself, and provide you with options such as: reload file, ignore modifications, merge, etc, and others simply ignore these changes overwriting the file. 一些程序(notepad ++,想法,重新激活编辑器等)已经实现了其他机制,这些机制将检测文件是否在程序本身之外的文件系统上被修改,并为您提供以下选项:重新加载文件,忽略修改,合并等,而其他人只是忽略这些更改而覆盖文件。

My guess is you'd have to do a similar thing or rethink your scenario about updating the files and triggering notifications. 我的猜测是您将不得不做类似的事情或重新考虑有关更新文件和触发通知的方案。

As the other users said, there is no way to do this from poi. 正如其他用户所说,poi无法做到这一点。 Options: 选项:

Your best option is RTD (you write a thin RTD "server" in C#, install it in the registry, and talk to it from java, eg via some socket; within excel, users just enter RTD formulas in their cells, for which excel calls your rtd server to get the latest data). 最好的选择是RTD(您可以在C#中编写一个瘦RTD“服务器”,将其安装在注册表中,然后通过Java与之对话,例如通过某些套接字;在excel中,用户只需在其单元格中输入RTD公式即可,呼叫您的rtd服务器以获取最新数据)。

You can also write the data directly to excel using COM (there are also java libraries to do this, such as teamdev's jexcel, or you could write your own com wrappers). 您也可以使用COM将数据直接写入excel(也有java库来执行此操作,例如teamdev的jexcel,或者您可以编写自己的com包装器)。

You can write your own excel plugin. 您可以编写自己的excel插件。

Finally, there are lower level solutions which I've heard talk of but don't understand. 最后,我听说过一些较低级别的解决方案,但不了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM