Im using the below C# code to insert the data in different cells in a CSV file and should be able to save it. When i execute the code, the data in individual cells get merged into single cell and file is changed to Read only mode. please support what can be done to insert data in specific cells in CSV file and to save it without disturbing the format and alignment of the data.
Code:
Excel.Application excelAppObj = new Excel.Application();
excelAppObj.DisplayAlerts = false;
//Open the excel work book
Excel.Workbook workBook = excelAppObj.Workbooks.Open("D:\\NAL_SSR_stats_stn.CSV", 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, false, false);
//Get the first sheet of the selected work book
Excel.Worksheet worksheet = (Excel.Worksheet)workBook.Worksheets.get_Item(1);
//Write 20 in Cell - C3
worksheet.Cells[1, 3] = "AP";
worksheet.Cells[1, 4] = "APC";
worksheet.Cells[1, 5] = "NOC";
worksheet.Cells[1, 6] = "NOP";
worksheet.Cells[1, 7] = "NOQ";
worksheet.Cells[1, 8] = "NOE";
//Save work book (.csv format)
workBook.SaveAs("D:\\NAL_SSR_stats_stn.CSV", Excel.XlFileFormat.xlCSVWindows, null, null, true, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);