Powershell изменить размер изображения в документе Word - PullRequest
0 голосов
/ 25 октября 2019

Я добавил изображение в текстовый документ с помощью powershell. Как я могу изменить размер?

$Word = New-Object -ComObject Word.Application

$Word.Visible = $True

$Document = $Word.Documents.Add()

$Selection = $Word.Selection

$Selection.InlineShapes.AddPicture("$imagelocation")|Out-Null

$Selection.InlineShapes.Height = 50

$Selection.InlineShapes.Width = 50

Но я получаю следующие ошибки:

Exception setting "Height": 
"The property 'Height' cannot be found on this object. Verify that the property exists and can be set."

Exception setting "Width": 
"The property 'Width' cannot be found on this object. Verify that the property exists and can be set."

1 Ответ

2 голосов
/ 25 октября 2019

Вы пытаетесь установить Height и Width в коллекции, содержащей все встроенные фигуры.

Используйте конкретный объект InlineShape, возвращаемый AddPicture() вместо:

$newInlineShape = $Selection.InlineShapes.AddPicture("$imagelocation")
$newInlineShape.Height = 50
$newInlineShape.Width = 50
...