I’m exporting a dataset to an existing Excel sheet using c# programming language. Hence i need to specifiy the exact column and row (Column G, Row 3)which the data to be inserted. Please note that the dataset has only 1 column. i have mentioned the coding that im using. But it doesn’t pass the dataset to the location that i need. Please help
dt = compareDataTables(Oracle, MIT);
dataGridView1.DataSource = dt;
//inserting to Excel file
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(textBox1.Text, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells["3", "G"] = cell.Value;
}
}
xlWorkBook.Save();
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
why xlWorkSheet.Cells[“3”, “G”] is hardcoded?, its over writing the data everytime