Created
December 26, 2025 10:01
-
-
Save mustafabutt-dev/0f2df20ecb0dc79529cfcb94d88fcad0 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 System.Text; | |
| using Aspose.Cells; | |
| namespace CsvToExcelConverter | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| if (args.Length != 2) | |
| { | |
| Console.WriteLine("Usage: CsvToExcelConverter.exe <input.csv> <output.xlsx>"); | |
| return; | |
| } | |
| string csvPath = args[0]; | |
| string xlsxPath = args[1]; | |
| try | |
| { | |
| ConvertCsvToXlsx(csvPath, xlsxPath); | |
| Console.WriteLine($"Conversion successful: {xlsxPath}"); | |
| } | |
| catch (Exception ex) | |
| { | |
| Console.WriteLine($"Error during conversion: {ex.Message}"); | |
| } | |
| } | |
| public static void ConvertCsvToXlsx(string csvPath, string xlsxPath) | |
| { | |
| // Load CSV with UTF‑8 encoding and default comma separator | |
| var loadOptions = new LoadOptions(LoadFormat.Csv) | |
| { | |
| Encoding = Encoding.UTF8, | |
| CsvSeparator = ',' | |
| }; | |
| // Create workbook from CSV | |
| var workbook = new Workbook(csvPath, loadOptions); | |
| // Optimize memory usage for large files | |
| workbook.Settings.MemoryOptimization = true; | |
| // Save as XLSX | |
| workbook.Save(xlsxPath, SaveFormat.Xlsx); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment