用C++显示单元格范围作为数据标签
Contents
[
Hide
]
在Microsoft Excel 2013中,您可以显示用于数据标签的单元格范围。Aspose.Cells支持此功能。
复选框显示单元格范围作为数据标签
在Microsoft Excel中显示单元格范围作为数据标签:
- 选择系列数据标签,右键单击以打开上下文菜单。
- 选择格式数据标签。标签选项会显示。
- 选择或清除选项 标签包含 - 来自单元格的值。
下面的示例代码访问图表系列数据标签,并将 DataLabels.GetShowCellRange() 属性设置为 true 以选择 标签包含 - 来自单元格的值 选项。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Charts;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Path of input excel file
U16String inputFilePath = srcDir + u"source.xlsx";
// Path of output excel file
U16String outputFilePath = outDir + u"output_out.xlsx";
// Create workbook from the source Excel file
Workbook workbook(inputFilePath);
// 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(outputFilePath);
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}