2013-02-21 29 views
0

我有一個Powershell(2.0)腳本,它使用Microsoft.Office.Interop.Word.WdSaveFormat遞歸地在Word中打開一系列html文件,然後分別使用wdFormatDocumentwdFormatDOSText參數保存爲Word和Text。該腳本爲每種文檔類型包含一個單獨的函數。Powershell:我可以擁有的輸出文件類型的數量是否有限制?

昨天,需求發生了變化,我現在也需要輸出一個RTF文檔。我添加了$saveFormatRTF變量

$saveFormatDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument"); 
$saveFormatTxt = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDOSText"); 
$saveFormatRTF = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF"); 

並且得到了以下錯誤。

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l 
oaded. 
At C:\users\x46332\Desktop\cgc\CGC002.PS1:68 char:76 
+ $saveFormatDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatDocument"); 
    + CategoryInfo   : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l 
oaded. 
At C:\users\x46332\Desktop\cgc\CGC002.PS1:69 char:76 
+ $saveFormatTxt = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatDOSText"); 
    + CategoryInfo   : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l 
oaded. 
At C:\users\x46332\Desktop\cgc\CGC002.PS1:70 char:76 
+ $saveFormatRTF = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatRTF"); 
    + CategoryInfo   : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

運行腳本轉換JUST到Word和文本工作正常。單獨運行RTF就好了。但是,每當我將RTF與其他輸出格式的腳本結合使用時,腳本中引用的所有輸出格式都會顯示爲「未找到」。 RTF是否需要自行導出?在一個腳本中可以有多少個輸出文件類型有限制(但它們都是獨立的函數)?有沒有一些參數我沒有設置?

我有verified that the member names輸出是正確的,我已經掃描MSDN尋找線索,但找不到任何會導致此行爲的東西,尤其是在向混音中添加RTF時出現不可預知的結果。有任何想法嗎?

+0

如果我啓動一個新的Powershell 2會話,執行'[System.Reflection.Assembly] :: LoadWithPartialName(「Microsoft.Office.Interop.Word」)',然後複製粘貼你的3行代碼,它作品。所有單獨的作品也是如此。對不起,無法以任何方式重現。對我來說,它使用'C:\ Windows \ assembly \ GAC_MSIL \ Microsoft.Office.Interop.Word \ 14.0.0.0__71e9bce111e9429c \ Microsoft.Office.Interop.Word.dll'。 – Joost 2013-03-29 12:17:54

回答

0

我做了一些進一步的測試,幾天後我能夠按預期轉換並沒有任何困難。我還測試了使用單個腳本轉換爲各種格式listed here ...除特殊字符上的一些時髦輸出格式外,一切都很順利。

所以,我猜測沒有限制,我的測試似乎證明了這一理論。

相關問題