Bonjour à tous,
j'explique mon besoin : je souhaite exécuter un script PowerShell qui parse un fichier Excel (j'utilise l'objet "Interop.Excel"). Or sur ma machine Office n'est pas installé (et ne le serra pas malheureusement ^^), du coup je pensais installer seulement la DLL qui m'intérèsse, c'est à dire : Microsoft.Office.Interop.Excel.dll
Malheureusement cela ne fonctionne pas du tout, après le chargement de ma DLL, la création de l'instance de l'objet tomb en erreur.
Mon code :
La sotie :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 try { try { Add-Type -Path "C:\Temp\reflex\importExcel\Microsoft.Office.Interop.Excel.dll" } catch { [System.Reflection.Assembly]::LoadFile("C:\Temp\reflex\importExcel\Microsoft.Office.Interop.Excel.dll") } } catch { write-host -f red "[ERROR] load excel dll" write-host $Error[0] return } try { # $xl = New-Object Microsoft.Office.Interop.Excel.ApplicationClass $xl = New-Object -comobject Microsoft.Office.Interop.Excel.ApplicationClass $wb = $xl.Workbooks.Open($pathExcel) $ws = $wb.Sheets.Item(1) } catch { write-host -f red "[ERROR] Problem exist with the excel file : " $pathExcel write-host $Error[0] return }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 GAC Version Location --- ------- -------- False v1.1.4322 C:\Temp\...... New object : Retrievinf the COM class factory for component with CLSID {0000....000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)) ...
Can you help me ?
Samuel_
Partager