XSpreadsheets xSpreadsheets = (XSpreadsheets) xSheetDoc.getSheets();
log.println("getting a sheet");
XSpreadsheet oSheet = null;
XIndexAccess oIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
XIndexAccess.class, xSpreadsheets);
try {
oSheet = (XSpreadsheet) AnyConverter.toObject(
new Type(XSpreadsheet.class),
oIndexAccess.getByIndex(0));
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get a spreadsheet", e);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get a spreadsheet", e);
} catch (com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get a spreadsheet", e);
}
log.println("filling some cells");
try {
oSheet.getCellByPosition(5, 5).setValue(15);
oSheet.getCellByPosition(1, 4).setValue(10);
oSheet.getCellByPosition(2, 0).setValue(-5.15);
oSheet.getCellByPosition(8, 8).setFormula("= B5 + C1");
// fill cells for XSheetOtline::autoutline
oSheet.getCellByPosition(6, 6).setValue(3);
oSheet.getCellByPosition(7, 6).setValue(3);
oSheet.getCellByPosition(8, 6).setFormula("= SUM(G7:H7)");
oSheet.getCellByPosition(9, 6).setFormula("= G7*I7");
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace(log);
throw new StatusException("Exception occurred while filling cells", e);
}
oObj = (XInterface) UnoRuntime.queryInterface(XInterface.class, oSheet);
log.println("creating a new environment for object");
TestEnvironment tEnv = new TestEnvironment(oObj);
// do not execute com::sun::star::sheets::XCellSeries::fillAuto()
tEnv.addObjRelation("XCELLSERIES_FILLAUTO", new Boolean(false));
// set the adress ranges of the cells (see values set above): for e.g. XSheetOutline test
tEnv.addObjRelation("CellRangeAddress",
new CellRangeAddress((short)0, 6, 6, 8, 8));
tEnv.addObjRelation("CellRangeSubAddress",
new CellRangeAddress((short)0, 6, 6, 7, 8));
// pick a cell with a formula for XSheetAuditing, a dependent cell and a precedent cell
tEnv.addObjRelation("XSheetAuditing.CellAddress", new CellAddress((short)0, 8, 6));
tEnv.addObjRelation("XSheetAuditing.PrecedentCellAddress", new CellAddress((short)0, 7, 6));
tEnv.addObjRelation("XSheetAuditing.DependentCellAddress", new CellAddress((short)0, 9, 6));
// add an existing sheet for linking
tEnv.addObjRelation("XSheetLinkable.LinkSheet", "ScSheetLinksObj.sdc");
//adding Scenario and with that a ScenarioSheet-Relation for Scenario and XScenarioEnhanced
XScenariosSupplier scene = (XScenariosSupplier) UnoRuntime.queryInterface(
XScenariosSupplier.class,
tEnv.getTestObject());
scene.getScenarios()
.addNewByName("Scenario",
new CellRangeAddress[] {
new CellRangeAddress((short) 0, 0, 0, 10, 10)
}, "Comment");
XSpreadsheet sSheet = null;
try {
sSheet = (XSpreadsheet) UnoRuntime.queryInterface(
XSpreadsheet.class,
xSpreadsheets.getByName("Scenario"));