Leggi e manipola i grafici di Excel 2016

Possibili scenari di utilizzo

Aspose.Cells supporta la lettura e la manipolazione dei grafici Microsoft Excel 2016 che non sono presenti in Microsoft Excel 2013 o versioni precedenti.

Leggi e manipola i grafici di Excel 2016

Il codice di esempio seguente carica il filefile excel di origine che contiene Microsoft grafici Excel 2016 nel primo foglio di lavoro. Legge tutti i grafici uno per uno e cambia il titolo in base al tipo di grafico. Lo screenshot seguente mostra il file excel di origine prima dell’esecuzione del codice. Come puoi vedere, il titolo del grafico è lo stesso per tutti i grafici.

cose da fare:immagine_alt_testo

Lo screenshot seguente mostra ilfile excel di output dopo l’esecuzione del codice. Come puoi vedere, il titolo del grafico viene modificato in base al tipo di grafico.

cose da fare:immagine_alt_testo

Codice d’esempio

// 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.getSharedDataDir(ReadManipulateExcel2016Charts.class) + "charts/";
// Load source excel file containing excel 2016 charts
Workbook wb = new Workbook(dataDir + "excel2016Charts.xlsx");
// Access the first worksheet which contains the charts
Worksheet ws = wb.getWorksheets().get(0);
//Converting integer enums to string enums
HashMap<Integer, String> cTypes = new HashMap<Integer, String>();
cTypes.put(ChartType.BOX_WHISKER, "BoxWhisker");
cTypes.put(ChartType.WATERFALL, "Waterfall");
cTypes.put(ChartType.TREEMAP, "Treemap");
cTypes.put(ChartType.HISTOGRAM, "Histogram");
cTypes.put(ChartType.SUNBURST, "Sunburst");
// Access all charts one by one and read their types
for (int i = 0; i < ws.getCharts().getCount(); i++) {
// Access the chart
Chart ch = ws.getCharts().get(i);
// Print chart type
String strChartType = cTypes.get(ch.getType());
System.out.println(strChartType);
// Change the title of the charts as per their types
ch.getTitle().setText("Chart Type is " + strChartType);
}
// Save the workbook
wb.save(dataDir + "out_excel2016Charts.xlsx");
// Print message
System.out.println("Excel 2016 Chart Titles changed successfully.");

Uscita console

Ecco l’output della console del codice di esempio precedente quando eseguito con il file fornitofile excel di origine.

 Waterfall

Treemap

Sunburst

Histogram

BoxWhisker

Argomenti avanzati