[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] Accessing MS Word from SWT
|
Hi
I am trying to access MS word document from SWT, want to do some
modifications programatically and save the document. Please look into the
below code and let me know what i am missing to do the needed one.
And also i need to display menu bar in the ole container which displays the
word document so that i could provide an interface for the user to save the
document.
int i;
Display display = new Display();
Shell shell = new Shell(display);
swtTest t = new swtTest();
OleFrame frame = new OleFrame(shell, SWT.NONE);
frame.setLayoutData(new GridData(GridData.FILL_BOTH));
Menu bar = new Menu(shell, SWT.BAR);
shell.setMenuBar(bar);
shell.setLayout(new GridLayout());
File file = new File("C:\\Source\\Name.doc");
OleClientSite clientSite = new OleClientSite(frame,SWT.NONE,file);
OleAutomation oleAutomation = new OleAutomation(clientSite);
clientSite.setEnabled(true);
clientSite.setVisible(true);
frame.setVisible(true);
clientSite.setSize(900, 900);
i = clientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
frame.setSize(1000,1000);
if(i == OLE.S_OK) {
System.out.println("OK");
}
shell.open();
shell.setSize(1001, 1001);
if (clientSite.isDirty()) {
File tempFile = new File(file.getAbsolutePath() + ".tmp");
file.renameTo(tempFile);
if (clientSite.save(file, true)){
// save was successful so discard the backup
tempFile.delete();
} else {
// save failed so restore the backup
tempFile.renameTo(file);
}
}
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) {
display.sleep ();
}
}
display.dispose ();
}
Thanks
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail