Hello,
I'am trying to modify the ExcelIntegrationSample from ComFYJ so that i can hide/disable toolbars.
Unfortunately i'm reciving exceptions and the code does not work.
For example:
_Workbook workbook = new _WorkbookImpl(_container.getOleObject());
Window window = workbook.getApplication().getActiveWindow();
if(window.getDisplayFormulas().getBooleanValue()){
window.setDisplayFormulas(VariantBool.FALSE);
}
Or
int size = (int) cb.getCount().getValue();
for (int i = 1; i < size; i++) {
CommandBar c = cb.getItem(new Variant(i));
c.setVisible(VariantBool.FALSE);
}
I Would greatly appriciate an working example of how to modify excel user interface from ComFYJ.
Also wonder why the simple invocations like following throw exceptions?
Does it need to be called in special thread, maybe it has to do with vm or office version ?
window.setDisplayFormulas(VariantBool.FALSE);
window.setDisplayGridlines(VariantBool.FALSE);
Thanks,
Krzysztof
Hi Krzysztof,
What kind of exception are you actually receiving? If it's a COM marshalling exception then this code should be invoked in the OleMessageLoop of the _container object, for example:
_container.getOleMessageLoop().doInvokeAndWait(new Runnable() {
public void run() {
// your code
}
}
Also, please take a look at our JExcel product which provides the convenient Java API for Excel and you should not care about marshalling.
-Serge
Hi Serge,
Thanks for the quick replay,
I've put the code to hide the display formulas into the OleMessageLoop, but still i'm receiving the exception:
Caused by: com.jniwrapper.win32.automation.AutomationException: COM object method returns error code: 0x80020009; DISP_E_EXCEPTION (Exception occurred.)
The exception is called when the following method is invoked:
window = workbook.getApplication().getActiveWindow();
window.setDisplayFormulas(VariantBool.FALSE);
I will have a look at JExcel, but i'm interested in embeding also other office ole objects (word maybe browser), with basic functionality. That's why i'm trying to hide the toolbars from excel view.
Other examples from the ComFyJ work perfectly fine, and i'm able to sysout for example names of the command bars, but seems that the modification of the gui in general does not work.
I wonder if it's the case (more steps == code involved, in the modifications of the gui), or rather i'm doing something wrong. If it's possible to modify the gui, sample would help.
Thanks,
Krzysztof
Hi Krzysztof,
We could not reproduce such DISP_E_EXCEPTION exception in our test environment. Could you please send us a complete test case? Also, please clarify how did you generate the stubs for Excel, was the "Prefer Automation" option enabled in Codegen application?
Also, it is possible to get the cause of the AutomationException, for example:
try {
// function call
} catch (AutomationException e) {
ExcepInfo info = e.getExceptionInformation();
String description = getBstrDescription();
System.err.println(description);
}
This code should print out the detailed exception information, so we can understand what COM component complains about.
Thanks.
-Serge
Hi Serge,
Well generation is a second problem i have.
It's failing when i'm trying to generate the stubs,
To be able to compile the project i had to replace the the UInt32 with ULongInt and manually fix some problems, i managed to build the classes and make a jar. I've later downloaded a builded jar which i've found somewhere on this forum. (link: ftp://ftp.teamdev.com/updates/msexcel.jar) and tested with this one as well.
As I said, samples and some of the methods do work.
I'm testing the library in the vm - operating system windows xp, office 2007 but unregistered version (asks for the registration number on startup).
As for the exception message, thank you for the code, i've added and catched the exception, here is the output for hiding the formulas bar:
"Unable to set the DisplayFormulas property of the Window class"
Please find the code attached.
Thanks,
Krzysztof
Hi Krzysztof,
Thanks for the update. We managed to run your updated example without any exception. You have mentioned that in your case the version of MS Office is not registered. That probably could be the explanation why that exception occurs.
-Serge
Hi Serge,
I've checked the code with the activated Office and it works perfectly.
Thanks for your help.
Krzysztof