Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Excel ActiveX DisplayAlerts property
Excel ActiveX DisplayAlerts property [message #521824] |
Thu, 18 March 2010 19:37 |
Paul Watson Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Hi all,
I would like to set the DisplayAlerts property on an Excel ActiveX
object embedded in an application I have. However, when I try to set the
property it remains unchanged. I am using Windows XP with Excel 2003.
Here is a snippet that illustrates the problem.
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DisplayAlertsSnippet {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
OleControlSite controlSite;
try {
OleFrame frame = new OleFrame(shell, SWT.NONE);
controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Sheet");
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
} catch (SWTError e) {
System.out.println("Unable to open activeX control");
display.dispose();
return;
}
shell.open();
OleAutomation excelSheet = new OleAutomation(controlSite);
int[] dispIDs = excelSheet.getIDsOfNames(new String[] { "Application" });
Variant pVarResult = excelSheet.getProperty(dispIDs[0]);
OleAutomation application = pVarResult.getAutomation();
displayAlerts(application, false);
pVarResult.dispose();
excelSheet.dispose();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
application.dispose();
display.dispose();
}
private static void displayAlerts(OleAutomation application, boolean
display) {
int[] dispIds = application.getIDsOfNames(new String[]{"DisplayAlerts"});
System.out.println("DisplayAlerts dispId " + dispIds[0]);
Variant result = application.getProperty(dispIds[0]);
System.out.println("DisplayAlerts before setting property = " + result);
result.dispose();
Variant variant = new Variant(display);
application.setProperty(dispIds[0], variant);
variant.dispose();
result = application.getProperty(dispIds[0]);
System.out.println("DisplayAlerts after setting property = " + result);
result.dispose();
}
}
The output from the snippet is as follows.
DisplayAlerts dispId 343
DisplayAlerts before setting property = VT_BOOL{true}
DisplayAlerts after setting property = VT_BOOL{true}
Is there anyone out there that has successfully managed to do this?
Cheers,
Paul
|
|
|
Re: Excel ActiveX DisplayAlerts property [message #522457 is a reply to message #521824] |
Mon, 22 March 2010 16:36 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi Paul,
I see the same behaviour, but unfortunately don't know why this is
happening. However a google search of "excel cannot set DisplayAlerts"
finds several other posts with a similar problem in non-swt contexts, so I
don't think it's an swt problem. Hopefully one of them has a follow-up that
can help with your case.
Grant
"Paul Watson" <pablowatson@gmail.com> wrote in message
news:hntvcu$pu8$1@build.eclipse.org...
> Hi all,
>
> I would like to set the DisplayAlerts property on an Excel ActiveX
> object embedded in an application I have. However, when I try to set the
> property it remains unchanged. I am using Windows XP with Excel 2003.
> Here is a snippet that illustrates the problem.
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.SWTError;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.ole.win32.OLE;
> import org.eclipse.swt.ole.win32.OleAutomation;
> import org.eclipse.swt.ole.win32.OleControlSite;
> import org.eclipse.swt.ole.win32.OleFrame;
> import org.eclipse.swt.ole.win32.Variant;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> public class DisplayAlertsSnippet {
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> OleControlSite controlSite;
> try {
> OleFrame frame = new OleFrame(shell, SWT.NONE);
> controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Sheet");
> controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
> } catch (SWTError e) {
> System.out.println("Unable to open activeX control");
> display.dispose();
> return;
> }
> shell.open();
>
> OleAutomation excelSheet = new OleAutomation(controlSite);
> int[] dispIDs = excelSheet.getIDsOfNames(new String[] { "Application" });
> Variant pVarResult = excelSheet.getProperty(dispIDs[0]);
> OleAutomation application = pVarResult.getAutomation();
>
> displayAlerts(application, false);
>
> pVarResult.dispose();
> excelSheet.dispose();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> application.dispose();
> display.dispose();
> }
>
> private static void displayAlerts(OleAutomation application, boolean
> display) {
> int[] dispIds = application.getIDsOfNames(new String[]{"DisplayAlerts"});
> System.out.println("DisplayAlerts dispId " + dispIds[0]);
>
> Variant result = application.getProperty(dispIds[0]);
> System.out.println("DisplayAlerts before setting property = " + result);
> result.dispose();
>
> Variant variant = new Variant(display);
> application.setProperty(dispIds[0], variant);
> variant.dispose();
>
> result = application.getProperty(dispIds[0]);
> System.out.println("DisplayAlerts after setting property = " + result);
> result.dispose();
> }
>
> }
>
> The output from the snippet is as follows.
>
> DisplayAlerts dispId 343
> DisplayAlerts before setting property = VT_BOOL{true}
> DisplayAlerts after setting property = VT_BOOL{true}
>
> Is there anyone out there that has successfully managed to do this?
>
> Cheers,
>
>
> Paul
>
>
|
|
|
Re: Excel ActiveX DisplayAlerts property [message #522468 is a reply to message #522457] |
Mon, 22 March 2010 17:44 |
Paul Watson Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Hi Grant,
Thanks for the suggestion. I think I found out what the problem is. This
is one of the application properties you cannot set until you have made
the application 'visible'. The follow snippet will let you set the
display alerts property, but at the rather ugly cost of flashing the
Excel application window.
public class DisplayAlertsSnippet {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
OleControlSite controlSite;
try {
OleFrame frame = new OleFrame(shell, SWT.NONE);
controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Sheet");
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
} catch (SWTError e) {
System.out.println("Unable to open activeX control");
display.dispose();
return;
}
shell.open();
OleAutomation excelSheet = new OleAutomation(controlSite);
int[] dispIDs = excelSheet.getIDsOfNames(new String[] { "Application" });
Variant pVarResult = excelSheet.getProperty(dispIDs[0]);
OleAutomation application = pVarResult.getAutomation();
setVisible(application, true);
displayAlerts(application, false);
setVisible(application, false);
pVarResult.dispose();
excelSheet.dispose();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
application.dispose();
display.dispose();
}
private static void setVisible(OleAutomation application, boolean
visible) {
int[] dispIds = application.getIDsOfNames(new String[]{"Visible"});
System.out.println("Visible dispId " + dispIds[0]);
application.setProperty(dispIds[0], new Variant(visible));
}
private static void displayAlerts(OleAutomation application, boolean
display) {
int[] dispIds = application.getIDsOfNames(new String[]{"DisplayAlerts"});
System.out.println("DisplayAlerts dispId " + dispIds[0]);
Variant result = application.getProperty(dispIds[0]);
System.out.println("DisplayAlerts before setting property = " + result);
result.dispose();
Variant variant = new Variant(display);
application.setProperty(dispIds[0], variant);
variant.dispose();
result = application.getProperty(dispIds[0]);
System.out.println("DisplayAlerts after setting property = " + result);
result.dispose();
// Set it back to true, otherwise the Excel process that never dies
will have the property set to false.
application.setProperty(dispIds[0], new Variant(true));
}
}
On 3/22/2010 9:36 AM, Grant Gayed wrote:
> Hi Paul,
>
> I see the same behaviour, but unfortunately don't know why this is
> happening. However a google search of "excel cannot set DisplayAlerts"
> finds several other posts with a similar problem in non-swt contexts, so I
> don't think it's an swt problem. Hopefully one of them has a follow-up that
> can help with your case.
>
> Grant
>
>
> "Paul Watson"<pablowatson@gmail.com> wrote in message
> news:hntvcu$pu8$1@build.eclipse.org...
>> Hi all,
>>
>> I would like to set the DisplayAlerts property on an Excel ActiveX
>> object embedded in an application I have. However, when I try to set the
>> property it remains unchanged. I am using Windows XP with Excel 2003.
>> Here is a snippet that illustrates the problem.
>>
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.SWTError;
>> import org.eclipse.swt.layout.FillLayout;
>> import org.eclipse.swt.ole.win32.OLE;
>> import org.eclipse.swt.ole.win32.OleAutomation;
>> import org.eclipse.swt.ole.win32.OleControlSite;
>> import org.eclipse.swt.ole.win32.OleFrame;
>> import org.eclipse.swt.ole.win32.Variant;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>>
>> public class DisplayAlertsSnippet {
>>
>> public static void main(String[] args) {
>> Display display = new Display();
>> Shell shell = new Shell(display);
>> shell.setLayout(new FillLayout());
>> OleControlSite controlSite;
>> try {
>> OleFrame frame = new OleFrame(shell, SWT.NONE);
>> controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Sheet");
>> controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
>> } catch (SWTError e) {
>> System.out.println("Unable to open activeX control");
>> display.dispose();
>> return;
>> }
>> shell.open();
>>
>> OleAutomation excelSheet = new OleAutomation(controlSite);
>> int[] dispIDs = excelSheet.getIDsOfNames(new String[] { "Application" });
>> Variant pVarResult = excelSheet.getProperty(dispIDs[0]);
>> OleAutomation application = pVarResult.getAutomation();
>>
>> displayAlerts(application, false);
>>
>> pVarResult.dispose();
>> excelSheet.dispose();
>>
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> application.dispose();
>> display.dispose();
>> }
>>
>> private static void displayAlerts(OleAutomation application, boolean
>> display) {
>> int[] dispIds = application.getIDsOfNames(new String[]{"DisplayAlerts"});
>> System.out.println("DisplayAlerts dispId " + dispIds[0]);
>>
>> Variant result = application.getProperty(dispIds[0]);
>> System.out.println("DisplayAlerts before setting property = " + result);
>> result.dispose();
>>
>> Variant variant = new Variant(display);
>> application.setProperty(dispIds[0], variant);
>> variant.dispose();
>>
>> result = application.getProperty(dispIds[0]);
>> System.out.println("DisplayAlerts after setting property = " + result);
>> result.dispose();
>> }
>>
>> }
>>
>> The output from the snippet is as follows.
>>
>> DisplayAlerts dispId 343
>> DisplayAlerts before setting property = VT_BOOL{true}
>> DisplayAlerts after setting property = VT_BOOL{true}
>>
>> Is there anyone out there that has successfully managed to do this?
>>
>> Cheers,
>>
>>
>> Paul
>>
>>
>
>
|
|
|
Goto Forum:
Current Time: Sun Dec 08 18:19:32 GMT 2024
Powered by FUDForum. Page generated in 0.23292 seconds
|