Embed word starting with a specified file [message #1019256] |
Fri, 15 March 2013 06:22  |
Eclipse User |
|
|
|
I am creating an application where I need to embed word and start it with a given file, however the file might be one which is not an OLE document type associated with word but can be opened by word. As an example, word can open HTML, however if I use the OleClientSite constructor where I pass in a file it fails to embed word if the file is a html file.
The obvious solution seems to be use the constructor OleClientSite(Composite parent, int style, String progId, File file) however I notice the below warning in the documentation:
IMPORTANT: This method is not part of the public API for OleClientSite. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.
So it seems like I should not use it although it will work for my needs.
So what is the correct way to achieve what I want if the above should not be done?
Thanks in advance for help.
|
|
|
Re: Embed word starting with a specified file [message #1027231 is a reply to message #1019256] |
Tue, 26 March 2013 14:27  |
Eclipse User |
|
|
|
Hi,
I am also using this method.
clientSite = new OleControlSite(clientFrame, SWT.NONE,"Word.Document", source);
if you have debugged the OleControlSite and OleClient site classes, you can see that with the progID, the registry key for this entry is taken.
Today I had a case where a colleague/customer had Woprd.Document.8 instead of Word.Document.12 as an entry in the registry. So the app got an exception.
When you just give a file, the class reads its extension (.docx) and redirects it to the proper program which is entered for it in the registry.
public OleClientSite(Composite parent, int style, String progId, File file) {
this(parent, style);
try {
if (file == null || file.isDirectory() || !file.exists()) OLE.error(OLE.ERROR_INVALID_ARGUMENT);
appClsid = getClassID(progId);
if (appClsid == null) OLE.error(OLE.ERROR_INVALID_CLASSID);
// Are we opening this file with the preferred OLE object?
char[] fileName = (file.getAbsolutePath()+"\0").toCharArray();
GUID fileClsid = new GUID();
COM.GetClassFile(fileName, fileClsid);
OleCreate(appClsid, fileClsid, fileName, file);
} catch (SWTException e) {
dispose();
disposeCOMInterfaces();
throw e;
}
}
Here appClsid and fileClsId are equal if you have the proper registry entries.
I have another problem. I try to get a row from a table. Sometimes it works , but sometimes the Word application crashes.
This is the code:
public static Variant getRow(Variant tableVar, int rowIndex) throws OleException {
OleAutomation tableAuto = tableAuto = tableVar.getAutomation();
OleUtils.printAutomation(tableAuto);
Variant rowsVar = null;
while (rowsVar == null){
rowsVar = tableAuto.getProperty(101/*Rows*/);
}
OleAutomation rowsAuto = rowsVar.getAutomation();
Variant rowVar = rowsAuto.invoke(0/*Item*/, new Variant[]{new Variant(rowIndex)});
return rowVar;
}
I cannot understand why the application crashes. Any ideas may be?
|
|
|
Powered by
FUDForum. Page generated in 0.07467 seconds