Created
December 28, 2025 18:38
-
-
Save mustafabutt-dev/0f40853e4f33c9bec85758c353316cc8 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) | |
| { | |
| // Apply license (optional for evaluation) | |
| try | |
| { | |
| var license = new License(); | |
| license.SetLicense("Aspose.Total.NET.lic"); | |
| } | |
| catch (Exception ex) | |
| { | |
| Console.WriteLine("License not applied: " + ex.Message); | |
| } | |
| // Define input and output paths | |
| string csvPath = "sample.csv"; | |
| string excelPath = "sample.xlsx"; | |
| // Configure load options for CSV | |
| var loadOptions = new LoadOptions(LoadFormat.Csv) | |
| { | |
| Encoding = System.Text.Encoding.UTF8, | |
| // Set delimiter if not a comma, e.g., ';' | |
| // Separator = ';' | |
| }; | |
| try | |
| { | |
| // Load CSV into a workbook | |
| var workbook = new Workbook(csvPath, loadOptions); | |
| // Save as XLSX | |
| workbook.Save(excelPath, SaveFormat.Xlsx); | |
| Console.WriteLine($"Conversion successful: {excelPath}"); | |
| } | |
| catch (Exception e) | |
| { | |
| Console.WriteLine("Error during conversion: " + e.Message); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment