Created
December 28, 2025 18:59
-
-
Save mustafabutt-dev/01dcefe7cb88d9bd170c3c0fb8046fdb 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; | |
| using Aspose.Cells.Utility; | |
| namespace CsvToExcelDemo | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // Path to the source CSV file | |
| string csvPath = @"C:\Data\sample.csv"; | |
| // Path for the generated Excel file | |
| string excelPath = @"C:\Data\sample.xlsx"; | |
| // Optional: Set up load options for CSV | |
| LoadOptions loadOptions = new LoadOptions(LoadFormat.Csv); | |
| // You can specify the delimiter if it's not a comma | |
| // loadOptions.CsvSeparator = ';'; | |
| // Load CSV into a Workbook object | |
| Workbook workbook = new Workbook(csvPath, loadOptions); | |
| // (Optional) Adjust workbook settings, e.g., apply a default style | |
| Worksheet sheet = workbook.Worksheets[0]; | |
| sheet.AutoFitColumns(); | |
| // Save the workbook as XLSX | |
| 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