Skip to content

Commit 673ee66

Browse files
authored
Merge pull request #201 from SyncfusionExamples/264734-HideSubtotalPivotTable
264734-How to hide subtotal in pivot table?
2 parents 6b81076 + 0e60ae7 commit 673ee66

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36127.28 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hide Subtotal in PivotTable", "Hide Subtotal in PivotTable\Hide Subtotal in PivotTable.csproj", "{B1CF192D-B631-45B2-A76F-F3F3A990E59D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {DAFDC45D-8596-4B8B-BD92-FBACA51AB34C}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Hide_Subtotal_in_PivotTable</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\*">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>

Use Cases/Hide Subtotal in PivotTable/.NET/Hide Subtotal in PivotTable/Hide Subtotal in PivotTable/Output/.gitkeep

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Syncfusion.XlsIO;
2+
3+
namespace Hide_Subtotal_in_PivotTable
4+
{
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
using (ExcelEngine excelEngine = new ExcelEngine())
10+
{
11+
IApplication application = excelEngine.Excel;
12+
application.DefaultVersion = ExcelVersion.Xlsx;
13+
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
14+
IWorkbook workbook = application.Workbooks.Open(inputStream);
15+
16+
IWorksheet worksheet = workbook.Worksheets[0];
17+
18+
IWorksheet pivotSheet = workbook.Worksheets[1];
19+
20+
//Create Pivot cache with the given data range
21+
IPivotCache cache = workbook.PivotCaches.Add(worksheet["A1:C9"]);
22+
23+
//Create PivotTable with the cache at the specified location
24+
IPivotTable pivotTable = pivotSheet.PivotTables.Add("PivotTable1", pivotSheet["A1"], cache);
25+
26+
//Add Pivot table field
27+
IPivotField regionField = pivotTable.Fields["Region"];
28+
regionField.Axis = PivotAxisTypes.Row;
29+
30+
//Hide subtotals
31+
regionField.Subtotals = PivotSubtotalTypes.None;
32+
33+
//Add Pivot table field
34+
IPivotField categoryField = pivotTable.Fields["Category"];
35+
categoryField.Axis = PivotAxisTypes.Row;
36+
37+
//Hide subtotals
38+
categoryField.Subtotals = PivotSubtotalTypes.None;
39+
40+
//Add data field
41+
IPivotField dataField = pivotTable.Fields["Sales"];
42+
pivotTable.DataFields.Add(dataField, "Total Sales", PivotSubtotalTypes.Sum);
43+
44+
#region Save
45+
//Saving the workbook
46+
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
47+
workbook.SaveAs(outputStream);
48+
#endregion
49+
50+
//Dispose streams
51+
outputStream.Dispose();
52+
inputStream.Dispose();
53+
}
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)