This article only scratches the surface of the full capabilities of the Spread.NET WPF spreadsheet component. Review the documentation to see some of the many available features. Integrating a spreadsheet component into your applications allows you to customize your users' experience and provide them with familiar spreadsheet functionality that is all contained within your own controlled application.
Quick Start Guide | |
---|---|
Tutorial Concept |
Learn how to build a C# WPF app that exports spreadsheet data to CSV and converts Excel (.xlsx) files to CSV using a WPF Spreadsheet Component. |
What You Will Need |
|
Controls Referenced |
When building WPF applications that handle spreadsheet data, exporting to CSV is a common requirement—especially for data exchange with other systems or legacy tools. While CSV is lightweight and easy to process, many users also work with rich Excel files (.xlsx). This tutorial shows how to use the WPF spreadsheet control, included in Spread.NET, in a .NET app to load Excel workbooks and export their data to CSV—all from the application’s UI.
Download a 30-Day Trial of this Powerful WPF Spreadsheet Component!
Import XLSX and Convert to CSV in a .NET WPF Apps using C#:
- Configure a .NET WPF Spreadsheet Application
- Load an Excel (.xlsx) File into the WPF Spreadsheet- OpenExcel Method
- Export a .NET WPF Spreadsheet Data to a CSV File - SaveAs Method
Download a Sample WPF Spreadsheet App to Follow Along with This Tutorial!
Configure a .NET WPF Spreadsheet Application
Open Visual Studio 2022 and create a New Project. Select WPF Application, name the project XLSX_to_CSV_WPF, and select .NET 8.0 as the framework.
In the MainWindow.xaml.cs file, add place holder functions that we will later add logic to.
Next, add a Menu control from the Toolbox under All WPF Controls. Create two menu items under File: Open XLSX and Save CSV. Then, in the MainWindow.xaml editor, bind each menu item to the corresponding command defined in MainWindow.xaml.cs.
Drag a Visual Studio Grid control into your layout. Define four RowDefinitions—use fixed heights, such as 30 for the top row to reserve space for the spreadsheet formula bar, and 350 for a lower row that will hold the WPF spreadsheet control.
Next, on the Solution Explorer, expand the project, XLSX_to_CSV_WPF; then, right-click Dependencies and select Manage NuGet Packages… Search for and install Mescius.Spread.Wpf, the WPF spreadsheet component we will use in this tutorial.
Drag and drop a GcSpreadSheet control to the bottom grid row. Then in the top row, add a GcSpreadNameBox and ensure the GcFormulaBar is associated to the spreadsheet instance.
The WPF application will now have the WPF spreadsheet control and associated formula bar added to the grid:
Load an Excel (.xlsx) File into the WPF Spreadsheet
We can now add the ability to import an existing Excel XLSX file into the current WPF spreadsheet instance using Spread for WPF’s OpenExcel method.
Check out the WPF Spreadsheet’s Load Files documentation to learn more.
Export WPF Spreadsheet Data to a CSV File using C#
CSV exporting capabilities can be invoked in the WPF application using the Spread for WPF’s SaveAs method and specifying the data as a .csv file using the CSV field of the FileFormat enumeration.
See Spread for WPF’s Save as Comma-Separated Value (.csv) documentation to learn more.