i m deveoping window application in c#.
my datagridview data is easily exported to excel.
but i m getting error when i also want to export datagridview's headers to excel.
error is : Exception from HRESULT: 0x800A03EC
and i m using code below
public void ExcelConversion()
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(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];
if (i == 0)
{
DataGridViewCell cell1 = dataGridView1[j, i];
xlWorkSheet.Cells[1, j] = dataGridView1.Columns[j].HeaderText.ToString();
}
else
{
xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
}
}
}
xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
can anyone help me please?
THANKS IN ADVANCE