js调用excel、word打印

js调用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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值