I'm new to C# and trying to accomplish some simple excel manipulation through the interop library.
I'd like to delete a text value which always appears as a separate line below the actual data table (with a blank row between the table and the text). It's a 'rows selected.' count which prints out in an automated report. It always appears in the first column.
The error "COMexception unhandled - Cannot access read-only document - test1.xlsx" appears after the row is deleted and I try to Close() the workbook.
I cannot seem to release the workbook, I've tried a lot of random garbage collection methods found on other forums, but has anyone seen this before?
Appreciate the help!
EDIT - So the file isn't read-only until I start running the program. Once I run the program it becomes locked and read-only. It isn't closing/releasing the workbook...
EDIT - I ended up adding a Workbook.Save() function and using the Application object's Quit() function. This question was also very informative (similar question).
        public void ExcelManip(string thisFileName)
        {
            Workbook workBook = _excelApp.Workbooks.Open(thisFileName,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing);
            DeleteRowCount(ref workBook);
            workBook.Save();
            workBook.Close(false, Type.Missing, Type.Missing);
            _excelApp.Application.Quit();
            _excelApp.Quit();
            //workBook.Close(true, thisFileName);//ERROR;Cannot access read-only document
            //Marshal.ReleaseComObject(workBook);
            //GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
 
    