<input type="button" value="toPrinter " onclick="viewToWord();" />
- Hide code
function viewToWord() {
//当前时间
var Time;
var today = new Date();
Time = today.toLocaleString();
try {
// 创建ActiveXObject对象
wdapp = new ActiveXObject("Word.Application");
}
catch (e) {
console.log("无法调用Office对象,!", e)
wdapp = null;
return;
}
wdapp.Documents.Open("f:\\PrinterTemplate1.doc"); //打开本地(客户端)word模板
wddoc = wdapp.ActiveDocument;
wddoc.Bookmarks("OrderNum").Range.Text = "201509080959" + "\n";
wddoc.Bookmarks("OrderName").Range.Text = "郑斌" + "\n";
wddoc.Bookmarks("OrderAddress").Range.Text = "www.cnblogs.com/zhengbin" + "\n";
wddoc.Bookmarks("OrderPhoneNum").Range.Text = "QQ:1746788394" + "\n";
wddoc.Bookmarks("OrderDaocanTime").Range.Text = "10:00-11:00" + "\n";
wddoc.Bookmarks("OrderTime").Range.Text = "09-08 10:15";
//添加表格
var myTable = wddoc.Tables.Add (wddoc.Bookmarks("OrderCart").Range,3,3);//(赋值区域,行数,列数)
//隐藏边框
var table=wdapp.ActiveDocument.Tables(1);
table.Borders(-1).LineStyle=0;
table.Borders(-2).LineStyle=0;
table.Borders(-3).LineStyle=0;
table.Borders(-4).LineStyle=0;
table.Borders(-5).LineStyle=0;
table.Borders(-6).LineStyle=0;
for(i=1;i<=3;i++){//行
//第一列
with (myTable.Cell(i,1).Range){
font.Size = 8;//调整字体大小
InsertAfter("博客园"+i);//插入的内容
}
//第二列
with(myTable.Cell(i,2).Range){
font.Size = 8;
InsertAfter(i);
ParagraphFormat.Alignment=1;//表格内容对齐:0-左对齐 1-居中 2-右对齐
}
//第三列
with(myTable.Cell(i,3).Range){
font.Size = 8;
InsertAfter("无价");
ParagraphFormat.Alignment=2;
}
}
wddoc.saveAs("f:\\PrinterTemp_cnblogs.doc"); //保存临时文件word
wddoc.Bookmarks("TotalPrice").Range.Text = "无价" + "\n";
wddoc.Bookmarks("Time").Range.Text = Time;
//wdapp.ActiveDocument.ActiveWindow.View.Type = 1;
wdapp.visible = false; //word模板是否可见
wdapp.Application.Printout(); //调用自动打印功能
wdapp.quit();
wdapp = null;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有