问题
I have a powershell script which use "-ComObject Word.Application". I would like to use this in a windows server but it doesn't have Word. For now, when i execute , i have this error.
New-Object : La récupération de la fabrique de classes COM pour le composant avec le CLSID
{00000000-0000-0000-0000-000000000000} a échoué en raison de l'erreur
suivante: 80040154 Classe non enregistrée
(Exception de HRESULT : 0x80040154 (REGDB_E_CLASSNOTREG)).
Au caractère E:\BELAIRREC\Scripts\PowerShell\Doc2PDF.ps1:27 : 16
+ $Wrd = New-Object -ComObject Word.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object],
COMException
+ FullyQualifiedErrorId :
NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
I think it's no doubt because Word is not installed. Is there a way to use -ComObject Word.Application without install Word ?
Thanks
回答1:
Depending on what you want to do, you might want to look at the OpenXML SDK, which is a free library from Microsoft that lets you manipulate Office documents without installing the Office products (though the SDK needs to be installed). The Open-XML-PowerTools is an open source collection of cmdlets that make working with the SDK easier.
回答2:
Any COM object you call must be installed on the computer.
There is a free Word viewer that you can download from Microsoft but I do not know if it has an exposed COM interface.
来源:https://stackoverflow.com/questions/50646343/use-comobject-word-application-without-install-word