Lire et Manipuler les Graphiques Excel 2016
Scénarios d’utilisation possibles
Aspose.Cells prend en charge la lecture et la manipulation des graphiques Microsoft Excel 2016 qui ne sont pas présents dans Microsoft Excel 2013 ou les versions antérieures.
Lire et manipuler les graphiques Excel 2016
Le code d’exemple suivant charge le fichier excel source qui contient des graphiques Microsoft Excel 2016 dans la première feuille de calcul. Il lit tous les graphiques un par un et modifie son titre selon son type de graphique. La capture d’écran suivante montre le fichier excel source avant l’exécution du code. Comme vous pouvez le voir, le titre du graphique est le même pour tous les graphiques.
La capture d’écran suivante montre le fichier excel de sortie après l’exécution du code. Comme vous pouvez le voir, le titre du graphique est modifié selon son type de graphique.
Code d’exemple
// 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."); |
Sortie console
Voici la sortie de la console du code d’exemple ci-dessus lorsqu’il est exécuté avec le fichier excel source fourni.
Waterfall
Treemap
Sunburst
Histogram
BoxWhisker