I'm writing a program that copy specific columns from pre-generated .csv file to template xlsx file. With my code I'am only able to achive copying the whole csv file to the first column. Any tips how to make the program see " ; " as a separator during pasting? Also if I overpass this problem how to copy only specific columns that i choose?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
namespace Kreator
{
class Program
{
static void Main(string[] args)
{
Excel.Application srcApp;
Excel.Workbook srcWorkbook;
Excel.Worksheet srcWorksheet;
Excel.Application destApp;
Excel.Workbook destWorkbook;
Excel.Worksheet destWorksheet;
string srcPath = "C:\\Users\\Desktop\\Raport.csv";
string destPath = "C:\\Users\\Desktop\\XXX.xlsx";
srcApp = new Excel.Application();
srcWorkbook = srcApp.Workbooks.Open(srcPath);
srcWorksheet = srcWorkbook.Worksheets.get_Item(1);
destApp = new Excel.Application();
destWorkbook = destApp.Workbooks.Open(destPath,0,false);
destWorksheet = destWorkbook.Worksheets.get_Item(1);
Excel.Range srcRange = srcWorksheet.get_Range("A1", "C20");
Excel.Range destRange = destWorksheet.get_Range("C10","E29");
srcRange.Copy(Type.Missing);
destRange.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteValu es, Microsoft.Office.Interop.Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone);
destWorkbook.SaveAs("C:\\Users\\Desktop\\GotowyPlik" + DateTime.Now.ToString("MM_dd_yyyy") + ".xlsx");
srcApp.Application.DisplayAlerts = false;
destApp.Application.DisplayAlerts = false;
srcWorkbook.Close(false, null, null);
destWorkbook.Close(true, null, null);
destApp.Quit();
srcApp.Quit();
}
}
}