Home >Web Front-end >JS Tutorial >How to open word document with javascript_basic knowledge

How to open word document with javascript_basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:52:061758browse

First we create a new html file and write a FileUpLoad and button control.

The code is as follows:

Copy codeThe code is as follows:

fileUpload

Then, write a javascript OpenFile method.

The code is as follows:

Copy code The code is as follows:

function OpenFile()
{
if (document.getElementById("flUpload").value.toUpperCase().indexOf(".XLS") != -1)
{
var objExcel;
objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = true;
objExcel.Workbooks.Open(document.getElementById("flUpload").value);
}
else if (document .getElementById("flUpload").value.toUpperCase().indexOf(".DOC") != -1)
{
var objDoc;
objDoc = new ActiveXObject("Word.Application") ;
objDoc.Visible = true;
objDoc.Documents.Open(document.getElementById("fileUpload").value);
}
else
{
alert("Please select Word/Excel file only");
return false;
}
}

OK. Then in IE, you can first select a word document, then click open, and the word document can be opened successfully.
Isn’t it very simple? It seems that it can only be used in IE.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn