Error Show like this when
export databse to excel file
"The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.Office' (are you missing an assembly reference?"
if (dataGridView.Rows.Count > 0)
{
Microsoft.Office.Interop.Excel.ApplicationClass XcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
XcelApp.Application.Workbooks.Add(Type.Missing);
for (int i = 1; i < dataGridView.Columns.Count + 1; i++)
{
XcelApp.Cells[1, i] = dataGridView.Columns[i - 1].HeaderText;
}
for (int i = 0; i < dataGridView.Rows.Count; i++)
{
for (int j = 0; j < dataGridView.Columns.Count; j++)
{
XcelApp.Cells[i + 2, j + 1] = dataGridView.Rows[i].Cells[j].Value.ToString();
}
}
XcelApp.Columns.AutoFit();
XcelApp.Visible = true;
}
{
Microsoft.Office.Interop.Excel.ApplicationClass XcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
XcelApp.Application.Workbooks.Add(Type.Missing);
for (int i = 1; i < dataGridView.Columns.Count + 1; i++)
{
XcelApp.Cells[1, i] = dataGridView.Columns[i - 1].HeaderText;
}
for (int i = 0; i < dataGridView.Rows.Count; i++)
{
for (int j = 0; j < dataGridView.Columns.Count; j++)
{
XcelApp.Cells[i + 2, j + 1] = dataGridView.Rows[i].Cells[j].Value.ToString();
}
}
XcelApp.Columns.AutoFit();
XcelApp.Visible = true;
}


Rafnas T PRank #280 · 8.8K reputationPosted Jul 6, 2017, 11:40 PM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Jul 6, 2017, 9:53 PM EDT
Jyoti JodhaRank #1,408 · 1.2K reputationPosted Jul 6, 2017, 10:03 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted Jul 6, 2017, 10:11 PM EDT
tick click ok.
Jyoti JodhaRank #1,408 · 1.2K reputationPosted Jul 6, 2017, 10:14 PM EDT
Rafnas T P
Rafnas T PRank #280 · 8.8K reputationPosted Jul 6, 2017, 10:19 PM EDT
Jyoti JodhaRank #1,408 · 1.2K reputationPosted Jul 6, 2017, 10:31 PM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Jul 6, 2017, 10:47 PM EDT
Jyoti JodhaRank #1,408 · 1.2K reputationPosted Jul 6, 2017, 11:28 PM EDT