How To Convert .CSV To .XLS In C# .NET ?

Forums .NETHow To Convert .CSV To .XLS In C# .NET ?
Staff asked 1 year ago

I Want To Convert .CSV To .XLS In C#.

Answers (1)

Add Answer
Shaikh Hafeezjaha Marked As Accepted
Staff answered 1 year ago
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
            //Save file as csv file
            wb.SaveAs(xls, 51);
            //Close the Workbook.
            //Quit Excel Application.
Try this.


Select Categories