我以前一直用VB,最近在学C#。在VB中可以利用word对象进行合同的打印。不只在C#中该如何处理打印问题?我看C#中也可以引用word对象,但不知该如何实现调用word对象进行打印?
我是新手,有些东西还不是很明白,如果有问错的地方,大家别见笑!希望可以得到你们的帮助指点!多谢了!!!

解决方案 »

  1.   

    这是一个打开Word的方法,打印的话,Word.Document对象有PrintOut()方法,
    基本把VB的代码改改就能用using Word;    Word.Application wdApp = null;
        static object missing = Missing.Value;    private Word.Document OpenFile(string filePath)
        {      Word.Document wdDoc = null;      object  fileName              = filePath;
          object  confirmConversions    = missing;
          object  readOnly              = true;
          object  addToRecentFiles      = missing;
          object  passwordDocument      = missing;
          object  passwordTemplate      = missing;
          object  revert                = missing;
          object  writePasswordDocument = missing;
          object  writePasswordTemplate = missing;
          object  format                = missing;
          object  encoding              = missing;
          object  visible               = false;
          object  openAndRepair         = missing;
          object  documentDirection     = missing;
          object  noEncodingDialog      = missing;      wdDoc = wdApp.Documents.Open(
            ref fileName              ,
            ref confirmConversions    ,
            ref readOnly              ,
            ref addToRecentFiles      ,
            ref passwordDocument      ,
            ref passwordTemplate      ,
            ref revert                ,
            ref writePasswordDocument ,
            ref writePasswordTemplate ,
            ref format                ,
            ref encoding              ,
            ref visible               ,
            ref openAndRepair         ,
            ref documentDirection     ,
            ref noEncodingDialog  );      wdDoc.Activate();
          
          return wdDoc;
        }
      

  2.   

    Word.Application wordApplication = new Word.Application();
    Word.Document thisDocument = new Word.Document();
    object missingValue = Type.Missing; 
    object myTrue = true;
    object fileName = "\\TestFile1.rtf";
    wordApplication.Visible = true; thisDocument = wordApplication.Documents.Open(ref fileName, ref missingValue,
    ref myTrue, ref missingValue, ref missingValue, ref missingValue,
    ref missingValue, ref missingValue, ref missingValue,
    ref missingValue, ref missingValue, ref missingValue,
    ref missingValue, ref missingValue, ref missingValue);
    Object background = Type.Missing;
    Object append = Type.Missing;
    Object range = Type.Missing;
    Object outputFileName = Type.Missing;
    Object from = Type.Missing;
    Object to = Type.Missing;
    Object item = Type.Missing;
    Object copies = Type.Missing;
    Object pages = Type.Missing;
    Object pageType = Type.Missing;
    Object printToFile = Type.Missing;
    Object collate = Type.Missing;
    Object fileName = Type.Missing;
    Object activePrinterMacGX = Type.Missing;
    Object manualDuplexPrint = Type.Missing;
    Object printZoomColumn = Type.Missing;
    Object printZoomRow = Type.Missing;
    Object printZoomPaperWidth = Type.Missing;
    Object printZoomPaperHeight = Type.Missing;ThisDocument.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 fileName, ref activePrinterMacGX, 
        ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow, 
        ref printZoomPaperWidth, ref printZoomPaperHeight);