C# Interop Save to excel from datagridview without creating new file
<p>I want to make changes to an existing file named "Original" in the directory "C:\Users\Twiga\Documents\VisualStudio2010\Projects\MarkSheetSystem\Original.xls".</p>

<p>Currently, I am only able to save the data that I have exported from my datagridview1 to a new file but that is not my intention.</p>

<p>Below is the code:</p>

<pre><code>private void btnexcel_Click(object sender, EventArgs e)
    {

        Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application(); 
        Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing); 
        Microsoft.Office.Interop.Excel._Worksheet worksheet = null; 

        try 
        { 

            worksheet = workbook.ActiveSheet; 

            worksheet.Name = "Marksheet 1";

            worksheet.Cells[12, 1] = dataGridView1.Rows[0].Cells[0].Value.ToString(); 


            int cellRowIndex = 10; 
            int cellColumnIndex = 1; 

            //Loop through each row and read value from each column. 
            for (int i = 0; i &lt; dataGridView1.Rows.Count; i++) 
            { 
                for (int j = 1; j &lt; dataGridView1.Columns.Count - 1; j++) 
                { 
                    // Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check. 
                    if (cellRowIndex == 0)
                    { 
                        worksheet.Cells[cellRowIndex, cellColumnIndex] = dataGridView1.Columns[j].HeaderText; 
                    } 
                    else 
                    { 
                        worksheet.Cells[cellRowIndex, cellColumnIndex] = dataGridView1.Rows[i].Cells[j].Value.ToString(); 
                    } 
                    cellColumnIndex++; 
                } 
                cellColumnIndex = 1; 
                cellRowIndex++; 
            } 

            //Getting the location and file name of the excel to save from user. 
            SaveFileDialog saveDialog = new SaveFileDialog(); 
            saveDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*"; 
            saveDialog.FilterIndex = 2; 

            if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
            { 
                workbook.SaveAs(saveDialog.FileName); 
                MessageBox.Show("The marksheet has been saved successfully!"); 
            }                
        } 
        catch (System.Exception ex) 
        { 
            MessageBox.Show(ex.Message); 
        } 
        finally 
        { 
            excel.Quit(); 
            workbook = null; 
            excel = null; 
        } 

    }
</code></pre>