Asp.Net调用打印机

我们先引用Microsoft.Office.Interop.Word,

 

 

object fileNames = HttpContext.Current.Request.MapPath("..") + @"\images\ApplyReport1.dot";
            object saveFileName = HttpContext.Current.Request.MapPath("..") + @"\images\ApplyReport1.doc";
            Word.ApplicationClass oWordApp = new Word.ApplicationClass();          
            object readOnly = false;
            object isVisible = true;
            object missing = System.Reflection.Missing.Value;
            object oTemplate = "D:\\BankrollApplyReport1.dot";         

            Word.Document oWordDoc = oWordApp.Documents.Add(ref oTemplate, ref readOnly, ref readOnly, ref isVisible);
            oWordDoc.Activate();

            object oBookMark = "";
            oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "3333";
            oBookMark = "ApplyUnitName";
            oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "开发单位";
        Dictionary<string,string> ReportDic=new Dictionary<string,string>();
        ReportDic.Add("BarCode","20200202");
        ReportDic.Add("ApplyUnitName","开发单位");
        SetBookMark(ref oWordDoc,ReportDic);
            Object background = true;

            Object append = Type.Missing;

            Object range = Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument;

            Object outputFileName = Type.Missing;

            Object from = Type.Missing;

            Object to = Type.Missing;

            Object item = Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;

            Object copies= 1;

            Object pages = "";

            Object pageType = Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages;

            Object printToFile = false;

            Object collate = true;

            Object fileName = "";

            Object activePrinterMacGX = Type.Missing;

            Object manualDuplexPrint = false;

            Object printZoomColumn = 0;

            Object printZoomRow = 0;

            Object printZoomPaperWidth = 0;

            Object printZoomPaperHeight = 0;

            //oWordDoc.Application.ActivePrinter = \\\\Jupitor\\HP550 on Ne03:;

            oWordDoc.PrintOut(ref background, ref append,

            ref range, ref outputFileName, ref from, ref to,

            ref item, ref copies, ref pages, ref pageType,

            ref printToFile, ref collate, ref activePrinterMacGX,

            ref manualDuplexPrint, ref printZoomColumn,

            ref printZoomRow, ref printZoomPaperWidth, ref printZoomPaperHeight);

 

因为模板书签定义好了,我们需要赋值,采用字典循环

  protected void SetBookMark(ref  Word.Document oWordDoc, Dictionary<string, string> dicField)
    {
        foreach (var dic in dicField)
        {
            object bookMark = (object)dic.Key;
            if (oWordDoc.Bookmarks.get_Item(ref bookMark) != null)
            {
                oWordDoc.Bookmarks.get_Item(ref bookMark).Range.Text = dic.Value;
            }
        }
    }

 

转载于:https://www.cnblogs.com/skyado/archive/2010/09/10/1823490.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值