设置点为总数的方法。
Contents
[
Hide
]
Excel图表中的"设为总和"是什么意思
在一些Excel图表中,例如瀑布图,某些点的数据是前面所有点的总和,你可能需要"设为总和"。我们会展示示例代码和说明。
瀑布图需要将点设为"总和"
此图显示了Excel中的瀑布图。我们可以看到有四个以"总和"开头的数据点,它们用于计算之前所有数据点的总和。 在此图中,设置并不完全正确,当我们选择"2024年总和"点时,可以看到Excel中"设为总和"选项没有被勾选。 下方附有需要修改的 示例Excel文件,我们将使用Aspose.Cells来正确设置它。
使用Aspose.Cells将点设为"总和"
我们使用以下代码来正确设置文件:
This file contains hidden or 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
string filePath = ""; | |
Workbook wb = new Workbook(filePath + "SampleSheet.xlsx"); | |
Worksheet worksheet = wb.Worksheets[0]; | |
Chart chart = worksheet.Charts["Graphiq5"]; | |
//set some points as total column | |
//In this example, we set points 0, 4, 8, 12 as total | |
chart.NSeries[0].LayoutProperties.Subtotals = new int[] { 0, 4, 8, 12 }; | |
wb.Save(filePath + "output.xlsx"); |
你可以得到以下正确的输出文件
如下图所示,四个"总和"数据点已正确设置,你可以看到与之前图表的区别。