Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2008, 04:33 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Word OLE
Code:
import java.io.File; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.ole.win32.OLE; import org.eclipse.swt.ole.win32.OleAutomation; import org.eclipse.swt.ole.win32.OleClientSite; import org.eclipse.swt.ole.win32.OleControlSite; import org.eclipse.swt.ole.win32.OleFrame; import org.eclipse.swt.ole.win32.Variant; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; public class WordOLE extends ApplicationWindow { OleFrame oleFrame; OleClientSite clientSite; OleControlSite controlSite; /** * @param parentShell */ public WordOLE(Shell parentShell) { super(parentShell); addMenuBar(); addToolBar(SWT.FLAT); } /* * (non-Javadoc) * * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite) */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new FillLayout()); oleFrame = new OleFrame(composite, SWT.NULL); if (getMenuBarManager() != null) { MenuItem windowMenu = new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE); windowMenu.setText("[Window]"); MenuItem containerMenu = new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE); containerMenu.setText("[Container]"); MenuItem fileMenu = new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE); fileMenu.setText("[File]"); oleFrame.setWindowMenus(new MenuItem[] { windowMenu }); oleFrame.setContainerMenus(new MenuItem[] { containerMenu }); oleFrame.setFileMenus(new MenuItem[] { fileMenu }); System.out.println("menu set"); } clientSite = new OleClientSite(oleFrame, SWT.NULL, new File("test.doc")); // clientSite = new OleClientSite(oleFrame, SWT.NONE, // "Word.Document.8"); // clientSite = new OleControlSite(oleFrame, SWT.NONE, // "Word.Document.8"); System.out.println(clientSite.getProgramID() + ", " + clientSite); clientSite.doVerb(OLE.OLEIVERB_SHOW); return composite; } /* * (non-Javadoc) * * @see org.eclipse.jface.window.ApplicationWindow#createToolBarManager(int) */ protected ToolBarManager createToolBarManager(int style) { ToolBarManager manager = new ToolBarManager(style); Action actionSaveAs = new Action("Save as") { public void run() { FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); String path = dialog.open(); if (path != null) { if (clientSite.save(new File(path), false)) { System.out.println("Saved to file successfully."); } else { System.err.println("Failed to save to file"); } } } }; Action actionDeactivate = new Action("Deactivate") { public void run() { clientSite.deactivateInPlaceClient(); } }; Action actionSpellCheck = new Action("Spell check") { public void run() { if ((clientSite.queryStatus(OLE.OLECMDID_SPELL) & OLE.OLECMDF_ENABLED) != 0) { clientSite.exec( OLE.OLECMDID_SPELL, OLE.OLECMDEXECOPT_PROMPTUSER, null, null); } } }; Action actionOAGetSpellingChecked = new Action("OA: Get SpellingChecked") { public void run() { OleAutomation automation = new OleAutomation(clientSite); // looks up the ID for property SpellingChecked. int[] propertyIDs = automation.getIDsOfNames(new String[]{"SpellingChecked"}); int propertyID = propertyIDs[0]; Variant result = automation.getProperty(propertyID); System.out.println("SpellingChecked: " + result.getBoolean()); automation.dispose(); } }; Action actionOASetSpellingChecked = new Action("OA: Set SpellingChecked") { public void run() { OleAutomation automation = new OleAutomation(clientSite); // looks up the ID for property SpellingChecked. int[] propertyIDs = automation.getIDsOfNames(new String[]{"SpellingChecked"}); int propertyID = propertyIDs[0]; boolean result = automation.setProperty(propertyID, new Variant(true)); System.out.println(result ? "Successful" : "Failed"); automation.dispose(); } }; Action actionOAInvokePrintPreview = new Action("OA: Invoke Select") { public void run() { OleAutomation automation = new OleAutomation(clientSite); // looks up the ID for method Select.int[] methodIDs = automation.getIDsOfNames(new String[]{"Select"}); int methodID = methodIDs[0]; Variant result = automation.invoke(methodID); System.out.println(result != null ? "Successful" : "Failed"); System.out.println(result); automation.dispose(); } }; manager.add(actionSaveAs); manager.add(actionDeactivate); manager.add(actionSpellCheck); manager.add(actionOAGetSpellingChecked); manager.add(actionOASetSpellingChecked); manager.add(actionOAInvokePrintPreview); return manager; } public static void main(String[] args) { WordOLE wordOLE = new WordOLE(null); wordOLE.setBlockOnOpen(true); wordOLE.open(); Display.getCurrent().dispose(); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The 3 Word Story [Mini Game] Eku Forum Lobby 90 11-16-2008 11:01 PM
Word Scramble lk9865 New To Java 5 11-17-2007 04:22 AM
Help with a word, if it is divided by spaces baltimore New To Java 1 08-07-2007 08:31 AM
How to update Existing Word Doc Using java umashankar Advanced Java 1 07-27-2007 03:29 PM
How to know the exact word on which the mouse is, in a JTextArea JavaBean AWT / Swing 1 05-19-2007 02:03 PM


All times are GMT +3. The time now is 08:06 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org