I am trying to creat code for export data from DGV to Excel . And i faced a problem in creating worksheet.
It showed error at the last two codes :
Error is :
cannot implicitly convert type 'object' to Microsoft.Office.Interop.Excel._Worksheet. An explicit conversion exists (are you missing a cast)
C#:
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
app.Visible = true
worksheet = workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
It showed error at the last two codes :
C#:
worksheet = workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
Error is :
cannot implicitly convert type 'object' to Microsoft.Office.Interop.Excel._Worksheet. An explicit conversion exists (are you missing a cast)
Last edited by a moderator: