Copy from csv file to excel worksheet

Ask general questions here.
Thet Thet
Posts: 27
Joined: Fri Jan 11, 2019 7:02 am

Copy from csv file to excel worksheet

Post by Thet Thet » Wed Jul 24, 2019 7:15 am

Hi,

How to copy from csv file worksheet into currently active excel worksheet.
How can I do that?

thanks

manish
Certified Professional
Certified Professional
Posts: 53
Joined: Fri Aug 10, 2018 12:46 pm

Re: Copy from csv file to excel worksheet

Post by manish » Wed Jul 24, 2019 7:48 am

HI,

You can try the below solution

Code: Select all


			string inputFilepath = @"C:\Temp\output.csv";
			string outputFilepath=  @"C:\temp\testtable.xlsx";
						
			Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
			Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(inputFilepath);
			
			wb.SaveAs(outputFilepath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault);
			wb.Close(false);
			app.Quit();
			

This code will take a .csv file as the input and generate a new .xlsx file copying the contents of the csv to it.

Thet Thet
Posts: 27
Joined: Fri Jan 11, 2019 7:02 am

Re: Copy from csv file to excel worksheet

Post by Thet Thet » Wed Jul 24, 2019 8:33 am

Hi,

I am sorry,My explanation is missing. I don't want to create a new Excel file.
I want to copy from csv file data into already exit excel file.

thanks.