Hi
HRESULT: 0x8002000B (DISP_E_BADINDEX)) this means invalid index, so within your for loop you are accessing a index that doesn't exists.
1) check where the index is going wrong;
2) make sure the cell is converted to range as below
for (int j = 0; j < itemDataGridView.Columns.Count; j++)
{
oRange = oSheet.Cells[1, j + 1] as Excel_12.Range;
oRange.Value2 = itemDataGridView.Columns[j].HeaderText;
}
for (int i = 0; i < itemDataGridView.Rows.Count - 1; i++)
{
for (int j = 0; j < itemDataGridView.Columns.Count; j++)
{
oRange = oSheet.Cells[i + 2, j + 1] as Excel_12.Range;
oRange.Value2 = itemDataGridView.Rows[i].Cells[j].Value;
}
}
you can see I removed the cast and used the "as"; the reason for this is if the cell returns null, then you cannot cast them, but the "as" will assign it as null.
hope this helps.
Jegan