Datagridview to Excel:你错过了演员吗?

时间:2017-11-06 08:28:21

标签: c# excel datagridview

你可以告诉我为什么我在工作表= workbook.Sheets [“Sheet1”]上收到此错误的原因; &安培; worksheet = workbook.ActiveSheet;

“不能将类型'对象'转换为'Microsoft.office.Interop.Excel._Worksheet'。显式转换存在(你是否错过了演员?)”

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;***

            worksheet.Name = "Exported from gridview";

0 个答案:

没有答案