作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在一个项目中,我需要将数千个文档从HTML转换为Word。我正在使用此功能:
function saveas-document ($docs) {
$opendoc = $word.documents.open($docs);
$savepath = $docs -replace [regex]::escape($htmPath),"$docpath"
$opendoc.saveas([ref]"$savepath", [ref]$saveFormat);
$opendoc.close();
}
$word.Visible-$False
参数。
Save As...
-force
作为参数吗?放置该参数的最佳位置在哪里?
Method invocation failed because [Microsoft.Office.Interop.Word.DocumentClass] doesn't contain a method named 'quit'.
At C:\users\x46332\desktop\sad003.ps1:69 char:18
+ $opendoc.quit <<<< ()
+ CategoryInfo : InvalidOperation: (quit:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Exception calling "SaveAs" with "16" argument(s): "COM object that has been separated from its underlying RCW cannot be
used."
At C:\users\x46332\desktop\sad003.ps1:73 char:20
+ $opendoc.saveas <<<< ([ref]"$savepath", [ref]$saveFormat);
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Exception calling "Close" with "3" argument(s): "COM object that has been separated from its underlying RCW cannot be u
sed."
At C:\users\x46332\desktop\sad003.ps1:74 char:19
+ $opendoc.close <<<< ();
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
最佳答案
尝试将readonly变体添加到方法中,这是第二个变体,请参见http://msdn.microsoft.com/en-us/library/office/bb216319(v=office.12).aspx。
即:
$opendoc = $word.documents.open($docs,$false,$true);
关于powershell - 如何在Powershell中强制执行文件操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14158962/
我是一名优秀的程序员,十分优秀!