Home : Embedding Excel as an ActiveX Control in a Java Frame
Q30421 - HOWTO: Embedding Excel as an ActiveX Control in a Java Frame

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.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 7/14/2006.
Last Modified by No Author Name Available!.
Article has been viewed 11250 times.
Rated 5 out of 10 based on 11 votes.
Print Article
Email Article