Showing Cell Range as the Data Labels
Show cell range as data labels in MS Excel
In Microsoft Excel 2013, you can display Cell Range for Data Labels. You can select this option by following these steps
- Select Data Labels of the Series and right click to open the pop up menu.
- Click the Format Data Labels… and it will show Label Options.
- Check or uncheck the check box Label Contains - Value From Cells.
Check-box to show Cell Range as Data Labels
The following screenshot highlights this option for your reference.
Show cell range as data labels with Aspose.Cells
Aspose.Cells provides the DataLabels.setShowCellRange() method to check or uncheck the checkbox Label Contains - Value From Cells as shown in the screenshot above.
Java code to show cell range as data labels
The sample code below accesses the Data Labels of the Chart Series and then set DataLabels.setShowCellRange() method to true to check Label Contains - Value From Cells option.
// 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(ShowCellRangeAsTheDataLabels.class); | |
// Create workbook from the source Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the chart inside the worksheet | |
Chart chart = worksheet.getCharts().get(0); | |
// Check the "Label Contains - Value From Cells" | |
DataLabels dataLabels = chart.getNSeries().get(0).getDataLabels(); | |
dataLabels.setShowCellRange(true); | |
// Save the workbook | |
workbook.save(dataDir + "output.xlsx"); |