using System; namespace ReadCSVFileApplication { class ReadCSVFile { static void Main(string[] args) { { try { List<String> column1 = new ArrayList<String>(); List<String> column2 = new ArrayList<String>(); //Add remaining columns if exist StreamReader objReader = new StreamReader(@"received.csv"); String row = objReader.ReadLine(); if (!string.IsNullOrEmpty(row)) { //Execute a loop over the columns. String[] arralistOfColumns= row.Split("##"); column1.add(arralistOfColumns[0]); column2.add(arralistOfColumns[1]); //Asaign remaining columns if exist } String inputFile = @"C:\Users\PROJEKTSTATUS_GESAMT_neues_Layout.xlsm"; Excel.Application oXL = new Excel.Application(); //Open a Excel File Excel.Workbook oWB = oXL.Workbooks.Add(inputFile); Excel._Worksheet oSheet = oWB.ActiveSheet; oSheet.Cells[1, 1] = "FirstColumn Name"; oSheet.Cells[1, 2] = "SecondColumn Name"; // Here 1 is the rowIndex and 2 is the columnIndex. //Enter the Header data in Column A int i = 0; for (i = 0; i < Name.Count; i++) { oSheet.Cells[i + 2, 1] = Name[i]; } //Enter the Percentage data in Column B for (i = 0; i < Percentage.Count; i++) { oSheet.Cells[i + 2, 2] = Percentage[i]; } //String ReportFile = @"D:\Excel\Output.xls"; oWB.SaveAs(inputFile, Excel.XlFileFormat.xlOpenXMLWorkbookMacroEnabled, Type.Missing, Type.Missing, false, false, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); oXL.Quit(); Marshal.ReleaseComObject(oSheet); Marshal.ReleaseComObject(oWB); Marshal.ReleaseComObject(oXL); oSheet = null; oWB = null; oXL = null; GC.GetTotalMemory(false); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.GetTotalMemory(true); } catch (Exception ex) { String errorMessage = "Error reading the Excel file : " + ex.Message; } } } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more