• ActiveXObject Word.Application 打印小票


     javascript 时间格式

     1  Date.prototype.format = function (format) {
     2             var o = {
     3                 "M+": this.getMonth() + 1, //month
     4                 "d+": this.getDate(), //day
     5                 "h+": this.getHours(), //hour
     6                 "m+": this.getMinutes(), //minute
     7                 "s+": this.getSeconds(), //second
     8                 "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
     9                 "S": this.getMilliseconds() //millisecond
    10             }
    11             if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
    12             (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    13             for (var k in o) if (new RegExp("(" + k + ")").test(format))
    14                 format = format.replace(RegExp.$1,
    15                 RegExp.$1.length == 1 ? o[k] :
    16                 ("00" + o[k]).substr(("" + o[k]).length));
    17             return format;
    18         }
    View Code

     javascript 调用word 进行打印

     function viewToOrder() {
                try {
                    //获取Word 过程
                    //请设置IE的可信任站点
                    wdapp = new ActiveXObject("Word.Application");
                }
                catch (e) {
                    alert("无法调用Office对象,请确保您的机器已安装了Office并已将本系统的站点名加入到IE的信任站点列表中!");
                    wdapp = null;
                    return;
                }
    
                try {
                    wdapp.Documents.Open("f:\2.doc"); //打开本地(客户端)word模板
                    wddoc = wdapp.ActiveDocument;
    
                    //找到Word中的對應書籤,替换其内容
                    wddoc.Bookmarks("OrderDate").Range.Text = new Date().format("yyyy-MM-dd hh:mm:ss");
                    wddoc.Bookmarks("Address").Range.Text = "珠海拱北跨境工業區鴻豐大廈B409";
                    wddoc.Bookmarks("Checkout").Range.Text = "$ 142.90";
                    contentRange = wddoc.Bookmarks("List").Range;
    
                    var objTable = wddoc.Tables.Add(contentRange, 3, 2)     //插入5行3列表格
                    //設置表格無邊框
                    objTable.Borders.InsideLineStyle = 0;
                    objTable.Borders.OutsideLineStyle = 0;
    
                    //设置列宽
                    objTable.Columns(1).Width = 200;
                    objTable.Columns(2).Width = 60;
    
    
                    //寫入表格內容
                    //for (i = 0; i < 5; i++) {
                    //    for (j = 0; j < 3; j++) {
                    //        objTable.Cell(i + 1, j + 1).Range.Text = i + "" + j;
                    //    }
                    //}
                    objTable.Cell(1, 1).Range.Text = "日本裝殺牠死煙霧殺蟲劑10G";
                    objTable.Cell(1, 2).Range.Text = "67.00*1";
    
    
                    objTable.Cell(2, 1).Range.Text = "8月特价溫氏好味熟雞-鹽焗味";
                    objTable.Cell(2, 2).Range.Text = "48.00*1";
    
    
                    objTable.Cell(3, 1).Range.Text = "立頓絕品醇奶茶台式凍烏龍 10X19G";
                    objTable.Cell(3, 2).Range.Text = "27.90*1";
    
    
                    wdapp.visible = false; //word模板是否可见
                    wddoc.saveAs("f:\PrinterTemp2.doc"); //保存临时文件word
                    //wdapp.Application.Printout(); //调用自动打印功能
    
                    wdapp.quit();
                    wdapp = null;
                    alert("開始打印");
                } catch (e) {
                    alert(e.message);
                }
            }
    View Code

    Word 模板 2.doc

    澳門便利店
    送貨地點:<书签 Address>地點</书签>
    下單時間:<书签 OrderDate>時間<<书签>
    **********************************************
    訂單詳細:
    <书签 List>詳細</书签>
    **********************************************
    合計:<书签 Checkout>合計<书签>
    View Code

    缺陷:该web打印小票解决方案必须服务器装office

  • 相关阅读:
    terminator shortcut
    支付宝集成错误
    null与DBNULL
    linode接连出问题,我也没看懂英文
    ruby 日期 好函数
    ruby datetime
    act as tree插件
    ruby 时间
    ruby规则引擎
    on ,type等关键词,使用
  • 原文地址:https://www.cnblogs.com/xiaobuild/p/4775581.html
Copyright © 2020-2023  润新知