Question PowerShell et Excel 2007 (résolu)

Plus d'informations
il y a 17 ans 1 semaine #4322 par Patrick Berthon
Bonjour,

j'ai un script qui fonctionnait très bien sur un PC, mais qui ne fonctionne plus sur un autre sans modification.

j'obtiens l'erreur suivante :
[code:1]
Exception calling \"SaveAs\" with \"2\" argument(s): \"Exception de HRESULT : 0x800A03EC\"
At C:\Users\Patrick Berthon\Desktop\Scripts PowerShell\DHCP.ps1:67 char:12
+ $_.SaveAs <<<< (\"$pwd\$($_.Name).csv\",$FileFormat)
+ CategoryInfo : NotSpecified: (:«») [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation

Unable to find type [Microsoft.Office.Interop.Excel.xlFileFormat]: make sure that the assembly containing this type is
loaded.
At C:\Users\Patrick Berthon\Desktop\Scripts PowerShell\DHCP.ps1:64 char:60
+ $FileFormat=[Microsoft.Office.Interop.Excel.xlFileFormat] <<<< ::«»xlCsv
+ CategoryInfo : InvalidOperation: (Microsoft.Offic...el.xlFileFormat:«»String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
[/code:1]

et voici le bout de code :
[code:1] $excel = New-Object -ComObject excel.application
$excel.Visible = $true;
$oBook = $excel.Workbooks.Open($arg1);
$oBook.Sheets | ForEach-Object {
$FileFormat=[Microsoft.Office.Interop.Excel.xlFileFormat]::«»xlCsv
if(test-path \"$pwd\$($_.Name).csv\"«»){Remove-Item \"$pwd\$($_.Name).csv\"}
Write-Host \"$($_.Name).csv\"
$_.SaveAs(\"$pwd\$($_.Name).csv\",$FileFormat)
}
$excel.displayalerts = $False
$excel.quit()
[/code:1]

z'auriez pas une idée, s'il vous plait ? (c'était office 2007 et c'est toujours office 2007 sur les 2 PCs)

merci,

Zylwee

[edit]j'y pense, le premier PC, c'était un XP, le second, c'est un Vista

Message édité par: Zylwee, à: 14/03/09 11:56<br><br>Message édité par: Zylwee, à: 15/03/09 08:26

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 1 semaine #4323 par Laurent Dardenne
Salut,
d'après le msg d'erreur

Unable to find type [Microsoft.Office.Interop.Excel.xlFileFormat]: make sure that the assembly containing this type is
loaded.

A prioris les fichiers interop ne sont pas installé/configuré sur le poste. Bien que par défaut ce devrait être le cas avec Office 2007.

Vérifie leur présence dans le GAC -&gt; C:\WINDOWS\assembly
Ou c'est la valeur [Microsoft.Office.Interop.Excel.xlFileFormat]::xlCsv
qui pose pb

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 1 semaine #4324 par Patrick Berthon
Réponse de Patrick Berthon sur le sujet Re:PowerShell et Excel 2007
Re

les interop semblent installés
[code:1]
d---- 06/03/2009 16:06 Microsoft.Office.InfoPath.Permission
d---- 06/03/2009 16:06 Microsoft.Office.Interop.Access
d---- 06/03/2009 16:06 Microsoft.Office.Interop.Access.Dao
d---- 06/03/2009 16:06 Microsoft.Office.Interop.Excel
d---- 06/03/2009 16:06 Microsoft.Office.Interop.Graph
d---- 06/03/2009 16:06 Microsoft.Office.Interop.InfoPath
d---- 06/03/2009 16:06 Microsoft.Office.Interop.InfoPath.SemiTrust
d---- 06/03/2009 16:06 Microsoft.Office.Interop.InfoPath.Xml
d---- 06/03/2009 16:06 Microsoft.Office.Interop.OneNote
d---- 06/03/2009 16:06 Microsoft.Office.Interop.Outlook
d---- 06/03/2009 16:06 Microsoft.Office.Interop.OutlookViewCtl
d---- 07/03/2009 11:13 Microsoft.Office.Interop.PowerPoint
d---- 06/03/2009 16:06 Microsoft.Office.Interop.Publisher
d---- 06/03/2009 16:06 Microsoft.Office.Interop.SmartTag
d---- 07/03/2009 11:09 Microsoft.Office.Interop.Word
[/code:1]

mais à priori, la valeur en question doit être bonne puisqu'elle a fonctionné sur l'autre PC :S

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 1 semaine #4325 par Laurent Dardenne
Zylwee écrit:

mais à priori, la valeur en question doit être bonne puisqu'elle a fonctionné sur l'autre PC

C'est bien la difficulté du problème énoncé :blink:
Par contre je viens de percuter, au vue des détails du message d'erreur, tu utilises PS V2 en ctp2 ou 3.
Que donne à ce propos un petit coup d'oeil sur MsConnect ?

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 1 semaine #4326 par Patrick Berthon
Réponse de Patrick Berthon sur le sujet Re:PowerShell et Excel 2007
CTP3, et l'autre probablement aussi, mais vu que je l'ai formaté, je peux plus aller vérifier.

par contre, le Vista est un Vista 64 bits.

pour le MsConnect : gniiiih ? pourrais-tu développer s'il te plait ?

merci

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 1 semaine #4327 par Patrick Berthon
Réponse de Patrick Berthon sur le sujet Re:PowerShell et Excel 2007
si je fais ça :
[code:1]
[AppDomain]::CurrentDomain.GetAssemblies()
[/code:1]

ça donne ça :
[code:1]
PS C:\Users\Patrick Berthon\Desktop\Scripts PowerShell&gt; [AppDomain]::CurrentDomain.GetAssemblies()

GAC Version Location
---

True v2.0.50727 C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.ConsoleHost\1.0.0.0__31bf3856ad364e35\Micros...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Man...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Diagnostics\1.0.0.0__31bf3856ad364e...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System.Configuration.Install\2.0.0.0__b03f5f7f11d50a3a\System.Con...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.WSMan.Management\1.0.0.0__31bf3856ad364e35\Microsoft.WS...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.WSMan.Runtime\1.0.0.0__31bf3856ad364e35\Microsoft.WSMan...
True v2.0.50727 C:\Windows\assembly\GAC_64\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\1.0.0.0__31bf3856ad364e35\M...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Management\1.0.0.0__31bf3856ad364e3...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System.Management\2.0.0.0__b03f5f7f11d50a3a\System.Management.dll
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System.ServiceProcess\2.0.0.0__b03f5f7f11d50a3a\System.ServicePro...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Security\1.0.0.0__31bf3856ad364e35\Microsoft...
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System.DirectoryServices\2.0.0.0__b03f5f7f11d50a3a\System.Directo...
True v2.0.50727 C:\Windows\assembly\GAC_64\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll
True v2.0.50727 C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll
True v2.0.50727 C:\Windows\assembly\GAC_64\CustomMarshalers\2.0.0.0__b03f5f7f11d50a3a\CustomMarshalers.dll
[/code:1]

est-ce que j'ai la liste de tous les assemblies installés ?

si oui, effectivement, il m'en manque ! :P

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.073 secondes
Propulsé par Kunena