又碰上一个一模一样的问题,这次是一句话的:
scriptString += "myWord.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyRevisions, NoReset:==False, Password:=='1234');"
各位快来救火啊...........
scriptString += "myWord.Application.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyRevisions, NoReset:==False, Password:=='1234');"
各位快来救火啊...........
scriptString += "FileName:='SB.doc',FileFormat:=wdFormatDocument,LockComments:=False,Password:='',AddToRecentFiles:=True,WritePassword:='',ReadOnlyRecommended:=False,EmbedTrueTypeFonts:=False,SaveNativePictureFormat:=False,SaveFormsData:=False,SaveAsAOCELetter:=False"
scriptString += "\");"
这句话是要看看到底有没有漏了")",是吗?可是当网页载入时就已经提示"缺少')'" 了,所以这句话应该没有实现的机会吧。To 秋水兄:
没有看漏的话,秋水兄是在第1、3句分别加上了 \" ,可是这样一来第3句的语法就出错了,因为三个" ,程序判别不到哪个是结束点。而加在第一句,程序会自动增加一个 " ,变成 \""" 还要麻烦一下两位和众多JS高手了。
myWord.Application.ActiveDocument.SaveAs(FileName:='SB.doc',FileFormat:=wdFormatDocument,LockComments:=False,Password:='',AddToRecentFiles:=True,WritePassword:='',ReadOnlyRecommended:=False,EmbedTrueTypeFonts:=False,SaveNativePictureFormat:=False,SaveFormsData:=False,SaveAsAOCELetter:=False);
可以看到,没有缺少 ) 啊。我猜可能是字符串的相加不妥当引起了歧义,导致程序不能识别,但是具体怎么操作我又不知道。所以还是要各位JS的高手帮帮忙啦!
[id(0x00000066), helpcontext(0x096b0066)]
HRESULT SaveAs(
[in, optional] VARIANT* FileName,
[in, optional] VARIANT* FileFormat,
[in, optional] VARIANT* LockComments,
[in, optional] VARIANT* Password,
[in, optional] VARIANT* AddToRecentFiles,
[in, optional] VARIANT* WritePassword,
[in, optional] VARIANT* ReadOnlyRecommended,
[in, optional] VARIANT* EmbedTrueTypeFonts,
[in, optional] VARIANT* SaveNativePictureFormat,
[in, optional] VARIANT* SaveFormsData,
[in, optional] VARIANT* SaveAsAOCELetter);
搞不懂 你的FiName:=的写法是什么意思,直接传字符串就行了。
请看:
<body>
<button onclick="newdoc()">new doc</button>
<script language="JavaScript">
var doc=null;
function newdoc(){
doc=new ActiveXObject("Word.Document");
alert(doc.Name);
doc.SaveAs("abc.doc");
}
</script>
</body>
测试通过。
谢谢你的建议!现在可以通过了,但是只有一个FileName的部分。如果还包括其他参数,如PASSWORD,应该怎么写在一起呢?就是说,在saveAs()里面应该怎么写呢?我写的是按照VBA的格式 :p
要按顺序传值。
VBA的写法实际执行时其内部也要转换成标准的COM调用格式。
刚才试了一下,连续写出 saveAs("SB.doc",wdFormatDocument) ,但是程序说wdFormatDocument未定义。如何解决呢?
<button onclick="newdoc()">new doc</button>
<!--
[id(0x00000066), helpcontext(0x096b0066)]
HRESULT SaveAs(
[in, optional] VARIANT* FileName,
[in, optional] VARIANT* FileFormat,
[in, optional] VARIANT* LockComments,
[in, optional] VARIANT* Password,
[in, optional] VARIANT* AddToRecentFiles,
[in, optional] VARIANT* WritePassword,
[in, optional] VARIANT* ReadOnlyRecommended,
[in, optional] VARIANT* EmbedTrueTypeFonts,
[in, optional] VARIANT* SaveNativePictureFormat,
[in, optional] VARIANT* SaveFormsData,
[in, optional] VARIANT* SaveAsAOCELetter);-->
<script language="JavaScript">
<!--
var app=null;
var doc=null;
function newdoc(){
//app= new ActiveXObject("Word.Application");
doc=new ActiveXObject("Word.Document");
alert(doc.Name);
FileName="abc.doc";
FileFormat=0;
LockComments=false;
Password="12345";
AddToRecentFiles=true;
WritePassword=true ;
ReadOnlyRecommended=false;
//EmbedTrueTypeFonts,
//SaveNativePictureFormat,
//SaveFormsData,
//SaveAsAOCELetter doc.SaveAs(FileName,FileFormat,LockComments,Password,AddToRecentFiles);
}
//-->
</script>
wdFormatDocument = 0,
wdFormatTemplate = 1,
wdFormatText = 2,
wdFormatTextLineBreaks = 3,
wdFormatDOSText = 4,
wdFormatDOSTextLineBreaks = 5,
wdFormatRTF = 6,
wdFormatUnicodeText = 7,
wdFormatEncodedText = 7,
wdFormatHTML = 8
} WdSaveFormat;
以上为WdSaveFormat的常量定义