Server-side pivot table processing with direct Excel export β Generate professional pivot table exports to Excel files without rendering UI components using ASP.NET Core and Syncfusion Pivot Engine.
This project demonstrates a production-ready implementation for exporting Pivot Table data directly to Excel format while maintaining a clean, component-free architecture. Perfect for business intelligence dashboards, financial reporting tools, and automated data export pipelines that don't require interactive UI pivot controls.
- β Headless Pivot Export: Export pivot data to Excel without rendering pivot table UI components
- β Server-Side Processing: Efficient pivot aggregation using Syncfusion Pivot Engine
- β Multiple Data Sources: Support for in-memory collections, CSV, and JSON data formats
- β Email Integration: Automated email delivery of Excel exports with attachments
- β Memory Caching: High-performance data caching for repeated pivot operations
- β RESTful API: Clean REST endpoints for pivot data retrieval and export
- β Background Services: Scheduled tasks with timed hosted services
- β CORS Enabled: Cross-origin resource sharing for flexible frontend integration
- Framework: ASP.NET Core 7.0+
- IDE: Visual Studio 2022 or Visual Studio Code
- Language: C# 11+
- Excel Engine: Syncfusion.XlsIO.Net.Core (v27.1.52+)
- Pivot Engine: Syncfusion.Pivot.Engine (v27.1.52+)
- Data Format: JSON, CSV, In-Memory Collections
- .NET SDK: 7.0 or higher
- Runtime: ASP.NET Core Runtime 7.0+
- Memory: 2GB minimum
- Platform: Windows, macOS, or Linux
git clone https://github.com/SyncfusionExamples/export-pivot-table-data-to-excel-without-displaying-the-pivot-table-component-in-the-UIOpen the PivotController.sln file in Visual Studio 2022:
File β Open β PivotController.sln
Right-click the Solution and select Restore NuGet Packages. Alternatively, use the Package Manager Console:
Update-PackageBuild the entire solution using:
Build β Build Solution (Ctrl+Shift+B)Edit the SendEMail method in PivotController.cs to add your SMTP credentials:
- Update
client.Hostwith your email provider's SMTP server - Replace
fromandrecipientsemail addresses - Set
client.Credentialswith valid app password
Start the application by pressing F5 or clicking the Run button.
The application will launch on http://localhost:5000 or http://localhost:5001 (HTTPS).
- Build and run the solution (F5)
- API endpoint is available at:
http://localhost:5000/api/pivot/post - Trigger export by making a POST request to the endpoint
- Excel file is saved to
D:\Export\Sample.xlsx - Optional: Email notification sent with the generated Excel attachment
POST /api/pivot/post HTTP/1.1
Host: localhost:5000
Content-Type: application/json
{
"Action": "onExcelExport",
"Hash": "a8016852-2c03-4f01-b7a8-cdbcfd820df1",
"ExportAllPages": true
}PivotController/
βββ PivotController.csproj # Project configuration with dependencies
βββ PivotController.sln # Visual Studio solution file
βββ Program.cs # ASP.NET Core startup configuration
βββ appsettings.json # Application settings
βββ appsettings.Development.json # Development configuration
β
βββ Controllers/
β βββ PivotController.cs # Main API controller for pivot operations
β
βββ DataSource/
β βββ DataSource.cs # Data source definitions and providers
β βββ sales.csv # Sample CSV data file
β βββ sales-analysis.json # Sample JSON data file
β
βββ Services/
β βββ TimedHostedService.cs # Background service for scheduled tasks
β
βββ Properties/
β βββ launchSettings.json # Debug launch configuration
β
βββ bin/ # Compiled binaries
βββ obj/ # Build artifacts
User Request (POST /api/pivot/post)
β
PivotController.Post()
β
Load Data Source (CSV/JSON/In-Memory)
β
Configure Pivot Engine Settings
β
Generate Pivot Report
β
Create Excel Workbook via Syncfusion.XlsIO
β
Update Worksheet with Pivot Data
β
Save to File System & Send Email
β
Return Response
- Handles API requests for pivot data and Excel export
- Manages pivot engine configuration and data aggregation
- Implements memory caching for performance optimization
- Triggers email notifications with Excel attachments
- Provides virtual product data with sales metrics
- Supports multiple data source formats (CSV, JSON, Collections)
- Implements INotifyPropertyChanged for real-time updates
- Background service for scheduled pivot processing
- Executes periodic data aggregation tasks
- Integrates with ASP.NET Core hosted service framework
Configure pivot field layout in PivotController.cs:
var param = new FetchData
{
Rows = new List<FieldOptions>
{
new FieldOptions { Name = "ProductID" }
},
Columns = new List<FieldOptions>
{
new FieldOptions { Name = "Country" }
},
Values = new List<FieldOptions>
{
new FieldOptions { Name = "Price", Caption = "Price" },
new FieldOptions { Name = "Sold", Caption = "Units Sold" }
}
};Configure in appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}Uncomment the desired data source in GetData method:
// Option 1: In-memory virtual data (default)
return new DataSource.PivotViewData().GetVirtualData();
// Option 2: CSV file
return new DataSource.PivotCSVData().ReadCSVData("DataSource/sales.csv");
// Option 3: JSON file
return new DataSource.PivotJSONData().ReadJSONData("DataSource/sales-analysis.json");
// Option 4: Remote CSV via HTTP
return new DataSource.PivotCSVData().ReadCSVData("http://cdn.syncfusion.com/data/sales-analysis.csv");The application automatically exports pivot data on startup. To manually trigger:
var controller = new PivotController(cache, environment);
await controller.Post();Modify the param object in Post() method to change:
- Row Fields: Product categories, regions, time periods
- Column Fields: Countries, years, quarters
- Value Fields: Sum, Count, Average aggregations
EnableServerSideAggregation = trueQ: Application won't start
- Ensure .NET 7.0 SDK is installed:
dotnet --version - Check if port 5000/5001 is available
- Review console output for specific error messages
Q: Excel file not being created
- Verify export path exists:
D:\Export\ - Check file permissions on the export directory
- Ensure Syncfusion.XlsIO NuGet package is properly installed
Q: Email not sending
- Configure SMTP credentials in
SendEMail()method - Use app-specific password for Gmail/Office365
- Check firewall/proxy settings for port 587 access
Q: Performance issues with large datasets
- Enable
EnableServerSideAggregation = true - Increase memory cache size in
Program.cs - Consider implementing pagination
Q: Port already in use
- Change port in
Properties/launchSettings.json - Or use PowerShell:
netstat -ano | findstr :5000
- ASP.NET Core Documentation
- Syncfusion Pivot Engine Guide
- Syncfusion Excel Export Guide
- MDN Web Documentation
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit changes (
git commit -m 'Add YourFeature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
This project is licensed under the Syncfusion Community License. See Syncfusion License for details.
For questions, issues, or suggestions:
- π§ Open a GitHub issue with detailed reproduction steps
- π¬ Review the Troubleshooting section above
- π Check existing documentation and resource links