The code below creates a corrupted file/read-only excel csv file so i cant open the file to write data inside. I need to read the data from the csv file
then save it into an excel file to plat a graph. May I know what's wrong with the code? Cause everytime i want to delete the file that is generated, it's still running in the process even if i closed it. I have to go to Task Manager everytime to force close the process then only I can delete the file.
I have tried literally every solutions provided in this link but nothing solves my problem. I wanted to try using
but idk what changes I have to make so that's the only thing I haven't tried till now.
Excel.WorkBook xlWorkBook;
...
public void createXMLFile()
{
Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
MessageBox.Show("Excel is not properly installed!!");
return;
}
object misValue = System.Reflection.Missing.Value;
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[1, 1] = "Stroke";
xlWorkSheet.Cells[1, 2] = "Force";
xlWorkBook.SaveAs(filePath, Excel.XlFileFormat.xlWorkbookNormal, AccessMode: Excel.XlSaveAsAccessMode.xlExclusive);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);
MessageBox.Show("Excel file created , you can find the file
D:\\Work\\ExtractData\\DataCharts");
}