First we create a new HTML file and write a fileupload and a button control.
The code is as follows:
Copy Code code as follows:
<input id= "flupload" type= "file"/>fileupload
<input id= "btnopenfile" type= "button" value= "button" onclick= "OpenFile" () "/>"
Then, write a JavaScript OpenFile method.
The code is as follows:
Copy Code code 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 select a Word document first, then click Open, you can successfully open the Word document.
is not very simple, seemingly can only be used in IE.