複製代碼 代碼如下:/*
給幾個js寫word的參考:
this.Word.Selection.Font.Size = 16; //字型大小
this.Word.Selection.Font.Bold = true; //是否加粗
this.Word.Selection.ParagraphFormat.Alignment = 2; //0靠左對齊,1置中,2靠右對齊,數字只能0-9,慢慢試吧
this.Word.Selection.InsertRowsBelow(1); //下面加入一行
this.Word.Selection.MoveRight(1); //游標右移
this.Word.Selection.TypeText(string); //只能寫string
this.Word.Selection.MoveDown(); //游標下移
this.Word.Selection.EndKey(); //游標移動到末尾
this.Word.ActiveDocument.Sections(1).Headers(1).Range.InsertAfter(string); //寫頁首,結尾處寫
this._LoadData = function () {
//替換函數,用於替換$strFld$類型的文本
function replace( Range, strFld ) {
//[FindText], [MatchCase], [MatchWholeWord], [MatchWildcards], [MatchSoundsLike], [MatchAllWordForms], [Forward], [Wrap], [Format], [ReplaceWith], [Replace], [MatchKashida], [MatchDiacritics], [MatchAlefHamza], [MatchControl]
Range.Find.Execute( "$"+strFld+"$", true, false, false, false, false, true, wdFindContinue, false, getElValue("l"+strFld) )
}
//初始化Word控制項
this._InitWord = function ()
{
try{
this.Word = new ActiveXObject("Word.Application");
this.Word.visible = true;
this.Doc = this.Word.Documents.Open( this.TemplatePath );
this.Doc.Activate();
this.Range = this.Doc.Range();
return true
} catch(e) {
//TODO: 如果使用者手動取消ActiveX的運行,則會留一WINWORD.EXE的進程。
//除非"設為可信網站,並在自訂層級裡將第二項啟用",則不會出現啟用ActiveX的對話方塊。
try {
if ( this.Doc ) { this.Doc.Close(0) };
if ( this.Word ) { this.Word.Quit() }
}
catch (e){}
return false
}
}
*/