/** Inserts a scenario containing one cell range into a sheet and * applies the value array. * @param xSheet The XSpreadsheet interface of the spreadsheet. * @param aRange The range address for the scenario. * @param aValueArray The array of cell contents. * @param aScenarioName The name of the new scenario. * @param aScenarioComment The user comment for the scenario. */ public void insertScenario( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange, uno.Any[][] aValueArray, String aScenarioName, String aScenarioComment) { // get the cell range with the given address unoidl.com.sun.star.table.XCellRange xCellRange = xSheet.getCellRangeByName(aRange); // create the range address sequence unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr = (unoidl.com.sun.star.sheet.XCellRangeAddressable)xCellRange; unoidl.com.sun.star.table.CellRangeAddress[] aRangesSeq = new unoidl.com.sun.star.table.CellRangeAddress[1]; aRangesSeq[0] = xAddr.getRangeAddress(); // create the scenario unoidl.com.sun.star.sheet.XScenariosSupplier xScenSupp = (unoidl.com.sun.star.sheet.XScenariosSupplier)xSheet; unoidl.com.sun.star.sheet.XScenarios xScenarios = xScenSupp.getScenarios(); xScenarios.addNewByName(aScenarioName, aRangesSeq, aScenarioComment); // insert the values into the range unoidl.com.sun.star.sheet.XCellRangeData xData = (unoidl.com.sun.star.sheet.XCellRangeData)xCellRange; xData.setDataArray(aValueArray); }
/** Activates a scenario. * @param xSheet The XSpreadsheet interface of the spreadsheet. * @param aScenarioName The name of the scenario. */ public void showScenario( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aScenarioName) { // get the scenario set unoidl.com.sun.star.sheet.XScenariosSupplier xScenSupp = (unoidl.com.sun.star.sheet.XScenariosSupplier)xSheet; unoidl.com.sun.star.sheet.XScenarios xScenarios = xScenSupp.getScenarios(); // get the scenario and activate it uno.Any aScenarioObj = xScenarios.getByName(aScenarioName); unoidl.com.sun.star.sheet.XScenario xScenario = (unoidl.com.sun.star.sheet.XScenario)aScenarioObj.Value; xScenario.apply(); }