Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Print Preview does not work in SWT OLE Excel
Print Preview does not work in SWT OLE Excel [message #1229708] Fri, 10 January 2014 03:07 Go to next message
Vu Duy Gian is currently offline Vu Duy GianFriend
Messages: 2
Registered: January 2014
Junior Member
Dear all,

My project need embed Excel to view and print excel documents. I'm using SWT OLE and facing to a problem that print command of OLE Excel works perfectly but print preview command does nothing. Please, help me to debug this?

Here are my code:

package oletest;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

public class EmbeddingTest {

public static void main(final String[] args) {

Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(592, 426);

OleFrame frame = new OleFrame(shell, SWT.NONE);
frame.setBounds(10, 10, 391, 185);
final OleControlSite controlSite = new OleControlSite(frame, SWT.BORDER, new File("C:\\Book1.xlsx"));
controlSite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
controlSite.exec(OLE.OLECMDID_HIDETOOLBARS, OLE.OLECMDEXECOPT_DODEFAULT, null, null);

Button prinButton = new Button(shell, SWT.NONE);
prinButton.setText("Print");
prinButton.setBounds(115, 327, 98, 25);
prinButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
controlSite.exec(OLE.OLECMDID_PRINT, OLE.OLECMDEXECOPT_PROMPTUSER, null, null);
}
});
Button prinPreviewButton = new Button(shell, SWT.NONE);
prinPreviewButton.setText("Print Preview");
prinPreviewButton.setBounds(219, 327, 98, 25);
prinPreviewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
controlSite.exec(OLE.OLECMDID_PRINTPREVIEW, OLE.OLECMDEXECOPT_PROMPTUSER, null, null);
}
});
shell.open();
while (!shell.isDisposed()) {

if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();
}

}
Re: Print Preview does not work in SWT OLE Excel [message #1232195 is a reply to message #1229708] Thu, 16 January 2014 12:04 Go to previous messageGo to next message
Niraj Modi is currently offline Niraj ModiFriend
Messages: 48
Registered: November 2013
Member
Getting following error on running this snippet:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.swt.ole.win32.OleControlSite.disconnectEventSinks(OleControlSite.java:468)
at org.eclipse.swt.ole.win32.OleControlSite.releaseObjectInterfaces(OleControlSite.java:776)
at org.eclipse.swt.ole.win32.OleClientSite.onDispose(OleClientSite.java:909)
at org.eclipse.swt.ole.win32.OleClientSite.access$1(OleClientSite.java:895)
at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:129)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4351)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1085)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
at org.eclipse.swt.widgets.Widget.release(Widget.java:816)
at org.eclipse.swt.widgets.Widget.dispose(Widget.java:454)
at org.eclipse.swt.ole.win32.OleClientSite.<init>(OleClientSite.java:194)
at org.eclipse.swt.ole.win32.OleControlSite.<init>(OleControlSite.java:96)
at org.eclipse.swt.snippets.EmbeddingTest.main(EmbeddingTest.java:24)

Any specific configuration needed to run this snippet, also which MS Office version are you using ?
Re: Print Preview does not work in SWT OLE Excel [message #1232571 is a reply to message #1232195] Fri, 17 January 2014 08:31 Go to previous messageGo to next message
Vu Duy Gian is currently offline Vu Duy GianFriend
Messages: 2
Registered: January 2014
Junior Member
Hi Niraj Modi,
First of all, thank you for considering my problem.
My snippet needn't have any specific configuration to run (Of course, it need to have a excel file with Book1.xlsx name on the C drive)
I'm using MS Office Excel 2007.

--------------
Best Regards
Re: Print Preview does not work in SWT OLE Excel [message #1240450 is a reply to message #1232571] Thu, 06 February 2014 13:46 Go to previous message
Niraj Modi is currently offline Niraj ModiFriend
Messages: 48
Registered: November 2013
Member
Reported the bug on Eclipse Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=427562

Thanks,
Niraj
Previous Topic:Custom Key Events
Next Topic:Ctrl-X/C/V not working in text fields
Goto Forum:
  


Current Time: Tue Mar 19 06:41:34 GMT 2024

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

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

Back to the top