Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36127.28 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hide Subtotal in PivotTable", "Hide Subtotal in PivotTable\Hide Subtotal in PivotTable.csproj", "{B1CF192D-B631-45B2-A76F-F3F3A990E59D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1CF192D-B631-45B2-A76F-F3F3A990E59D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DAFDC45D-8596-4B8B-BD92-FBACA51AB34C}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Hide_Subtotal_in_PivotTable</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Syncfusion.XlsIO;

namespace Hide_Subtotal_in_PivotTable
{
class Program
{
public static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);

IWorksheet worksheet = workbook.Worksheets[0];

IWorksheet pivotSheet = workbook.Worksheets[1];

//Create Pivot cache with the given data range
IPivotCache cache = workbook.PivotCaches.Add(worksheet["A1:C9"]);

//Create PivotTable with the cache at the specified location
IPivotTable pivotTable = pivotSheet.PivotTables.Add("PivotTable1", pivotSheet["A1"], cache);

//Add Pivot table field
IPivotField regionField = pivotTable.Fields["Region"];
regionField.Axis = PivotAxisTypes.Row;

//Hide subtotals
regionField.Subtotals = PivotSubtotalTypes.None;

//Add Pivot table field
IPivotField categoryField = pivotTable.Fields["Category"];
categoryField.Axis = PivotAxisTypes.Row;

//Hide subtotals
categoryField.Subtotals = PivotSubtotalTypes.None;

//Add data field
IPivotField dataField = pivotTable.Fields["Sales"];
pivotTable.DataFields.Add(dataField, "Total Sales", PivotSubtotalTypes.Sum);

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
#endregion

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
}
}
}
}