这是我在Office 2016安装之前使用的代码。Microsoft.Office.Interop.Excel初始化失败(Office 2016)
var excelApp = new Excel.Application();
excelApp.Visible = true;
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(finfo.FullName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
var cellValue =(excelWorksheet.Cells[a, b] as Excel.Range).Value;
的代码能正常工作,但办公室2016安装后,我已经看到了,我不能使用 using Excel = Microsoft.Office.Interop.Excel;
,我发现的唯一的兼容库
Microsoft.Office.Core (Microsoft Office 16.0 Object Library)
我便无法找到任何访问Excel文件的例子。是否有任何其他方式来访问Excel文件与Office 2016安装(PIA)
这是我得到的错误,当我尝试运行代码
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).
试试这个:https://stackoverflow.com/questions/5070124/why-doesnt-the-office-pia-install-correctly-to-the-gac –
这是不是很明显这是什么与“初始化”。过去7年PIA [已过时](https://stackoverflow.com/questions/21013912/can-i-still-use-microsoft-office-interop-assemblies-with-office-2013),你会必须停止使用它们。如果它确实是“初始化”,程序将无法启动,那么请考虑您可能安装了64位版本的Office。所以你的程序也需要以64位模式运行。 –
当我说初始化我的意思是Excel对象的实例来访问Excel文件。我将Office更改为2016年,我认为PIA是我的代码不起作用的主要问题(我猜)。我应该怎样做才能访问Excel文件? – kostas