powershell - 无法将“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
解决方案
原来 using0
导致错误,但使用-1
forFrom/To
值按预期工作(空值)。
推荐阅读
- javascript - 我想动态加载到入口点的 Webpack 捆绑模块
- postgresql - 如何声明一个 while 循环,直到成功完成 PL/PGSQL 中的 fetch 语句
- python-3.x - Pandas 使用过滤器按月计算唯一出现次数
- android - 删除按钮Android API 21的部分文本
- java - 为什么我的 CheerpJ 网页显示加载屏幕却无法使用?
- javascript - JavaScript 在包含在另一个带有“w3-include-html”的 html 文件中的 html 文件中时不起作用
- java - 使用 SharePoint API 下载文件:文件损坏
- docker - 多执行连接窗口显示一个容器的相同会话信息
- azure - 如何安全地从家里连接到 Azure 门户
- python - 如何从 FFT 分析中过滤基于特定频率的数据过滤?