JS打开word文档的代码
Admin | 2015-3-19 8:54:33 | 被阅次数 | 5107
第一步:在页面中放这两个控件
<input id="flUpload" type="file" />flUpload
<input id="btnOpenFile" type="button" value="button" onclick="OpenFile()" />
第二步:在页面中放如下代码
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("flUpload").value);
}
else
{
alert("Please select Word/Excel file only");
return false;
}
}