public void Print(object fileName)
{
try
{
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
{
p.Kill();
}
this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Object missing = System.Reflection.Missing.Value;
object redOlny = false ;
this._wordDocument = this._wordApplication.Documents.Open(ref fileName, ref missing, ref redOlny, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
//------------------------使用Printout方法进行打印------------------------------
object background = false; //这个很重要,否则关闭的时候会提示请等待Word打印完毕后再退出,加上这个后可以使Word所有
_wordDocument.PrintOut(ref background, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing);
object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
this._wordDocument.Close(ref saveOption, ref missing, ref missing); //关闭当前文档,如果有多个模版文件进行操作,则执行完这一步后接着执行打开Word文档的方法即可
saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
this._wordApplication.Quit(ref saveOption, ref missing, ref missing); //关闭Word进程
}
catch (Exception ex)
{
MessageBox.Show("没安装打印机或者打印机出故障");
}
}
public void PrintViewWord(object fileNmae)
{
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
{
p.Kill();
}
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
object Missing = System.Reflection.Missing.Value;
object readOnly = false;
Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(ref fileNmae, ref Missing, ref readOnly, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);
wordApp.Visible = true;
wordDoc.PrintPreview();
}