Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Excel in SWT
Excel in SWT [message #462802] Wed, 19 October 2005 17:22 Go to next message
Eclipse UserFriend
Originally posted by: rigolet.j.fr.ibm.com

This is a multi-part message in MIME format.
--------------000508010506070002030503
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Is there a working sample of a viewpart displaying & editing a an Excel
file somewhere?
We tried different things & the best we get was by embedding the OLE
object within the IE browser. Doing so, we couldn't get any Excel
toolbar - toolbar we could have by just creating the ole frame in the
view - but this time without any access to the xls file.

Remark: we also want to programatically read & make updates to the xls
content.

Thank you.


Attached is the view we're using.


--------------000508010506070002030503
Content-Type: text/plain;
name="View.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="View.java"

package jPMCDesktop;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.ole.win32.OLE;
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.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.part.ViewPart;

public class View extends ViewPart {
public static final String ID = "JPMCDesktop.view";

private String PROGRAM_ID = "Excel.Sheet";

/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
OleFrame frame = new OleFrame(parent, SWT.NONE);

Shell shell = parent.getShell();
Menu bar = new Menu(shell, SWT.BAR);

MenuItem fileItem1 = new MenuItem(bar, SWT.CASCADE);
fileItem1.setText("File Item 1");
MenuItem fileItem2 = new MenuItem(bar, SWT.CASCADE);
fileItem1.setText("File Item 2");

MenuItem containerItem = new MenuItem(bar, SWT.CASCADE);
containerItem.setText("Container Item");

MenuItem windowItem1 = new MenuItem(bar, SWT.CASCADE);
windowItem1.setText("Window Item 1");
MenuItem windowItem2 = new MenuItem(bar, SWT.CASCADE);
windowItem2.setText("Window Item 2");

frame.setFileMenus(new MenuItem[] { fileItem1, fileItem2 });
frame.setContainerMenus(new MenuItem[] { containerItem });
frame.setWindowMenus(new MenuItem[] { windowItem1, windowItem2 });

File file = new File("C://Conges.XLS");
OleClientSite clientSite = new OleClientSite(frame, SWT.NONE, file);
clientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);

}

/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}
--------------000508010506070002030503--
Re: Excel in SWT [message #462803 is a reply to message #462802] Wed, 19 October 2005 17:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

Sorry, no idea about the OLE side of the problem. But for
programatically accessing Excel files, the following is useful:
http://www.andykhan.com/jexcelapi/

Regards,
Friederich


JYR wrote:
> Is there a working sample of a viewpart displaying & editing a an Excel
> file somewhere?
> We tried different things & the best we get was by embedding the OLE
> object within the IE browser. Doing so, we couldn't get any Excel
> toolbar - toolbar we could have by just creating the ole frame in the
> view - but this time without any access to the xls file.
>
> Remark: we also want to programatically read & make updates to the xls
> content.
>
> Thank you.
>
>
> Attached is the view we're using.
>
>
> ------------------------------------------------------------ ------------
>
> package jPMCDesktop;
>
> import java.io.File;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.SWTException;
> import org.eclipse.swt.ole.win32.OLE;
> 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.widgets.Composite;
> import org.eclipse.swt.widgets.Menu;
> import org.eclipse.swt.widgets.MenuItem;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.ui.part.ViewPart;
>
> public class View extends ViewPart {
> public static final String ID = "JPMCDesktop.view";
>
> private String PROGRAM_ID = "Excel.Sheet";
>
> /**
> * This is a callback that will allow us to create the viewer and initialize
> * it.
> */
> public void createPartControl(Composite parent) {
> OleFrame frame = new OleFrame(parent, SWT.NONE);
>
> Shell shell = parent.getShell();
> Menu bar = new Menu(shell, SWT.BAR);
>
> MenuItem fileItem1 = new MenuItem(bar, SWT.CASCADE);
> fileItem1.setText("File Item 1");
> MenuItem fileItem2 = new MenuItem(bar, SWT.CASCADE);
> fileItem1.setText("File Item 2");
>
> MenuItem containerItem = new MenuItem(bar, SWT.CASCADE);
> containerItem.setText("Container Item");
>
> MenuItem windowItem1 = new MenuItem(bar, SWT.CASCADE);
> windowItem1.setText("Window Item 1");
> MenuItem windowItem2 = new MenuItem(bar, SWT.CASCADE);
> windowItem2.setText("Window Item 2");
>
> frame.setFileMenus(new MenuItem[] { fileItem1, fileItem2 });
> frame.setContainerMenus(new MenuItem[] { containerItem });
> frame.setWindowMenus(new MenuItem[] { windowItem1, windowItem2 });
>
> File file = new File("C://Conges.XLS");
> OleClientSite clientSite = new OleClientSite(frame, SWT.NONE, file);
> clientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
>
> }
>
> /**
> * Passing the focus request to the viewer's control.
> */
> public void setFocus() {
> }
> }


--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel 0241 160696-1
Fax 0221 726670
www.kupzog.de/fkmk
Re: Excel in SWT [message #462804 is a reply to message #462802] Wed, 19 October 2005 19:45 Go to previous messageGo to next message
Haris Peco is currently offline Haris PecoFriend
Messages: 1072
Registered: July 2009
Senior Member
JYR wrote:

> Is there a working sample of a viewpart displaying & editing a an Excel
> file somewhere?
> We tried different things & the best we get was by embedding the OLE
> object within the IE browser. Doing so, we couldn't get any Excel
> toolbar - toolbar we could have by just creating the ole frame in the
> view - but this time without any access to the xls file.
>
> Remark: we also want to programatically read & make updates to the xls
> content.
>
> Thank you.
>
>
> Attached is the view we're using.
you can try with OpenOffice and OfficeBean - you can display
and edit diferent files : *.xls , *.doc etc
see http://www.snpe.co.yu/index1.php?sadrzaj=html/ooswt.html
and screenshots on the end document
Peco
Re: Excel in SWT [message #462809 is a reply to message #462802] Wed, 19 October 2005 22:21 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
If you want excel to provide its own toolbar, you need to create an
embedded Ole Document which you do by creating an OleClientSite. The
toolbar will appear inside the bounds of the OleClientSite.

If you want to contribute to the toolbar at the top of eclipse, you will
need to contribute all toolbar items. You can create an OleControlSite
and use OleAutomation to access the data in excel.

There is an article on OLE support in SWT at:
http://eclipse.org/articles/Article-ActiveX%20Support%20in%2 0SWT/ActiveX%20Support%20in%20SWT.html

There are also some relevant code snippets :

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet199.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet186.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup
Previous Topic:SWT Browser crash
Next Topic:Problems with PrintDialog
Goto Forum:
  


Current Time: Fri Apr 19 12:00:06 GMT 2024

Powered by FUDForum. Page generated in 0.01686 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top