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

How to open word document with javascript_basic knowledge

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:52:06
Original
1813 people have browsed it

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.

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template