Accessing Excel from Java using EZ JCom
The Java API for Excel can be built using EZ JCom,
just like the Java API for any other COM application. (The COM
file used in the built-in package for Excel is Excel9.OLB, other
versions of Excel e.g. Excel10.OLB can also be used.)
However, the Excel API is huge. Therefore
it has been pre-built and packaged with some sample
programs. Those interested in calling Excel
from Java should download this pre-packaged version
instead of using the tool directly.
Following are some brief Excel sample programs (also included in
the pre-packaged version.) Following the samples,
is a guideline explaining the programming steps.
Note that these samples are for "demonstration" purposes.
In typical usage as a calculation engine, the Excel application
will not be made visible and the "Quit" method would
be a part of the finalizations. (However, the Excel
application would need to be made visible if its
UI elements are to be used by the calling Java program.)
Excel Sample 1. This sample starts
up a copy of Excel, makes it visible, puts the value "33" in cell A1, and
leaves Excel running for the user.
Excel Sample 2. This sample starts
up a copy of Excel, DOES NOT make it visible, puts the value "33" in cell A1,
saves to file C:\JavaExcelSample.xls and exits the running copy of Excel.
Excel Sample 3. This sample starts
up a copy of Excel, makes it visible, opens the file C:\JavaExcelSample.xls,
puts a formula in B1 and one in B2, and copies the formulae to C1:F1 and B2:D5.
Leaves Excel running for the user.
Excel Sample 4. This sample starts
up a copy of Excel, populates in with data, and creates a chart from
cells B1:D5. Leaves Excel running for the user.
Excel Sample 5. Various simple
calculations using Excel.
Steps in programming the Excel COM interface