Embedding Excel as an ActiveX Control in a Java Frame |
|
Excel is an ActiveX Document and is not an ActiveX Control. An ActiveX Document cannot be embedded in a VB or VC++ application. Therefore you can not embed it in a Java frame using J-Integra either.
You can however embed the "Microsoft Office Spreadsheet" control, which gives a similar effect. Use the \Program Files\Microsoft Office\Office\MSOWC.DLL type library.
The Spreadsheet control is documented by Microsoft here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/owcvba11/html/octocSpreadsheetObjectModel_HV01050209.asp?frame=true
This code embeds a spreadsheet in a frame, and loads an MS Excel Spreadsheet that has been saved in the CSV format. It assumes that you ran com2java on the MSOWC.DLL type library, specifying owc as the Java package name, and checking the Generate Java AWT classes option in the Options dialog box.
import java.awt.*; import java.awt.event.*;
public class EmbedSpreadsheet { public static void main(String[] args) throws Exception { Frame frame = new Frame ("Spreadsheet inside a Java Frame"); frame.setSize(new Dimension(500, 500)); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
owc.Spreadsheet spreadsheet = new owc.Spreadsheet(); spreadsheet.setSize(400,400); spreadsheet.setCSVURL("file:\\c:\\temp\\test.csv");
// Add Spreadsheet to the frame, and display the frame frame.add(spreadsheet, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } } |
Remember to include the \jre\bin directory in your PATH environment variable:
set PATH=C:\java\j2sdk1.4.2\bin;C:\java\j2sdk1.4.2\jre\bin;C:\jintegra\bin;%PATH%
The example assumes you have created a test spreadsheet in CSV format.