Created
December 28, 2025 16:45
-
-
Save mustafabutt-dev/2c7493b2ebc208afc25f9a1c19b1724e 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; | |
| class CsvToExcelConverter | |
| { | |
| static void Main() | |
| { | |
| // Path to the source CSV file | |
| string csvPath = "input.csv"; | |
| // Configure load options for CSV (default delimiter is comma) | |
| var loadOptions = new LoadOptions(LoadFormat.CSV) | |
| { | |
| // Uncomment and modify if your CSV uses a different delimiter | |
| // CsvSeparator = ';', | |
| // Encoding = System.Text.Encoding.UTF8 | |
| }; | |
| // Load CSV into a Workbook object | |
| Workbook workbook = new Workbook(csvPath, loadOptions); | |
| // Optional: apply any worksheet customizations here | |
| Worksheet sheet = workbook.Worksheets[0]; | |
| Cells cells = sheet.Cells; | |
| // Example: Auto-fit columns for better appearance | |
| cells.AutoFitColumns(); | |
| // Save the workbook as an Excel file | |
| string excelPath = "output.xlsx"; | |
| workbook.Save(excelPath, SaveFormat.Xlsx); | |
| Console.WriteLine($"CSV file '{csvPath}' successfully converted to '{excelPath}'."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment