[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] problem in automating Excel 2003

Hi!

I am automating Excel-2003 using SWT. I am having windows-2000 on my machine.

I am having a problem in line-16 in given code snippet:

Code:
-----
void OpenExcel()
{
1: Composite composite = new Composite(parent, SWT.NULL);
2: composite.setLayout(new FillLayout());

3: this.oleFrame = new OleFrame(composite, SWT.NULL);
4: this.clientSite = new OleClientSite(oleFrame, SWT.NONE, "Excel.Application");
6: this.clientSite.doVerb(OLE.OLEIVERB_OPEN);
7: this.dispInterface = new OleAutomation(clientSite);
8: this.application = this.dispInterface;
9: workbooks = getProperty(application, "Workbooks", null)getAutomation();
11: int rgdispid[] = workbooks.getIDsOfNames(new String[] { "Add" });
12: int dispIdMember = rgdispid[0];
13: Variant pVarResult = workbooks.invoke(dispIdMember);
14: Variant rgvarg[] = new Variant[1];
15: rgvarg[0] = new Variant((long)1);


16: workbook = getProperty(workbooks, "Item", rgvarg).getAutomation();

17: worksheets = getProperty(application, "Worksheets", null).getAutomation();
19: Variant rgvarg1[] = new Variant[1];
20: rgvarg1[0] = new Variant((long)1);
21: pVarResult = getProperty(worksheets, "Item", rgvarg1);
22: worksheet = pVarResult.getAutomation();
23: setProperty(application, "Visible", new Variant((boolean)true));
}


public Variant getProperty(OleAutomation automation, String strPropName, Variant param[])
{
1: Variant variant = null;
2: try
3: {
4: int rgdispid[] = automation.getIDsOfNames(new String[] { strPropName });
5: int dispIdMember = rgdispid[0];
6: if (param != null)
7: variant = automation.getProperty(dispIdMember, param);
8: else
9: variant = automation.getProperty(dispIdMember);
10: }
11. catch (SWTError e)
{
//Logging
}
14: return variant;
}




in function OpenExcel() i am getting the problem at line-16(fn openExcel()), which calls a fn getProperty(). In fn getProperty() dispIdMember is 170 for property "Item" which is correct but in line-7 of fn getProperty(), it returns null.

What could be the problem?

Regards,
Vicky