Re: Jawin code sample for showing grouping level in Excel
"Mcnamara, Sean D" <[email protected]> Tue, 22 Aug 2006 08:35:11 -0400
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <57F935D6BB6B2543AF5D835DCE7CAF27029EF762@MD61EX100.ad.honeywell-tsi.com> |
ActiveSheet and Outline are considered DispatchPtr in Jawin. ActiveSheet
is a property of the Application dispatch.
Use the Jawin stub generator on Excel's tlb to get your Java source
files providing friendly APIs for you use. Otherwise you will have to
use the DispatchPtr interface.
The concept of "late bound" code in VBA can be achieved without the
Jawin stub generator:
/*UNTESTED CODE. NO WARRANTY*/
import org.jawin.*;
public static something() {
Ole32.CoInitialize();
DispatchPtr excelApp =3D new DispatchPtr("Excel.Application");
DispatchPtr activeSheet =3D excelApp.get("ActiveSheet");
DispatchPtr outline =3D activeSheet.get("Outline");
Object[] argReferences =3D new Object[2]; //all parameters must be a
reference type
argReferences[0] =3D new Integer(0); //RowLevels
argReferences[1] =3D new Integer(2); //ColumnLevels
outline.invoke("ShowLevels",argReferences); /*invoke the method
ShowLevels RowLevels:=3D0, ColumnLevels:=3D2 (assuming these are the =
first
and second parameters of the method. If not, pass null values into the
array for the omitted arguments)*/
}
The Java code above has the following VB equivalent:
Sub something()
Dim excelApp As Object, activeSheet As Object, outline As Object
Set excelApp =3D CreateObject("Excel.Application")
Set activeSheet =3D excelApp.ActiveSheet
Set outline =3D activeSheet.Outline
Outline.ShowLevels RowLevels:=3D0, ColumnLevels:=3D2
End Sub
The concept of "early bound" code in VBA can be achieved by first using
the Jawin stub generator. I'm not sure exactly how it names its classes
for Excel, but it's a little more intuitive:
/*UNTESTED CODE. NO WARRANTY*/
import org.jawin.*;
Import org.ExcelStubs.*; /*this package could be called anything you
choose it to be*/
public static something() {
Ole32.CoInitialize();
_Application excelApp =3D new _Application();
=20
_Worksheet ws =3D excelApp.getActiveSheet();
_Outline ol =3D ws.getOutline();
ol.ShowLevels(new Integer(0),new Integer(2));
}
Get it?
-Sean
-----Original Message-----
From: Discussion of Java/Win32/COM integration with Jawin
[mailto:[email protected]] On Behalf Of Juhnyoung Lee
Sent: Monday, August 21, 2006 5:10 PM
To: [email protected]
Subject: [JAWIN] Jawin code sample for showing grouping level in Excel
I am looking for a Jawin API code sample that shows grouping levels in
Excel. Examples of VBA code in Excel are simply
ActiveSheet.Outline.ShowLevels RowLevels:=3D1
or
ActiveSheet.Outline.ShowLevels RowLevels:=3D0, ColumnLevels:=3D2
Will greatly appreciate sample code in Jawin API for this VBA code.
Thanks,
Juhnyoung