VBA/excel to dll/exe for Java - java

I have an Excel file with manual input functions, which use an add-in from a third party. I want to use the functionality of the Excel file in Java. I could think of two ways of doing it:
code the functions in VBA, or VB with Excel reference, then generate .dll or .exe files for Java to use.
Feed data to an Excel file using jxl (would Excel file update automatically when it receives new data?), then read the new result every time from the Excel file.
I don't have much experience with Excel or VBA. I want to know which method is more doable and faster.

As your code is invoking a third-party add-in and is needs that for correct operation, then you will need to go the VB route or access Excel via the Automaton API (from Java, using for example, Com4j).
The reason is that the pure-java excel readers (jxl, Poi, xlSQL etc..) all use java to emulate the built in functionality of excel, but of cousre they cannot emulate third party add-ons.
Reading excel files using com4j is discussed in this thread.

Obba allows you to make calls from an Excel cell to a Java virtual machine (which may run on a different computer, if necessary). The JVM has to run Obba server (provided as a Java with main() method). The Obba server can load other JARs an instantiate objects via functional calls form the Excel sheet.
You could also use Obba to pass values, results to a Java code (or server).
(You may contact me, if you are interested in exploring this and need assistance (I work on Obba).

Related

Apache POI and EXCEL

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

How can I run Excel Macro from Java?

I've .txt files generated by Java (with databases queries). I need to generate an excel with that (with graphics and other kind of information, is not just a pure csv).
How can I call my excel macro using java?
I would say, have your Excel macro use the csv as a data source and let it do it's job directly.
Otherwise you might want to look into a reporting framework like jasper reports http://community.jaspersoft.com/project/jasperreports-library
You need to use a JAVA-to-COM bridge, such as Jacob. http://danadler.com/jacob/ there are other out there but I am familiar with Jacob. Then you would be able to start the application, load the file, run the macro, and then close the application. This should get you started.
Why not create an excel directly using java apache poi, instead of creating txt and then converting txt excel using macro.

Map Excel workbook with multiple sheets to XSD

I have an Excel workbook with multiple sheets. Each sheet holds a table, the different tables have different formats.
I need to read the entire workbook into my Java program. The most convenient method IMHO is to export the entire data into a single XML and parse it (using simpleXML or some other compatible parser).
I have found no method for applying a schema to multiple sheets of a workbook, only to a single sheet. Is it possible? If so, how?
When it comes to convenience, there are many factors that influence or define it. For example, it depends if this is an ongoing thing, or if it needs to be integrated into a process, etc.
Before recommending a solution as suggested, I would try to convince you to take a look at Apache's POI (the Java API for Microsoft Documents), specifically the Excel API. It gives you a Java API for your Java program that should allow you to read what you need pretty easily. It would be a one stop shop kind of thing.
Another approach might be to use Jdbc to Odbc and access the Excel via JDBC API (JDBC to ODBC provider). I can't tell from details in your question if your deployment model would allow for this (e.g. if you run on a platform that doesn't have an ODBC provider for Excel files), but on Windows for sure is an option; also, many places on internet detailing this approach.
If you insist on going down the XML export way, QTAssistant (I am associated with it) has a comprehensive solution (XML Builder) for generating XML from any supported relational data source. It provides a GUI and a command line. In your case it would need the XLS, an XSD which describes the XML you want to get out and a mapping file (basically another XML file) to create the XML you need. In general this feature is largely used to convert test data into XML for Web service calls, so it is geared towards a certain interaction pattern between the user, the tool, and the XML generation activities. If you're interested in more details, let me know.

Is there a tool that would replace passing Excel files back and forth and merging them?

Some legacy software relies on downloading multiple Excel files, merging the contents, sending it back out, someone far away making some changes to it, and then sending the modified Excel file back, where the next day the multiple Excel files will be downloaded again and merged with this file. Is there some tool (preferably for Java or that can be used from a Java program) that would allow me to replace this legacy code, as maintaining/extending it is only slightly preferable to self immolation?
I should add that the reason we're using Excel at all rather than a database is that some of the reports can only be exported as Excel, and on our end some of the staff are comfortable with using Excel formulas. So we would need something that they can edit in an Excel like way but that we can do all the above to otherwise.
Update: These files contain no images, just normal Excel data and formulas. I'm leaving "sending" generic because that can be changed pretty easily. It could be by FTP, by email, by web form, etc., doesn't really change the nature of the process.
Google Docs' spreadsheets should be considered.
If you're looking for a library for reading and writing excel files, take a look at http://jexcelapi.sourceforge.net/

Good xls exporter to generate excel sheets automatically with a few macros from any programming language?

We have a system which generates reports in XLS using Spreadsheet_Excel_Writer for smaller files and in case of huge files we just export them as CSVs.
We now want to export excel sheets which are multicolor etc. as a part of report generation, which in excel could be done through a few macros.
Is there any good exporter which generates the excel sheets with macros?(Spreadsheet_Excel_Writer cant do this) If it exists for PHP it would be amazing but if it exists for any other language, its fine we could interface it.
It's your "excel sheets with macros" that is going to cause you all end of problems. If you're on a Windows platform, with Excel installed, then PHP's COM extension should allow you to do this. Otherwise, I'm nor aware of any PHP library which allows you to create macros... not even PHPExcel. I suspect the same will apply with most languages, other than perhaps those running with .Net (and possibly Mono).
However, do you really need macros to play with colour? Can't you do this more simply with styles, and perhaps conditional formatting?
PS. What's your definition of "huge"?

Categories