Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mustafabutt-dev/01dcefe7cb88d9bd170c3c0fb8046fdb to your computer and use it in GitHub Desktop.

Select an option

Save mustafabutt-dev/01dcefe7cb88d9bd170c3c0fb8046fdb to your computer and use it in GitHub Desktop.
Convert CSV to Excel in C# with Aspose.cells
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