禁用图表的数据标签文本换行

Contents
[ ]

Aspose.Cells提供了DataLabels.setTextWrapped()方法。设置为TrueFalse分别启用或禁用数据标签上的文本换行。

同样,使用DataLabels.isTextWrapped()方法来查看数据标签是否已经换行。

此屏幕截图显示了一个包含图表的示例Microsoft Excel文件,其中数据标签的文本已经换行。您可以看到,在Microsoft Excel 2013的Format Datalabels面板的ALIGNMENT部分中,您可以选中或清除Wrap text in shape选项。

数据标签换行

todo:image_alt_text

以下代码加载示例Microsoft Excel文件,并使用DataLabels.setTextWrapped()方法禁用数据标签文本换行。当代码执行时,图表看起来像这样。先前换行的文本现在已经取消换行。

仅显示单行数据标签

todo:image_alt_text

// 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(DisableTextWrapping.class);
// Load the sample Excel file inside the workbook object
Workbook workbook = new Workbook(dataDir + "SampleChart.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Access the first chart inside the worksheet
Chart chart = worksheet.getCharts().get(0);
// Disable the Text Wrapping of Data Labels in all Series
chart.getNSeries().get(0).getDataLabels().setTextWrapped(false);
chart.getNSeries().get(1).getDataLabels().setTextWrapped(false);
chart.getNSeries().get(2).getDataLabels().setTextWrapped(false);
// Save the workbook
workbook.save(dataDir + "Output.xlsx");