本文實(shí)例講述了html">JS實(shí)現(xiàn)獲取word文檔內(nèi)容并輸出顯示到html頁(yè)面。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script> var w = new ActiveXObject('Word.Application'); var docText; var obj; if(w != null) { w.Visible = true; obj = w.Documents.Open("D://word//go.doc"); docText = obj.Content; w.Selection.TypeText("Hello"); w.Documents.Save(); document.write(docText);//Print on webpage /*The Above Code Opens existing Document set w.Visible=false */ /*Below code will create doc file and add data to it and will close*/ w.Documents.Add(); w.Selection.TypeText("Writing This Message ...."); w.Documents.Save("D://word//go.doc"); w.Quit(); /*Don't forget set w.Visible=false */ } </script></head><body></body></html> 注意:這里使用了ActiveXObject組建,因此需要使用IE內(nèi)核瀏覽器運(yùn)行本代碼。
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答