Created
December 28, 2025 17:40
-
-
Save mustafabutt-dev/37308e90e7e47cf55860f193c2f23fa2 to your computer and use it in GitHub Desktop.
Convert CSV to Excel in C# with Aspose.cells
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using Aspose.Cells; | |
| namespace CsvToExcelDemo | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // Path to the source CSV file | |
| string csvPath = @"C:\Data\sample.csv"; | |
| // Path for the output Excel file | |
| string excelPath = @"C:\Data\sample.xlsx"; | |
| // Configure load options for CSV parsing | |
| LoadOptions loadOptions = new LoadOptions(LoadFormat.Csv) | |
| { | |
| // Set the delimiter if it's not a comma (e.g., ';') | |
| // Delimiter = ';', | |
| // Enable automatic data type detection | |
| ConvertNumericData = true, | |
| ConvertDateTimeData = true | |
| }; | |
| // Load the CSV file into a Workbook | |
| Workbook workbook = new Workbook(csvPath, loadOptions); | |
| // Optional: Auto-fit columns for better appearance | |
| Worksheet sheet = workbook.Worksheets[0]; | |
| sheet.AutoFitColumns(); | |
| // Save the workbook as an XLSX file | |
| workbook.Save(excelPath, SaveFormat.Xlsx); | |
| Console.WriteLine("CSV has been successfully converted to Excel."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment