调整图表的数据标签形状以适合文本

调整图表的数据标签形状以适应 Microsoft Excel 中的文本

通过选择图表上的任何数据标签,可以在 Excel 界面上访问此选项。右键单击并选择格式化数据标签菜单。在尺寸和特性选项卡,展开结盟揭示相关属性,包括调整形状大小以固定文本选项。

调整图表的数据标签形状以适合文本

为了模仿 Excel 调整数据标签形状大小以适应文本的功能,Aspose.Cells API 公开了布尔类型DataLabels.IsResizeShapeToFitText财产。下面一段代码展示了简单的使用场景DataLabels.IsResizeShapeToFitText财产。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create an instance of Workbook containing the Chart
var book = new Workbook(dataDir + "source.xlsx");
// Access the Worksheet that contains the Chart
var sheet = book.Worksheets[0];
foreach (Chart chart in sheet.Charts)
{
for (int index = 0; index < chart.NSeries.Count; index++)
{
// Access the DataLabels of indexed NSeries
var labels = chart.NSeries[index].DataLabels;
// Set ResizeShapeToFitText property to true
labels.IsResizeShapeToFitText = true;
}
// Calculate Chart
chart.Calculate();
}
// Save the result
book.Save(dataDir + "output_out.xlsx");