[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Load Excel workbook without any options (commands)
|
- From: sajid622@xxxxxxxxxxx (Sajid)
- Date: Thu, 10 Apr 2008 14:24:33 +0000 (UTC)
- Newsgroups: eclipse.platform.swt
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
Hi,
As a newbie I tried different code snippets and examples available on
http://www.eclipse.org/swt/ but couldn't achieve the required results.
Every time I try to run an example that uses oleClientControl to load an
excel file, the file loads into Excel in a separate window and my Shell
window remains blank (no sheets on it).
Earlier on I was trying to open the file with oleClientSite and hide
different toolbars and menus but then I realized that options are endless
and users can do different things by either using context menus (for
example add new sheets) or use keyboard shortcuts (for example Ctrl+B). I
don't want to give any such control to the user. User should only be able
to enter text and do not apply formating, add sheets or do other things.
At the moment I'm using the following code to load an excel file and hide
toolbars etc. Can anybody help me achieve my requirements?
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();
}
}