Pregunta

I'm using Apache POI API to access an Excel .xlsx file, using the API I can read/write cells. My problem is: How can I do that with the .xlsx file opened in Excel GUI? 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. BUT I want to stick with Java,what could I do? Is switching to linux an option? THANKS!!!

¿Fue útil?

Solución

AFAIK poi only works on the file system, so there is no interaction through Real-Time Data. I think you should not edit the xlsx file while it is still open in excel if you want to prevent corruption.

If you want to use RTD, you should try to find java bindings for that. I think they are COM based, so maybe JACOB can help you. http://sourceforge.net/projects/jacob-project/

See also this discussion: http://sourceforge.net/p/jacob-project/discussion/375946/thread/946012e8/

Oh. Btw. COM is Windows only, so I would stay on Windows :)

Otros consejos

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. 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.

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.

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. 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, e.g. 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).

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).

You can write your own excel plugin.

Finally, there are lower level solutions which I've heard talk of but don't understand.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top