// Create an Application object Word.ApplicationClass ac = new Word.ApplicationClass(); Word.Application app = ac.Application;// I'm setting all of the alerts to be off as I am trying to get // this to print in the background app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;// Open the document to print... object filename = "myFile.rtf"; object missingValue = Type.Type.Missing;// Using OpenOld so as to be compatible with other versions of Word Word.Document document = app.Documents.OpenOld(ref filename, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);// Set the active printer app.ActivePrinter = "My Printer Name";object myTrue = true; // Print in background object myFalse = false;// Using PrintOutOld to be version independent m_App.ActiveDocument.PrintOutOld(ref myTrue, ref myFalse, ref missingValue, ref missingValue, ref missingValue, missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref myFalse, ref missingValue, ref missingValue, ref m_MissingValue);document.Close(ref missingValue, ref missingValue, ref missingValue);// Make sure all of the documents are gone from the queue while(m_App.BackgroundPrintingStatus > 0) { System.Threading.Thread.Sleep(250); }app.Quitref missingValue, ref missingValue, ref missingValue);
// Create an Application object
Word.ApplicationClass ac = new Word.ApplicationClass();
Word.Application app = ac.Application;// I'm setting all of the alerts to be off as I am trying to get
// this to print in the background
app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;// Open the document to print...
object filename = "myFile.rtf";
object missingValue = Type.Type.Missing;// Using OpenOld so as to be compatible with other versions of Word
Word.Document document = app.Documents.OpenOld(ref filename,
ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue, ref missingValue);// Set the active printer
app.ActivePrinter = "My Printer Name";object myTrue = true; // Print in background
object myFalse = false;// Using PrintOutOld to be version independent
m_App.ActiveDocument.PrintOutOld(ref myTrue,
ref myFalse, ref missingValue, ref missingValue, ref missingValue,
missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue, ref myFalse,
ref missingValue, ref missingValue, ref m_MissingValue);document.Close(ref missingValue, ref missingValue, ref missingValue);// Make sure all of the documents are gone from the queue
while(m_App.BackgroundPrintingStatus > 0)
{
System.Threading.Thread.Sleep(250);
}app.Quitref missingValue, ref missingValue, ref missingValue);
http://www.codeproject.com/KB/office/WordPrint.aspx
ThisDocument.PrintOut()
PrintOut 方法有多个可选参数,允许您微调打印文档的方式,下表概括了这些参数。参数 说明
Background 设置为 True 可允许在 Word 打印文档时继续处理。
Append 与 OutputFileName 参数一起使用。设置为 True 可将指定的文档名称追加到由 OutputFileName 参数指定的文件名后。设置为 False 将重写 OutputFileName 的内容。
Range 页面范围。可以为任何 WdPrintOutRange 枚举:wdPrintAllDocument、wdPrintCurrentPage、wdPrintFromTo、wdPrintRangeOfPages 或 wdPrintSelection。
OutputFileName 如果 PrintToFile 为 True,此参数指定输出文件的路径和文件名。
From Range 设置为 wdPrintFromTo 时的起始页码。
To Range 设置为 wdPrintFromTo 时的结束页码。
Item 要打印的项。可以是任何 WdPrintOutItem 枚举:wdPrintAutoTextEntries、wdPrintComments、wdPrintDocumentContent、wdPrintKeyAssignments、wdPrintProperties、wdPrintStyles。
Copies 要打印的份数。
Pages 要打印的页码和页码范围,由逗号分隔。例如,“2, 6-10”意为打印第 2 页和第 6、7、8、9、10 页。
PageType 要打印的页面的类型。可以是任何 WdPrintOutPages 常量:wdPrintAllPages、wdPrintEvenPagesOnly、wdPrintOddPagesOnly。
PrintToFile 设置为 True 可将打印机指令发送到文档。确保使用 OutputFileName 指定一个文件名。
Collate 打印一个文档的多个副本时使用此参数。设置为 True 则在打印下一个副本前将打印此文档的所有页面。
FileName 仅适用于 Application 对象。要打印的文档的路径和文件名。如果不用此参数,Word 将打印活动文档。
ManualDuplexPrint 设置为 True 可在打印机上没有双面打印装置的情况下打印双面文档。 常用的 PrintOut 参数。打印活动文档的第一页下面的过程打印活动文档的第一页:
// C#
internal void PrintOutDoc()
{
object myTrue = true;
object myFalse = false;
object missingValue = Type.Missing;
object range = Word.WdPrintOutRange.wdPrintCurrentPage;
object items = Word.WdPrintOutItem.wdPrintDocumentContent;
object copies = "1";
object pages = "1";
object pageType = Word.WdPrintOutPages.wdPrintAllPages; ThisDocument.PrintOut(ref myTrue, ref myFalse, ref range,
ref missingValue, ref missingValue, ref missingValue,
ref items, ref copies, ref pages, ref pageType, ref myFalse,
ref myTrue, ref missingValue, ref myFalse, ref missingValue,
ref missingValue, ref missingValue, ref missingValue);
}
这个是打印一个WORD的代码吗? 呵呵 要自己研究研究阿
那具体到我要打印C:/123.doc 该怎么来写阿?
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
Document doc = wordApp.Documents.Open(ref filename, ref oMiss, ref readOnly, ref oMiss, ref oMiss, ref oMiss, ref oMiss, ref oMiss,
ref oMiss, ref oMiss, ref oMiss, ref oMiss, ref oMiss, ref oMiss, ref oMiss, ref oMiss); doc.Activate();
doc.Application.PrintPreview = true;
doc.Application.ActiveDocument.PrintPreview();