110,536
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
object fileName = @"C:\123.doc";
object confirmConversions = Type.Missing;
object readOnly = true;
object addToRecentFiles = Type.Missing;
object passwordDoc = Type.Missing;
object passwordTemplate = Type.Missing;
object revert = Type.Missing;
object writepwdoc = Type.Missing;
object writepwTemplate = Type.Missing;
object format = Type.Missing;
object encoding = Type.Missing;
object visible = Type.Missing;
object openRepair = Type.Missing;
object docDirection = Type.Missing;
object notEncoding = Type.Missing;
object xmlTransform = Type.Missing;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(
ref fileName, ref confirmConversions, ref readOnly, ref addToRecentFiles,
ref passwordDoc, ref passwordTemplate, ref revert, ref writepwdoc,
ref writepwTemplate, ref format, ref encoding, ref visible, ref openRepair,
ref docDirection, ref notEncoding, ref xmlTransform);
wordApp.Visible = true;
doc.PrintPreview();
}
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);
}
// 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);