First, create an html file and write a FileUpLoad and button control.
The Code is as follows:
Copy codeThe Code is 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 codeThe 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, you can select a Word document in IE and click open to open the Word document.
Is it very simple? It seems that it can only be used in IE.