Strange error on Excel Workbook input

柔情痞子 提交于 2019-12-05 15:18:21

I suppose that in your code the fullname of Workbook is Microsoft.Office.Interop.Excel.Workbook, and that excel is an instance of Microsoft.Office.Interop.Excel.Application.

If this is the case your code can't work because Workbook is an interface, and interfaces do not have constructors. You have to ask the excel application to create the workbooks for you, and in your case you have to simply write:

Workbook wb = excel.Workbooks.Open(currentPath); 

In a similar way, if you want to create a new empty workbook, you should write:

Workbook wb = excel.Workbooks.Add(System.Reflection.Missing.Value);

I don't know about your error but I have done something similar like this:

 _app = new Excel.Application();
Excel.Workbook wb = _app.Workbooks.Open(currentPath);

Right click to your Solution and change Platform to x86 Rebuild your solution... Good luck to you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!