Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » OLE Understanding Excel Automation(writing values into cells - selecting specific sheets)
icon5.gif  OLE Understanding Excel Automation [message #521629] Thu, 18 March 2010 10:51 Go to next message
Mo is currently offline MoFriend
Messages: 12
Registered: March 2010
Junior Member
Hi,
I want to create an Excel OLE object, and write some values into this object (in a definite worksheet). How can I do this? I have found on a Japanese side the following example:

public class OleExcel extends OleClientSite {


	public static final String ID = "ExcelSheet";
	private static final int CELL_VALUE_ID = 0x00000006;
	private static final int CELL_ID = 0x000000c5;
	private static final int SHEET_ID = 0x000001e5;
	private OleAutomation cell;


	public OleExcel(Composite parent, int style, File file	) {
		super(parent, style, file);

		OleAutomation workbook = new OleAutomation(this);
		OleAutomation worksheet = workbook.getProperty(SHEET_ID,
				new Variant[] { new Variant(1) }).getAutomation();

	
			cell = worksheet.getProperty(CELL_ID,new Variant[] { new Variant("A1") }).getAutomation();
			cell.setProperty(CELL_VALUE_ID, new Variant("Testeintrag"));
	}

}


But where do the ID's? I would prefer to solve the whole thing, like"... GetIDsOfNames (new String [] (" xxx ")".
Someone an idea? How I write in certain sheets?

I have begun linke this:

	
...
@Override
	public void createPartControl(Composite parent) {

		try {

			try {
				OleFrame frame = new OleFrame(parent, SWT.NONE);
				site = new OleClientSite(frame, SWT.NONE, "Excel.Sheet");
			
			
				//get an Excel workbook       
			     OleAutomation workbook = new OleAutomation(site); 

			     // activeSheet
			     int [] ids = workbook.getIDsOfNames(new String[]{"ActiveSheet"});


			
			} catch (SWTError e) {
				System.out.println("Unable to open activeX control");
				return;
			}

	
			
		} catch (SWTError e) {
			System.out.println("Unable to open activeX control");
			return;
		}
	}



I'm really desperate. I can´t find any reasonable docu Sad

greetings, mo

[Updated on: Thu, 18 March 2010 11:19]

Report message to a moderator

Re: OLE Understanding Excel Automation [message #522477 is a reply to message #521629] Mon, 22 March 2010 17:55 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

I think you're looking for a reference like
http://msdn.microsoft.com/en-us/library/aa272268(office.11).aspx . As an
added bonus, here's a utility class that I've found to be quite helpful in
the past. You can pass it any OleAutomation and it will write to stdout all
of its properties and methods with ids and descriptions (if available).

public class OLEDisplayAPI {

public static void printAPI(OleAutomation auto) { // <---
TYPEATTR typeattr = auto.getTypeInfoAttributes();
printMethods(auto, typeattr);
printProperties(auto, typeattr);
}
private static void printProperties(OleAutomation auto, TYPEATTR typeattr) {
if (typeattr != null) {
if (typeattr.cVars > 0) System.out.println("\n\nVariables :");
for (int i = 0; i < typeattr.cVars; i++) {
OlePropertyDescription data = auto.getPropertyDescription(i);
System.out.println("PROPERTY (id = " + data.id + ") :");
System.out.println("\tName : " + data.name);
System.out.println("\tType : " + getTypeName(data.type) + "\n");
}
}
}
private static void printMethods(OleAutomation auto, TYPEATTR typeattr) {
if (typeattr.cFuncs > 0) System.out.println("Methods:");
for (int i = 0; i < typeattr.cFuncs; i++) {
OleFunctionDescription data = auto.getFunctionDescription(i);
String argList = "";
int firstOptionalArgIndex = data.args.length -
data.optionalArgCount;
for (int j = 0; j < data.args.length; j++) {
argList += "[";
if (j >= firstOptionalArgIndex) argList += "optional, ";
argList += (getDirection(data.args[j].flags) + "] "
+ getTypeName(data.args[j].type) + " " + data.args[j].name);
if (j < (data.args.length - 1)) argList += ", ";
}
System.out.println(getInvokeKind(data.invokeKind) + " (id = " +
data.id + ") : ");
System.out.println("\tSignature : " + getTypeName(data.returnType) +
" " + data.name + "(" + argList + ")");
System.out.println("\tDescription : " + data.documentation);
System.out.println("\tHelp File : " + data.helpFile + "\n");
}
}
private static String getTypeName(int type) {
switch (type) {
case OLE.VT_BOOL: return "boolean";
case OLE.VT_R4: return "float";
case OLE.VT_R8: return "double";
case OLE.VT_I4: return "int";
case OLE.VT_DISPATCH: return "IDispatch";
case OLE.VT_UNKNOWN: return "IUnknown";
case OLE.VT_I2: return "short";
case OLE.VT_BSTR: return "String";
case OLE.VT_VARIANT: return "Variant";
case OLE.VT_CY: return "Currency";
case OLE.VT_DATE: return "Date";
case OLE.VT_UI1: return "unsigned char";
case OLE.VT_UI4: return "unsigned int";
case OLE.VT_USERDEFINED: return "UserDefined";
case OLE.VT_HRESULT: return "int";
case OLE.VT_VOID: return "void";
case OLE.VT_BYREF | OLE.VT_BOOL: return "boolean *";
case OLE.VT_BYREF | OLE.VT_R4: return "float *";
case OLE.VT_BYREF | OLE.VT_R8: return "double *";
case OLE.VT_BYREF | OLE.VT_I4: return "int *";
case OLE.VT_BYREF | OLE.VT_DISPATCH: return "IDispatch *";
case OLE.VT_BYREF | OLE.VT_UNKNOWN: return "IUnknown *";
case OLE.VT_BYREF | OLE.VT_I2: return "short *";
case OLE.VT_BYREF | OLE.VT_BSTR: return "String *";
case OLE.VT_BYREF | OLE.VT_VARIANT: return "Variant *";
case OLE.VT_BYREF | OLE.VT_CY: return "Currency *";
case OLE.VT_BYREF | OLE.VT_DATE: return "Date *";
case OLE.VT_BYREF | OLE.VT_UI1: return "unsigned char *";
case OLE.VT_BYREF | OLE.VT_UI4: return "unsigned int *";
case OLE.VT_BYREF | OLE.VT_USERDEFINED: return "UserDefined *";
}
return "unknown " + type;
}
private static String getDirection(int direction) {
String dirString = "";
boolean comma = false;
if ((direction & OLE.IDLFLAG_FIN) != 0) {
dirString += "in";
comma = true;
}
if ((direction & OLE.IDLFLAG_FOUT) != 0) {
if (comma) dirString += ", ";
dirString += "out";
comma = true;
}
if ((direction & OLE.IDLFLAG_FLCID) != 0) {
if (comma) dirString += ", ";
dirString += "lcid";
comma = true;
}
if ((direction & OLE.IDLFLAG_FRETVAL) != 0) {
if (comma) dirString += ", ";
dirString += "retval";
}
return dirString;
}
private static String getInvokeKind(int invKind) {
switch (invKind) {
case OLE.INVOKE_FUNC: return "METHOD";
case OLE.INVOKE_PROPERTYGET: return "PROPERTY GET";
case OLE.INVOKE_PROPERTYPUT: return "PROPERTY PUT";
case OLE.INVOKE_PROPERTYPUTREF: return "PROPERTY PUT BY REF";
}
return "unknown " + invKind;
}

}

Grant


<mo84@gmx.de> wrote in message news:hnt0jd$lv$1@build.eclipse.org...
> Hi,
> I want to create an Excel OLE object, and write some values into this
object (in a definite worksheet). How can I do this? I have found on a
Japanese side the following example:
>
> public class OleExcel extends OleClientSite {
>
>
> public static final String ID = "ExcelSheet";
> private static final int CELL_VALUE_ID = 0x00000006;
> private static final int CELL_ID = 0x000000c5;
> private static final int SHEET_ID = 0x000001e5;
> private OleAutomation cell;
>
>
> public OleExcel(Composite parent, int style, File file ) {
> super(parent, style, file);
>
> OleAutomation workbook = new OleAutomation(this);
> OleAutomation worksheet = workbook.getProperty(SHEET_ID,
> new Variant[] { new Variant(1) }).getAutomation();
>
>
> cell = worksheet.getProperty(CELL_ID,new Variant[] { new
Variant("A1") }).getAutomation();
> cell.setProperty(CELL_VALUE_ID, new Variant("Testeintrag"));
> }
>
> }
>
> But where do the ID's? I would prefer to solve the whole thing, like"...
GetIDsOfNames (new String [] (" xxx ")".
> Someone an idea? How I write in certain sheets?
>
> I'm really desperate. I think any reasonable docu :(
>
> greetings, mo
>
>
Previous Topic:Excel ActiveX DisplayAlerts property
Next Topic:Swing AWT and SWT Browser
Goto Forum:
  


Current Time: Mon Dec 09 08:28:54 GMT 2024

Powered by FUDForum. Page generated in 0.04787 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top