简体   繁体   中英

Cannot Load Workbook from Excel File - Office.Interop.excel

I'm using Office Interop for Excel Version 15.0.0.0

There is no option to create a workbook from an Existing File.The old sample code uses the following method to create a workbook

Workbook workbook = new Workbook();
workbook.LoadFromFile(@"D:\MyExcel\SurfaceSample.xls");

This method --> LoadFromFile has been removed from the current library,also the open method is a delegate.I have refereed the documentation but cannot find a relevant method.

The Office object models don't work the same as those of the .NET Framework. For one thing, the New keyword should never be used for anything except the Application .

In order to create a new object (copy) from an existing file, Office applications provide the Add method. So something more like:

Workbook wb = xlApp.Workbooks.Add(filePathToTemplate);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM