Il s'agit du code que j'utilisais avant l'installation d'Office 2016.Échec Microsoft.Office.Interop.Excel à l'initialisation (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;
Le code a bien fonctionné, mais après l'installation d'Office 2016, j'ai vu que je ne pouvais pas utiliser using Excel = Microsoft.Office.Interop.Excel;
La seule bibliothèque compatible que j'ai trouvé est
Microsoft.Office.Core (Microsoft Office 16.0 Object Library)
I could't trouver des exemples d'accès aux fichiers Excel. Est-il un autre moyen d'accéder aux fichiers Excel avec Office 2016 installé (PIA)
C'est l'erreur que je reçois lorsque je tente d'exécuter le code
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).
Essayez ceci: https://stackoverflow.com/questions/5070124/why-doesnt-the-office-pia-install-correctly-to-the-gac –
Ce n'est pas très évident ce que cela a à voir avec " initialisation ". Les PIA [ont été obsolètes] (https://stackoverflow.com/questions/21013912/can-i-still-use-microsoft-office-interop-assemblies-with-office-2013) pour les 7 dernières années, vous aurez dois cesser de les utiliser. Si c'est vraiment "initialisation", votre programme ne démarrera pas, alors considérez que vous pouvez avoir installé la version 64 bits d'Office. Votre programme doit donc également fonctionner en mode 64 bits. –
Quand je dis initialisation, je veux dire l'instance d'un objet Excel pour accéder au fichier Excel. J'ai changé Office en 2016 et je pense que PIA est le principal problème que mon code ne fonctionne pas (je suppose). Quels changements dois-je faire pour accéder à un fichier Excel? – kostas