禁用图表数据标签的文本换行
Contents
[
Hide
]
Microsoft Excel 2013 允许用户在图表的数据标签内环绕或展开文本。默认情况下,数据标签文本是换行的。
Aspose.Cells 提供了DataLabels.setTextWrapped()方法。调成真的要么错误的分别启用或禁用数据标签上的文本换行。
同样,使用DataLabels.isTextWrapped()查明数据标签是否已包装的方法。
此屏幕截图显示了一个示例 Microsoft Excel 文件,其中包含一个图表,其中包含数据标签的文本。如您所见,您可以检查或清除将文字环绕成形状Microsoft Excel 2013 中格式数据标签面板的对齐部分中的选项。
包装数据标签
下面的示例代码使用 Aspose.Cells 加载示例 Microsoft Excel 文件并使用禁用数据标签文本换行DataLabels.setTextWrapped()方法。执行代码时,图表如下所示。先前换行的文本现在已展开。
仅在一行中显示数据标签
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |