Hello,
We are developing a java application which needs to display MSOffice documents and PDF´s inside a Java frame. We have downloaded the comfyJ demo to test it before purchasing a license but we are really confused. We have been able to generate the different stubs and executed the samples but we don't know how to customize the code.
What we really need is simply open a document in our hard disk. For instance, the “ExcelIntegrationSample” opens a new worksheet containing some data but we are not able to specify our document and open it.
The four documents in the “docs” folder (programmer’s guide and tutorial for ComfyJ and JNIWrapper) were read but we didn’t find the solution.
We will be very grateful if someone could help us. We would like to have an example properly working before getting a license.
Thanks in advance.
Enrique
Hi Enrique,
What do you mean by "how to customize the code"? Do you need to do something that is not demonstrated by the examples? If so, then I think it should be mentioned here that ComfyJ is just the Java COM bridge which allows integrating with different COM libraries. It does not provide the complete solutions for integrations with any particular product, simply because it's not possible. That is why our samples demonstrates only the basics of API usage. And if you need the further integration with a particular COM library (such as MS Word or any other) then definitely you need to know the API of the product which you are going to use.
For instance, the “ExcelIntegrationSample” opens a new worksheet containing some data but we are not able to specify our document and open it.
Well, that sample is designed to demonstrate how to open different excel documents. Please clarify - you cannot specify your document in a open file dialog (perhaps because there is no appropriate filter in it)? Or you are getting some exception during opening a file?
The four documents in the “docs” folder (programmer’s guide and tutorial for ComfyJ and JNIWrapper) were read but we didn’t find the solution.
Those were not intended to provide the particular solutions for integration with MS Word API or something else. They were designed to demonstrate different techniques and product usage.
-Serge
Hi Serge,
First of all, thank you very much for your quick answer.
What we need to do is to show the content of a file, for example "C:\myExcel.xls", inside a JFrame. ExcelIntegrationSample demonstrates who to open a blank document and how to complete some cells. What we are trying to do is to display the document “myExcel” in the frame, no a blank one. We don’t want the user to go to the “Open” option and select the file, we are interested in displaying it automatically. Is it possible using ComfyJ?
Thank you very much again.
Enrique
Hi Enrique,
Of course it's possible.
In order to open an Excel document you can use one of the following approaches:
1) Open a document using the OleContainer.createObject(File) method. For example, in the ExcelIntegrationSample.java class you need to change one line only:
// _container.createObject(DOCUMENT_PROGID);
_container.createObject(new File("C:\\FileName.xls"));
2) Open a required document via Excel API, using the generated stubs:
_Application application = getApplication();
Workbooks workbooks = application.getWorkbooks();
Variant unspecified = Variant.createUnspecifiedParameter();
workbooks.open(new BStr("C:\\FileName.xls"),
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
unspecified,
new Int32(0));
3) Open a required document using Automation:
IDispatch workbooks = ...;
Automation workbooksAutomation = new Automation(workbooks, true);
workbooksAutomation.invoke("open", "C:\\FileName.xls");
Please let me know if you have another questions.
-Serge