I am trying to run a simple test, bellow is a source code. While this program is updating the excel sheet which is visible to the user and if user clicks on any cell, I get this following exception. I need to be able to update data to the excel plus user should be able to modify any data. Is there a way to do this?
public class ExcelWithEventTest {
public static void main(String[] args) throws ExcelException
{
Application application = new Application();
application.setVisible(true);
GenericWorkbook workbook = application.createWorkbook(null);
Worksheet worksheet = workbook.getWorksheet(1);
worksheet.setEventHandler(new WorksheetEventHandler() {
public boolean beforeDoubleClick(WorksheetEventObject event) {
int col = event.getCell().getColumn();
int row = event.getCell().getRow();
System.out.println("Row: " + row + " Col: " + col);
return false;
}
public boolean beforeRightClick(WorksheetEventObject event) {
int col = event.getCell().getColumn();
int row = event.getCell().getRow();
System.out.println("Row: " + row + " Col: " + col);
return false;
}
});
Cell cell;
cell = worksheet.getCell("A2");
String instrument = cell.getString();
System.out.println("Instrument: " + instrument);
for (int i=0; i< 200000; i++) {
worksheet.getCell(1, 2).setValue(i);
worksheet.getCell(1, 3).setValue(i+1);
}
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
application.close();
}
}
===============
StackTrade
===============
Exception in thread "main" com.jniwrapper.win32.automation.AutomationException: COM object method returns error code: 0x80020009; DISP_E_EXCEPTION (Exception occurred.)
at com.jniwrapper.win32.com.impl.IUnknownImpl.invokeStandardVirtualMethod(SourceFile:654)
at com.jniwrapper.win32.automation.impl.IDispatchImpl.invoke(SourceFile:112)
at com.jniwrapper.win32.automation.Automation$InvocationHelper.a(SourceFile:688)
at com.jniwrapper.win32.automation.Automation$InvocationHelper.a(SourceFile:672)
at com.jniwrapper.win32.automation.Automation$InvocationHelper.c(SourceFile:660)
at com.jniwrapper.win32.automation.Automation$InvocationHelper.setProperty(SourceFile:642)
at com.jniwrapper.win32.automation.Automation.setProperty(SourceFile:369)
at com.jniwrapper.win32.automation.Automation.setProperty(SourceFile:395)
at com.jniwrapper.win32.automation.Automation.setDispatchProperty(SourceFile:447)
at com.jniwrapper.win32.excel.impl.RangeImpl.setValue2(SourceFile:1979)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.jniwrapper.win32.automation.m.run(SourceFile:233)
at com.jniwrapper.win32.MessageLoopThread$ThreadSynchronizedAction.run(MessageLoopThread.java:544)
at com.jniwrapper.win32.MessageLoopThread$LoopThread.run(MessageLoopThread.java:493)
Thanks,
Suresh