WOrd ,excel实现打印功能
2012-04-11 09:03
513 查看
PrintDocument print = new PrintDocument();
string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
string s = "";
foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
{
s = sPrint;
}
return;
OpenFileDialog fileDialog = new OpenFileDialog();
//fileDialog.Title = "请选择文件";
//fileDialog.Filter = "excel03文件(*.xls)|*.xls";
//fileDialog.FilterIndex = 1;
//fileDialog.RestoreDirectory = true;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
#region excel
//Microsoft.Office.Interop.Excel.ApplicationClass xlsApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
//xlsApp.Visible = true;
//object oMissing = System.Reflection.Missing.Value;
//Microsoft.Office.Interop.Excel.Workbook xlsWorkbook = xlsApp.Workbooks.Open(fileDialog.FileName, 0, true, 5, oMissing, oMissing, true, 1, oMissing, false, false, oMissing, false, oMissing, oMissing);
//Microsoft.Office.Interop.Excel.Worksheet xlsWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlsWorkbook.Worksheets[1];
////xlsWorksheet.PrintPreview(null);
//xlsWorksheet.PrintOut(1, 2, 1, false, oMissing, true, false, oMissing);
//xlsApp.Visible = false;
//xlsWorksheet = null;
#endregion
#region word
object wordFile = fileDialog.FileName;
object oMissing = Missing.Value;
object copies = "1";
object oTrue = true;
object oFalse = false;
object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
appWord.Visible = false;
appWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
string defaultPrinter = appWord.ActivePrinter;
Microsoft.Office.Interop.Word.Document doc = appWord.Documents.Open(
ref wordFile ,
ref oMissing,
ref oTrue ,
ref oFalse ,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);
//弹出打印设置
//appWord.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref oMissing);
//appWord.Visible = false;
appWord.ActivePrinter = "hp3030 ";
doc.PrintOut(
ref oTrue,
ref oFalse,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref copies,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);
appWord.ActivePrinter = defaultPrinter;
doc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
appWord.Quit(ref oMissing, ref oMissing, ref oMissing);
doc = null;
appWord = null;
GC.Collect();
#endregion word
}
string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
string s = "";
foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
{
s = sPrint;
}
return;
OpenFileDialog fileDialog = new OpenFileDialog();
//fileDialog.Title = "请选择文件";
//fileDialog.Filter = "excel03文件(*.xls)|*.xls";
//fileDialog.FilterIndex = 1;
//fileDialog.RestoreDirectory = true;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
#region excel
//Microsoft.Office.Interop.Excel.ApplicationClass xlsApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
//xlsApp.Visible = true;
//object oMissing = System.Reflection.Missing.Value;
//Microsoft.Office.Interop.Excel.Workbook xlsWorkbook = xlsApp.Workbooks.Open(fileDialog.FileName, 0, true, 5, oMissing, oMissing, true, 1, oMissing, false, false, oMissing, false, oMissing, oMissing);
//Microsoft.Office.Interop.Excel.Worksheet xlsWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlsWorkbook.Worksheets[1];
////xlsWorksheet.PrintPreview(null);
//xlsWorksheet.PrintOut(1, 2, 1, false, oMissing, true, false, oMissing);
//xlsApp.Visible = false;
//xlsWorksheet = null;
#endregion
#region word
object wordFile = fileDialog.FileName;
object oMissing = Missing.Value;
object copies = "1";
object oTrue = true;
object oFalse = false;
object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
appWord.Visible = false;
appWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
string defaultPrinter = appWord.ActivePrinter;
Microsoft.Office.Interop.Word.Document doc = appWord.Documents.Open(
ref wordFile ,
ref oMissing,
ref oTrue ,
ref oFalse ,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);
//弹出打印设置
//appWord.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref oMissing);
//appWord.Visible = false;
appWord.ActivePrinter = "hp3030 ";
doc.PrintOut(
ref oTrue,
ref oFalse,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref copies,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);
appWord.ActivePrinter = defaultPrinter;
doc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
appWord.Quit(ref oMissing, ref oMissing, ref oMissing);
doc = null;
appWord = null;
GC.Collect();
#endregion word
}
相关文章推荐
- JavaScript实现打印页面表报,表单输出到word和excel功能
- Ubuntu 服务器 PHP实现word、excel、ppt、pdf 等文档在线阅读功能的实现
- 使用jsp实现word、excel格式报表打印
- 12、借助Jacob实现Java打印报表(Excel、Word)
- 使用jsp实现word、excel格式报表打印
- ASP网站远程客户实现EXCEL打印功能
- 使用JSP实现WORD、EXCEL格式报表打印
- .net 实现word、excel、ppt、pdf预览功能
- ASP网站远程客户实现EXCEL打印功能
- JS利用ActiveX控件的方式,即 Excel.Application,实现对word或者excel的打印
- 使用jsp实现word、excel格式报表打印
- 水晶报表导出为pdf, word , excel 格式(已经测试过,实现了该功能)
- JS+调用word打印功能实现在Webfrom客户端
- jacob打印word(.doc)或者excel(.xls) 【java实现】
- C#前期绑定和后期绑定操作Excel-------实现简单打印功能
- C#前期绑定和后期绑定操作Excel-------实现简单打印功能
- JSP页面实现图片、PDF字节流的显示,Word、Excel、Zip字节流的下载功能的实现
- c#实现Word联接Excel的MailMerge功能
- jsp实现针对excel及word文档的打印方法
- 报表导出到word或者excel的功能实现