Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

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