Created
December 28, 2025 16:47
-
-
Save mustafabutt-dev/2e47c5a590ba032b7e251a3fa2662a46 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"; | |
| // Load CSV into a Workbook object | |
| Workbook workbook = new Workbook(csvPath, new LoadOptions(LoadFormat.Csv)); | |
| // Get the first worksheet | |
| Worksheet sheet = workbook.Worksheets[0]; | |
| // Optional: Auto‑fit all columns for better readability | |
| sheet.AutoFitColumns(); | |
| // Optional: Set a header style for the first row | |
| Style headerStyle = workbook.CreateStyle(); | |
| headerStyle.Font.IsBold = true; | |
| sheet.Cells.Rows[0].ApplyStyle(headerStyle, new StyleFlag() { FontBold = true }); | |
| // Save the workbook as an Excel file | |
| workbook.Save(excelPath, SaveFormat.Xlsx); | |
| Console.WriteLine("CSV file successfully converted to Excel."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment