Not able to write to cell using this export-to-excel code
<p>I am using this code to export DataGridView rows to an Excel sheet.</p>

<pre><code>        Excel.Application xlApp;
        Excel.Workbook xlWorkBook;
        Excel.Worksheet xlWorkSheet;
        object misValue = System.Reflection.Missing.Value;


        xlApp = new Excel.ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Add(misValue);
        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

        int i = 0;
        int j = 0;

        for (i = 0; i &lt;= dgv.RowCount - 1; i++)
        {
            for (j = 0; j &lt;= dgv.ColumnCount - 1; j++)
            {
                DataGridViewCell cell = dgv[j, i];
                xlWorkSheet.Cells[i + 5, j + 2] = cell.Value;
            }
        }

        string SavedFilePath = Application.StartupPath + "\\GeneratedExcelReports\\";
        xlWorkBook.SaveAs(SavedFilePath + ExcelFileNameToCreate + ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
        xlWorkBook.Close(true, misValue, misValue);
        xlApp.Quit();
</code></pre>

<p>If I add this line of code:</p>

<pre><code>xlWorkSheet.Cells[0,1].Value = "My Test Report";
</code></pre>

<p>it generates error, because it has nothing as Value in the list that Intelli-Sense opens. How to edit a particular cell at run-time?</p>
