是否有使用OLE自动化(从Java)一个很好的参考? [英] Is there a good reference for using OLE Automation (from Java)?
问题描述
我想从Java / SWT应用程序与Excel进行通信。我已经能够打开一个工作表,打开一个文件并将其保存,但仅此而已。
任何人都可以点我为此一些文档/例子吗?我特别需要知道哪些命令可用。我曾尝试录制宏检查。这是有用的,但没有给我我想要的一切。
这是我迄今已尝试的例子:
私有静态了oleautomation中openFile(
自动化了oleautomation,字符串文件名){
变体的工作簿= automation.getProperty(0x0000023c); //获取用户
//定义
//工作簿
变体[] =参数新变种[1];参数[0] =新变种(文件名);
的System.out.println(工作簿:: \\ t的工作簿+);的IDispatch P1 = workbooks.getDispatch();
INT [] = rgdispid workbooks.getAutomation()的GetIDsOfNames(新的String [] {打开});
INT dispIdMember = rgdispid [0];
变体的工作簿= workbooks.getAutomation()调用(dispIdMember,参数)。
的System.out.println(打开工作簿);
尝试{
视频下载(500);
}赶上(InterruptedException的E){
e.printStackTrace();
}
INT ID = workbook.getAutomation()的GetIDsOfNames(新的String [] {ActiveSheet})[0]。
的System.out.println(ID);
变体片= workbook.getAutomation()的getProperty(ID)。
了oleautomation sheetAutomation = sheet.getAutomation();回报(sheetAutomation);
}
不是一个文件,但因为你通过自动化询问了可用的命令:你尝试过附带在Windows 2000 Resource Kit中的OLE / COM对象查看器?下载<一个href=\"http://download.microsoft.com/download/win2000platform/oleview/1.00.0.1/nt5/en-us/oleview_setup.exe\"相对=nofollow>此处。
I am trying to communicate with Excel from a Java/SWT application. I have been able to open a worksheet, open a file and save it but that's about it.
Can anyone point me to some documentation/examples for this? I especially need to know which commands are available. I did try to record macros to inspect. This was useful but did not give me everything I wanted.
This is a sample of what I have been trying so far:
private static OleAutomation openFile(
OleAutomation automation, String fileName) {
Variant workbooks = automation.getProperty(0x0000023c);// get User
// Defined
// Workbooks
Variant[] arguments = new Variant[1];
arguments[0] = new Variant(fileName);
System.out.println("workbooks::\t" + workbooks);
IDispatch p1 = workbooks.getDispatch();
int[] rgdispid = workbooks.getAutomation().getIDsOfNames(new String[] { "Open" });
int dispIdMember = rgdispid[0];
Variant workbook = workbooks.getAutomation().invoke(dispIdMember, arguments);
System.out.println("Opened the Work Book");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
int id = workbook.getAutomation().getIDsOfNames(new String[] { "ActiveSheet" })[0];
System.out.println(id);
Variant sheet = workbook.getAutomation().getProperty(id);
OleAutomation sheetAutomation = sheet.getAutomation();
return (sheetAutomation);
}
Not a documentation, but since you asked about the available commands via automation: have you tried the OLE/COM Object viewer that comes with the Windows 2000 resource kit? Download here.
这篇关于是否有使用OLE自动化(从Java)一个很好的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!