SOF.createInstance(oComp, "com.sun.star.sheet.SheetCellRanges");
XSpreadsheets oSheets = xSheetDoc.getSheets() ;
XIndexAccess oIndSheets = (XIndexAccess)
UnoRuntime.queryInterface (XIndexAccess.class, oSheets);
XSpreadsheet oSheet = null;
try {
oSheet = (XSpreadsheet) AnyConverter.toObject(
new Type(XSpreadsheet.class), oIndSheets.getByIndex(0));
XNameContainer oRanges = (XNameContainer)
UnoRuntime.queryInterface(XNameContainer.class, oObj);
oRange = oSheet.getCellRangeByName("C1:D4");
oRanges.insertByName("Range1", oRange);
oRange = oSheet.getCellRangeByName("E2:F5");
oRanges.insertByName("Range2", oRange);
oRange = oSheet.getCellRangeByName("G2:H3");
oRanges.insertByName("Range3", oRange);
oRange = oSheet.getCellRangeByName("I7:J8");
oRanges.insertByName("Range4", oRange);
} catch(com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test object", e);
} catch(com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test object", e);
} catch(com.sun.star.container.ElementExistException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test object", e);
} catch(com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test object", e);
}
log.println("filling some cells");
try {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 5; j++) {
oSheet.getCellByPosition(i, j).setFormula("a");
}
}
for (int i = 0; i < 10; i++) {
for (int j = 5; j < 10; j++) {
oSheet.getCellByPosition(i, j).setValue(i + j);
}
}
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace(log);
throw new StatusException (
"Exception occurred while filling cells", e);
}
TestEnvironment tEnv = new TestEnvironment( oObj );
// NameReplaceIndex : _XNameReplace
log.println( "adding NameReplaceIndex as mod relation to environment" );
tEnv.addObjRelation("NameReplaceIndex", "0");
// INSTANCEn : _XNameContainer; _XNameReplace
log.println( "adding INSTANCEn as mod relation to environment" );
int THRCNT = 1;
if ((String)Param.get("THRCNT") != null) {
THRCNT= Integer.parseInt((String)Param.get("THRCNT"));
}
int a = 0;
int b = 0;
for (int n = 1; n < (THRCNT + 1) ; n++) {
a = n * 2;
b = a + 1;
oRange = oSheet.getCellRangeByName("A" + a + ":B" + b);
log.println(
"adding INSTANCE" + n + " as mod relation to environment" );
tEnv.addObjRelation("INSTANCE" + n, oRange);
}