首页 > 解决方案 > 无法将“System.Reflection.Missing”类型的“System.Reflection.Missing”值转换为“System.Int32”类型。- PowerShell PPT打印

问题描述

我正在尝试.printout在 PowerPoint 中输入默认值/空值/缺失值,但我无法让它工作。给我带来麻烦的值在此页面中定义为整数。

通常我已经能够使用[System.Type]::Missing或者''这些都不起作用,我得到以下信息:

Cannot convert the "System.Reflection.Missing" value of type "System.Reflection.Missing" to type "System.Int32".

如何.printout为 PowerPoint 的这两个参数输入空值?

到目前为止,这是我的代码:

###PPT
IF ($FILETYPE -eq "PPT") {
 ECHO "PPT_FOUND"

 $msoFalse = [Microsoft.Office.Core.MsoTriState]::msoFalse
 $msoTrue = [Microsoft.Office.Core.MsoTriState]::msoTrue

 $ObjPPT = New-Object -comobject PowerPoint.Application
 $ObjPPT.Visible  = $msoTrue
 #$ObjPPT.DisplayAlerts = $msoFalse 
 #Exception setting "DisplayAlerts": "Cannot convert value "msoFalse" to type "Microsoft.Office.Interop.PowerPoint.PpAlertLevel" due to enumeration values that are not valid. Specify one of the following 
 #enumeration values and try again. The possible enumeration values are "ppAlertsNone,ppAlertsAll"."
 
 #.Open
 $FILENAME = $FILEPATH
 IF (!$ReadOnly){$ReadOnly = $msoTrue}
 IF (!$Untitled){$Untitled = $missing}
 IF ((!$WithWindow) -and ($OPENUI -eq "FALSE")){$WithWindow = $msoFalse} ELSE {$WithWindow = $msoTrue}
 $ObjPresentation=$ObjPPT.Presentations.open($FILENAME,$ReadOnly,$Untitled,$WithWindow)

 #.Print
 #.PrintOut (From[Integer], To[Integer], PrintToFile[String], Copies [Integer], Collate[Bool]{msoTrue/False}) 
 IF (!$From){[int]$From = $missing}
 IF (!$To){[int]$To = $missing}
 IF (!$PrintToFile){[string]$PrintToFile = $missing}
 #Copies Defined Earlier
 IF (!$Collate){$Collate = $msoTrue}
 #$ObjPresentation.printout($From,$To,$PrintToFile,$COPIES,$Collate)
 $ObjPresentation.printout($From,$To)# , ,$COPIES,$Collate)

 #All Done
 Sleep 2
 $ObjPresentation.Close()
 $ObjPPT.Quit()
 Do-CloseIfRunning -Process $PROCESS
}

[gc]::collect()
[gc]::WaitForPendingFinalizers()

#Get-Variable
#PAUSE

标签: powershellpowerpoint

解决方案


原来 using0导致错误,但使用-1forFrom/To值按预期工作(空值)。


推荐阅读