winform实现可编辑模板打印 我现在从Excel中读取所有客户数据,然后打印成信封,数据读出来了,可不知道怎么打印。因为不知道这个打印模板做,可以随时更改打印模板!我想过用word来做打印模板,可不知道如何实现!请高手指点,如还有其他方法,都提出来吧!谢谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通过Printdocument显示模板绑定数据,并打印 我晕,这个问题可以直接用word邮件合并功能实现,我给同事打请帖就这样子 //用word替换的功能可以实现打印模板的功能 //先将模板复制到另外的文件夹,然后替换打印. object oMissing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = false; object fileName = "文件路径"; oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); object FindText, ReplaceWith, Replace; Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll; FindText = "old";//要查找的文本 ReplaceWith = "new";//替换文本 oWord.Selection.Find.Execute(ref FindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref ReplaceWith, ref Replace, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.Save(); oDoc.PrintOut(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); if (oDoc != null) oDoc.Close(ref oMissing, ref oMissing, ref oMissing); if (oWord != null) oWord.Quit(ref oMissing, ref oMissing, ref oMissing); 8楼的方法可以,但现在如何实现打印预览和打印呢?以下是打印预览的方法,可是如何和word绑定啊? protected virtual void ShowPrintPreviewDialog(PrintDocument printDocument) { if (printDocument == null) { throw new Exception("关联的打印文档不能为空!"); } try { //申明并实例化PrintPreviewDialog PrintPreviewDialog ppDlg = new PrintPreviewDialog(); //指定打印文档 ppDlg.Document = printDocument; //显示对话框 DialogResult result = ppDlg.ShowDialog(); if (result == DialogResult.OK) { //... } } catch (System.Drawing.Printing.InvalidPrinterException e) { MessageBox.Show("未安装打印机,请进入系统控制面版添加打印机!", "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } //word里面就有打印预览的功能 object oMissing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = true; object fileName = "文件路径"; oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.PrintPreview(); //注意这个 oWord.Visible = true; //不要下面的 if (oDoc != null) oDoc.Close(ref oMissing, ref oMissing, ref oMissing); if (oWord != null) oWord.Quit(ref oMissing, ref oMissing, ref oMissing); oDoc.PrintOut(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);为什么会弹出保存为 tiff文件的对话框? oDoc.PrintOut调用打印的方法了? 打印和预览分两个不同的按钮事件写.==============================保存为 tiff文件的对话框:是你装的虚拟打印机打印文件 必须先保存成tiff文件,再将tiff文件打印出来? 分开写,怎么写啊,打印word文档,网上不多,有很多都不行 两个按钮,一个打印的,写8楼的回复.一个打印预览的,写10楼的回复.============================================ //如果打印预览时,文档是没替换的,那就加上下面的代码 object FindText, ReplaceWith, Replace; Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll; FindText = "old";//要查找的文本 ReplaceWith = "new";//替换文本 oWord.Selection.Find.Execute(ref FindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref ReplaceWith, ref Replace, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.Save(); 哎,才发现,问题出在没搜索到打印机上。给个判断有没有打印机的代码我的判断不对:string strdefaultprinter = printDocument1.PrinterSettings.PrinterName;//获取默认的打印机名 if (strdefaultprinter == null || strdefaultprinter == "") { MessageBox.Show("未安装打印机,请进入系统控制面版添加打印机!", "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } foreach (string strprinter in PrinterSettings.InstalledPrinters) //在列表框中列出所有的打印机, { if (strprinter == null||strprinter =="")//把默认打印机设为缺省值 { MessageBox.Show("未安装打印机,请进入系统控制面版添加打印机!", "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } strdefaultprinter = strprinter; break; } 各位比较牛的兄弟 进来看看吧 字符串查找 求C# winform项目源码 新手问题??!! 求教ADO.NET的一个简单问题 急:c# 和java 的socket间的通信问题 c#开发webform焦点时离开Textbox1所对应的事件是什么 大家帮忙呀,不是我小气 如何得到一个url的绝对路径(说明是C#应用程序。不是web) 简单的ADO.NET问题 我的VS2008,怎么项目模板里没有"ADO.NET Entity Data Model"? GridView.Rows[0].Cells[1].Text,取不到自动增长列的值
//用word替换的功能可以实现打印模板的功能
//先将模板复制到另外的文件夹,然后替换打印.
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
object fileName = "文件路径";
oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); object FindText, ReplaceWith, Replace;
Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll; FindText = "old";//要查找的文本
ReplaceWith = "new";//替换文本
oWord.Selection.Find.Execute(ref FindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref ReplaceWith, ref Replace, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.Save();
oDoc.PrintOut(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); if (oDoc != null)
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
if (oWord != null)
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
以下是打印预览的方法,可是如何和word绑定啊? protected virtual void ShowPrintPreviewDialog(PrintDocument printDocument)
{
if (printDocument == null)
{
throw new Exception("关联的打印文档不能为空!");
} try
{
//申明并实例化PrintPreviewDialog
PrintPreviewDialog ppDlg = new PrintPreviewDialog(); //指定打印文档
ppDlg.Document = printDocument;
//显示对话框
DialogResult result = ppDlg.ShowDialog();
if (result == DialogResult.OK)
{
//...
} }
catch (System.Drawing.Printing.InvalidPrinterException e)
{
MessageBox.Show("未安装打印机,请进入系统控制面版添加打印机!", "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
//word里面就有打印预览的功能
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
object fileName = "文件路径";
oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.PrintPreview();
//注意这个
oWord.Visible = true; //不要下面的
if (oDoc != null)
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
if (oWord != null)
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
oDoc.PrintOut(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);为什么会弹出保存为 tiff文件的对话框?
调用打印的方法了?
==============================
保存为 tiff文件的对话框:是你装的虚拟打印机打印文件
一个打印预览的,写10楼的回复.
============================================ //如果打印预览时,文档是没替换的,那就加上下面的代码
object FindText, ReplaceWith, Replace;
Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll; FindText = "old";//要查找的文本
ReplaceWith = "new";//替换文本
oWord.Selection.Find.Execute(ref FindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref ReplaceWith, ref Replace, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.Save();
给个判断有没有打印机的代码
我的判断不对:string strdefaultprinter = printDocument1.PrinterSettings.PrinterName;//获取默认的打印机名
if (strdefaultprinter == null || strdefaultprinter == "")
{
MessageBox.Show("未安装打印机,请进入系统控制面版添加打印机!", "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
foreach (string strprinter in PrinterSettings.InstalledPrinters) //在列表框中列出所有的打印机,
{
if (strprinter == null||strprinter =="")//把默认打印机设为缺省值
{
MessageBox.Show("未安装打印机,请进入系统控制面版添加打印机!", "打印", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
strdefaultprinter = strprinter;
break;
}