Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Excel file in Swt, get the selected cell position in terms of row and column number

Hi
 
I have a SWT application wherein an Excel is embedded as an OLE object. I need to know the position of the selected cell in terms of row and column.
Below is the code :
public
class CreateExcelOLE {
static int SheetSelectionChange = 0x00000616;
static int SheetChange = 0x0000061c;
static String IID_AppEvents = "{00024413-0000-0000-C000-000000000046}";
public static void main(String[] args) {
Display display =
new Display();
Shell shell =
new Shell(display);
shell.setText(
"Excel Example");
shell.setLayout(
new FillLayout());
Button button =
new Button(shell,SWT.NONE);
button.setText(
"Submit");
try {
OleFrame frame =
new OleFrame(shell, SWT.NONE);
File file =
new File("C:\RateSheet.xls");
OleClientSite clientSite =
new OleClientSite(frame, SWT.NONE, file);
OleControlSite controlSite =
new OleControlSite(frame, SWT.NONE,"Excel.Sheet");
OleAutomation excelSheet =
new OleAutomation(clientSite);
int[] dispIDs = excelSheet
.getIDsOfNames(
new String[] { "Application" });
Variant pVarResult = excelSheet.getProperty(dispIDs[0]);
Variant[] openArgs =
new Variant[] { pVarResult };
OleAutomation application = pVarResult.getAutomation();
pVarResult.dispose();
excelSheet.dispose();
OleListener listener =
new OleListener() {
public void handleEvent(OleEvent e) {
System.out.println("sheet selection has changed");
Variant[] args = e.
arguments;
for (int i = 0; i < args.length; i++) {
System.
out.println(args[i]);
args[i].dispose();
}
}
};
int eventID = SheetSelectionChange;
controlSite.addEventListener(application,
IID_AppEvents, eventID,
listener);
 
}
catch (SWTError e) {
System.
out.println("Unable to open activeX control");
return;
}
shell.setSize(800, 600);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
 
 
Any pointers?

Back to the top