Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » OLE Automation Excel - SaveAs workbook
icon5.gif  OLE Automation Excel - SaveAs workbook [message #527546] Thu, 15 April 2010 14:51 Go to next message
Mo is currently offline MoFriend
Messages: 12
Registered: March 2010
Junior Member
Hi, I have an Excel object embedded in Eclipse. Now I want to save the whole thing as a Workbook. How can I do that?

I have started following:
(It's also a workbook exported, but only one work sheet, not all the sheets in the workbook)


	private void saveFileAs(String path) {

		int[] saveId = workbook.getIDsOfNames(new String[] { "SaveAs",
				"FileName", "FileFormat" });


		int[] rgdispidNamedArgs = new int[] { saveId[1], saveId[2] };

		// Arguments
		Variant[] rgvarg = new Variant[2];
		rgvarg[0] = new Variant(path); // FileName
		rgvarg[1] = new Variant(3); // FileFormat (XLS)

		// Calling Method
		Variant pVarResult = workbook.invoke(saveId[0], rgvarg,
				rgdispidNamedArgs);
		};



please help me Sad


Greetings, Marc

[Updated on: Thu, 15 April 2010 14:51]

Report message to a moderator

Re: OLE Automation Excel - SaveAs workbook [message #530135 is a reply to message #527546] Wed, 28 April 2010 15:33 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi, sorry for the late reply,

The following snippet works for me on Windows 2000 with Excel 2002. Does it
work for you?

public class ModifiedSnippet261 {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Excel Example");
shell.setLayout(new FillLayout());
OleAutomation auto;
try {
OleFrame frame = new OleFrame(shell, SWT.NONE);
OleClientSite site = new OleClientSite(frame, SWT.NONE,
"Excel.Sheet");
auto = new OleAutomation(site);
addFileMenu(frame, auto);
} catch (SWTError e) {
System.out.println("Unable to open activeX control");
display.dispose();
return;
}
shell.setSize(800, 600);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
auto.dispose();
display.dispose();
}

static void addFileMenu(OleFrame frame, final OleAutomation auto) {
final Shell shell = frame.getShell();
Menu menuBar = new Menu(shell, SWT.BAR);
shell.setMenuBar(menuBar);
MenuItem fileMenuItem = new MenuItem(menuBar, SWT.CASCADE);
fileMenuItem.setText("&File");
Menu fileMenu = new Menu(fileMenuItem);
fileMenuItem.setMenu(fileMenu);
MenuItem saveAsMenuItem = new MenuItem(fileMenu, SWT.NONE);
saveAsMenuItem.setText("Save As...");
saveAsMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int[] saveId = auto.getIDsOfNames(new String[] { "SaveAs",
"FileName"});
Variant[] args = new Variant[1];
args[0] = new Variant("c:\\asdf.xls");
Variant result = auto.invoke(saveId[0], args);
System.out.println("result: " + result);
args[0].dispose();
result.dispose();
}
});
MenuItem exitMenuItem = new MenuItem(fileMenu, SWT.NONE);
exitMenuItem.setText("Exit");
exitMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.dispose();
}
});
frame.setFileMenus(new MenuItem[] { fileMenuItem });
}
}

Grant


"Mo" <mo84@gmx.de> wrote in message news:hq7957$3lf$1@build.eclipse.org...
> Hi, I have an Excel object embedded in Eclipse. Now I want to save the
whole thing as a Workbook. How can I do that?
>
> I have started following:
> (It's also a workbook exported, but only one work sheet, not all the
sheets in the workbook)
>
>
> private void saveFileAs(String path) {
>
> int[] saveId = workbook.getIDsOfNames(new String[] { "SaveAs",
> "FileName", "FileFormat" });
>
>
> int[] rgdispidNamedArgs = new int[] { saveId[1], saveId[2] };
>
> // Arguments
> Variant[] rgvarg = new Variant[2];
> rgvarg[0] = new Variant(path); // FileName
> rgvarg[1] = new Variant(3); // FileFormat (XLS)
>
> // Calling Method
> Variant pVarResult = workbook.invoke(saveId[0], rgvarg,
> rgdispidNamedArgs);
> workbook.dispose();
>
>
> please help me :(
>
>
> Greetings, Marc
Previous Topic:Initial state/scrolling when Drawing on SWT Components
Next Topic:Default focus on combo and scrolling
Goto Forum:
  


Current Time: Tue Mar 19 10:38:12 GMT 2024

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

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

Back to the top