js调用excel、word打印
excel
word
测试查询
<script type="text/javascript">
printExcel('d:/800031.xls');
function printExcel(obj)
{
var xlsApp = null;
try{
xlsApp = new ActiveXObject('Excel.Application'); }catch(e)
{
alert(e+', 原因分析: 浏览器安全级别较高导致不能创建Excel对象或者客户端没有安装Excel软件');
return;
}
//var xlBook = xlsApp.Workbooks.Open('http://'+window.location.host+obj.value);
var xlBook = xlsApp.Workbooks.Open(obj);
var xlsheet = xlBook.Worksheets(1);
xlsApp.Application.Visible = false;
xlsApp.visible = false;
xlsheet.Printout;
xlsApp.Quit();
xlsApp=null;
}
</script>
excel
function openExcel(obj)
{
// var xlsApp = null;
//try{
// xlsApp = new ActiveXObject('Excel.Application'); }catch(e)
//{
// alert(e+', 原因分析: 浏览器安全级别较高导致不能创建Excel对象或者客户端没有安装Excel软件');
// return;
// }
//var s='http://'+window.location.host+obj.replace(/(file:\/\/)/g,'/report/');
//var xlBook = xlsApp.Workbooks.Open(s);
//xlsApp.Application.Visible = true;
//xlsApp.visible = true;
var s=obj.replace(/(file:\/\/)/g,'/report/');
window.showModalDialog('/ocx/attachshow.jsp?xlsName='+s,'报表预览','dialogWidth=1024px;dialogHeight=800px;status=no;help=no;scroll=no;location=no');
}
function printExcels(obj)
{
var xlsApp = null;
try{
xlsApp = new ActiveXObject('Excel.Application'); }catch(e)
{
alert(e+', 原因分析: 浏览器安全级别较高导致不能创建Excel对象或者客户端没有安装Excel软件');
return;
}
var s='http://'+window.location.host+obj.replace(/(file:\/\/)/g,'/report/');
var ss = s.split("/");
if(!(setFlag(ss[ss.length-2])))
return;
var xlBook = xlsApp.Workbooks.Open(s);
//var xlsheet;
try{
//for(printSheetLen=1;printSheetLen<=xlBook.Sheets.Count;printSheetLen++){
// xlsheet = xlBook.Worksheets(printSheetLen);
// xlsApp.Application.Visible = false;
// xlsApp.visible = false;
// xlsheet.Printout;
//}
xlBook.Printout;
}
catch(e){
alert(e);
}
finally{
xlsApp.Quit();
xlsApp=null;
// clearPrintFlag();
}
}
word
function printWord(obj)
{
var wordApp = null;
try{
wordApp = new ActiveXObject('Word.Application'); }catch(e)
{
alert(e+', 原因分析: 浏览器安全级别较高导致不能创建Word对象或者客户端没有安装Word软件');
return;
}
var Doc=wordApp.Documents.Open('http://'+window.location.host+obj.value);
wordApp.Application.Visible = false;
wordApp.visible = false;
wordApp.ActiveDocument.printout();
wordApp.ActiveDocument.close();
wordApp.Quit();
wordApp=null;
}
测试查询
<script type="text/javascript">
printWord('d:/test.doc');
function printWord(obj)
{
var wordApp = null;
try{
wordApp = new ActiveXObject('Word.Application'); }catch(e)
{
alert(e+', 原因分析: 浏览器安全级别较高导致不能创建Word对象或者客户端没有安装Word软件');
return;
}
//var Doc=wordApp.Documents.Open('http://'+window.location.host+obj.value);
var Doc=wordApp.Documents.Open(obj);
wordApp.Application.Visible = false;
wordApp.visible = false;
wordApp.ActiveDocument.printout();
wordApp.ActiveDocument.close();
wordApp.Quit();
wordApp=null;
}
</script>