In this topic, we’ll answer the question how to export large Excel file to CSV in C#. The steps to convert Excel file to CSV format programmatically in C# applications given below along with the simple and easy code will provide you the required solution.
The main problem developers face when processing large Excel file like XLSX or XLS is memory management. This problem can be easily resolved by setting MemorySetting property of LoadOptions class to MemoryPreference. This will help manage memory efficiently. The default value of this property is Normal which should be used in case of a regular size Excel files.
Steps to Export Large Excel File to CSV in C#
- Install Aspose.Cells for .NET package from NuGet.org
- Add Using directive for Aspose.Cells namespace
- Set Aspose license using SetLicense method
- Set MemorySetting property to MemoryPreference option
- Create an instance of Workbook Class and pass the LoadOptions object created in previous step
- Finally, save the exported output CSV file
C# Code to Save Large Excel File as CSV Format
The above code saves only the first sheet in the Excel file as CSV. However, if you have multiple sheets in the large excel file then you can use the following code snippet. Please note, in this case we again need to use the same MemorySetting property to properly and efficiently manage the memory.
Export Multiple Excel Sheets to Separate CSV Files
In the above code, we used the C# Console Application, but you can use the same code to export Excel file to CSV in ASP.NET or convert Excel file format to CSV in Windows applications with .NET Framework. This does not require Excel file on the system or server where your code is running.