using System;
using System.Collections.Generic;
using Excel = Microsoft.Office.Interop.Excel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSV_TO_XLS
{
class Program
{
static void Main(string[] args)
{
string csv = @"D:\Files\csvfile.csv";
string xls = @"D:\Files\xlsfile.xlsx";
Excel.Application xl = new Excel.Application();
//Open Excel Workbook for conversion.
Excel.Workbook wb = xl.Workbooks.Open(csv);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets.get_Item(1);
//Select The UsedRange
Excel.Range used = ws.UsedRange;
//Autofit The Columns
used.EntireColumn.AutoFit();
//Save file as csv file
wb.SaveAs(xls, 51);
//Close the Workbook.
wb.Close();
//Quit Excel Application.
xl.Quit();
}
}
}
Try this.