我想使用JavaScript(在網頁上)來插入一些文本到Microsoft Word文檔中插入文本。 The Documentation具有用於VB和C#代碼示例,但還沒有爲JavaScript(JScript中)。我已經能夠找出使用代碼樣本as seen here很多,但一定行搞亂了我。Microsoft Word中 - 從JavaScript/JScript中的ActiveX
以下是我到目前爲止:
var retText;
var wshShell = new ActiveXObject("WScript.Shell");
var wordApp = new ActiveXObject("Word.Application");
wordApp.Documents.Add();
if (wordApp.Application.Options.Overtype) {
wordApp.Options.Overtype = false;
}
但是,當涉及到這條線(在C#),我不能完全得到如何翻譯它:
if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP)
currentSelection.Type
可以在我上面的代碼被翻譯爲wordApp.Selection.Type
,但我不知道該怎麼辦Word.WdSelectionType.wdSelectionIP
。
一些失敗的嘗試:
alert(wordApp.WdSelectionType); //undefined
alert(new ActiveXObject("Word.WdSelectionType"); //errors out
alert(wordApp.ActiveDocument.WdSelectionType); //undefined
出於安全原因,你不能這樣做。 – SLaks 2011-06-14 01:50:53
@SLak我們的Intranet上的安全性被降低了;我們已經有一些基於Word.Basic API的文本插入代碼,但是我認爲我需要一些不能用於那個的功能。還是有關於WdSelectionType的東西的單獨的安全角色? – jtpereyda 2011-06-14 14:25:24