Crea, manipola o rimuovi scenari dai fogli di lavoro

Contents
[ ]

Aspose.Cells fornisce alcune lezioni utili, ad esempioScenarioCollection, Scenario, ScenarioInputCellCollection eScenarioInputCell . Fornisce inoltre ilFoglio di lavoro.Scenariproprietà. Il codice di esempio seguente apre un file Excel XLSX (che contiene alcuni scenari) e rimuove uno scenario esistente dal foglio di lavoro. Aggiunge anche un nuovo scenario prima di salvare il file Excel. Utilizza un file modello molto semplice che contiene uno scenario.

Dopo aver eseguito il codice, uno scenario esistente viene rimosso e un nuovo scenario viene aggiunto al foglio di lavoro.

Il file di output

cose da fare:immagine_alt_testo

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateScenariosfromWorksheets.class);
// Instantiate the Workbook
// Load an Excel file
Workbook workbook = new Workbook(dataDir + "Bk_scenarios.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Remove the existing first scenario from the sheet
worksheet.getScenarios().removeAt(0);
// Create a scenario
int i = worksheet.getScenarios().add("MyScenario");
// Get the scenario
Scenario scenario = worksheet.getScenarios().get(i);
// Add comment to it
scenario.setComment("Test sceanrio is created.");
// Get the input cells for the scenario
ScenarioInputCellCollection sic = scenario.getInputCells();
// Add the scenario on B4 (as changing cell) with default value
sic.add(3, 1, "1100000");
// Save the Excel file.
workbook.save(dataDir + "outBk_scenarios1.xlsx");