Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Hiding menus and toolbars from Excel Sheet


You should ask this question in the SWT newsgroup (http://www.eclipse.org/newsportal/thread.php?group=eclipse.platform.swt).

I don't think the menus show up by default unless you add them (at least, I don't see any menus when I run your example on my machine). However, the toolbars do show up but they are added by the Application.

However, you can turn off these menubars and toolbars by sending the application appropriate commands. I found these commands from MSDN after some digging.
Essentially, you have to send turn off the toolbars that you don't want visible. In VB, the syntax is something like this:

        exel.Application.CommandBars("Standard").Visible = false;
        exel.Application.ToolBars("Standard").Visible = false;

I added the following lines of code to your original code to hide the toolbars:

                        OleAutomation sheet = new OleAutomation(clientSite);
                        OleAutomation application = getAutoProperty(sheet, "Application");
                        OleAutomation standard = getAutoProperty(application, "ToolBars",
                                        new Variant("Standard"));
                        setProperty(standard, "Visible", new Variant(false));
                        OleAutomation formatting = getAutoProperty(application, "ToolBars",
                                        new Variant("Formatting"));
                        setProperty(formatting, "Visible", new Variant(false));

See complete code below.

Duong


package swt.examples.ole;

import java.io.*;

import org.eclipse.swt.*;
import org.eclipse.swt.ole.win32.*;
import org.eclipse.swt.widgets.*;

public class Try2 {
        private Shell shell;

        static OleClientSite clientSite;

        public Shell open(Display display) {
                this.shell = new Shell(display, SWT.MIN);

                final Button saveChangesButton = new Button(shell, SWT.NONE);
                saveChangesButton.setText("Save Changes");
                saveChangesButton.setBounds(64, 405, 93, 23);

                OleFrame frame = new OleFrame(shell, SWT.NONE);
                frame.setBounds(0, 0, (shell.getSize().x) - 5, 400);
                final File file = new File("e:/temp/ole/test.xls");
                try {
                        clientSite = new OleClientSite(frame, SWT.NONE, file);
                        this.shell.layout();
                        clientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);

                        OleAutomation sheet = new OleAutomation(clientSite);
                        OleAutomation application = getAutoProperty(sheet, "Application");
                        OleAutomation standard = getAutoProperty(application, "ToolBars",
                                        new Variant("Standard"));
                        setProperty(standard, "Visible", new Variant(false));
                        OleAutomation formatting = getAutoProperty(application, "ToolBars",
                                        new Variant("Formatting"));
                        setProperty(formatting, "Visible", new Variant(false));
                } catch (SWTException ex) {
                        System.out.println(ex.getMessage());
                        return null;
                }

                Listener saveChangesButtonListner = new Listener() {
                        public void handleEvent(Event event) {
                                if (clientSite.isDirty())
                                        clientSite.save(file, true);
                        }
                };

                saveChangesButton.addListener(SWT.Selection, saveChangesButtonListner);
                shell.open();
                return shell;
        }

        private static int property(OleAutomation auto, String name) {
                return auto.getIDsOfNames(new String[] { name })[0];
        }

        private OleAutomation getAutoProperty(OleAutomation auto, String name) {
                Variant varResult = auto.getProperty(property(auto, name));
                if (varResult != null && varResult.getType() != OLE.VT_EMPTY) {
                        OleAutomation result = varResult.getAutomation();
                        varResult.dispose();
                        return result;
                }
                return null;
        }

        private static OleAutomation getAutoProperty(OleAutomation auto,
                        String name, Variant value) {
                Variant varResult = auto.getProperty(property(auto, name),
                                new Variant[] { value });
                if (varResult != null && varResult.getType() != OLE.VT_EMPTY) {
                        OleAutomation result = varResult.getAutomation();
                        varResult.dispose();
                        return result;
                }
                return null;
        }

        private static boolean setProperty(OleAutomation auto, String name,
                        Variant value) {
                return auto.setProperty(property(auto, name), value);
        }

        /**
         * @param args
         */
        public static void main(String[] args) {

                Display display = new Display();
                Shell shell = (new Try2()).open(display);
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
                clientSite.dispose();
                display.dispose();

        }

}




Sajid <sajid622@xxxxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

04/08/2008 08:48 AM

Please respond to
"Eclipse Platform SWT component developers list."        <platform-swt-dev@xxxxxxxxxxx>

To
<platform-swt-dev@xxxxxxxxxxx>
cc
Subject
[platform-swt-dev] Hiding menus and toolbars from Excel Sheet





Hi,

I'm very new to Java development, specially to SWT and OLE.

I used OleClientSite to display an Excel sheet on SWT shell. Though it displays fine, but my requirement is not to show any Excel menus and Tool bars so that user should not be able to save or apply formating etc. I have also read different answers at the mailing list and snippets at http://www.eclipse.org/swt/snippets/     that OleControlSite should be used for this purpose but still this does not solve my problem. Because still I can see the menus and toolbars, also the contents of my excel sheet does not get loaded and all the cells appear blank.

Can anybody help to solve this problem? Some code will be very helpful for me.
I have office 2007,  SWT 3.3.1 and JDK 5 installed. Below is my code:

public class Try2 {
   private Shell shell;
   
   static OleClientSite clientSite;
     
   public Shell open(Display display){
       this.shell=new Shell(display, SWT.MIN);
       
       final Button saveChangesButton = new Button(shell, SWT.NONE);
       saveChangesButton.setText("Save Changes");
       saveChangesButton.setBounds(64, 405, 93, 23);
               
       OleFrame frame = new OleFrame(shell,SWT.NONE);
       frame.setBounds(0, 0, (shell.getSize().x)-5, 400);
       final File file= new File("D:/Work/Worksheet1.xls");
       try{
           clientSite =  new OleClientSite(frame, SWT.NONE, file);
           this.shell.layout();
           
           clientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
           
      }catch(SWTException ex)
      {
          System.out.println(ex.getMessage());
          return null;
      }
       
       Listener saveChangesButtonListner = new Listener() {
           public void handleEvent(Event event) {
               
               if(clientSite.isDirty())
                   clientSite.save(file, true);
           }
       };
       
       saveChangesButton.addListener(SWT.Selection, saveChangesButtonListner);

       shell.open();
       return  shell;
   }
   
   /**
    * @param args
    */
   public static void main(String[] args) {
       
       Display display=new Display();
       Shell shell=(new Try2()).open(display);
       while(!shell.isDisposed()){
           if(!display.readAndDispatch()){
               display.sleep();
           }
       }
       clientSite.dispose();
       display.dispose();

   }

}



Connect to the next generation of MSN Messenger  Get it now! _______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top